![v2-8b5a86b5c4ab10438264811e269f4daf_1440w.jpg?source=172ae18b](http://img-02.proxy.5ce.com/view/image?&type=2&guid=2bdf0bc0-422f-eb11-8da9-e4434bdf6706&url=https://pic2.zhimg.com/v2-8b5a86b5c4ab10438264811e269f4daf_1440w.jpg?source=172ae18b)
简介
支持导出各种文件。通过graph2ppt导出到PPT,通过graph2doc导出到Word...只有你想不到,没有它做不到。
秒秒钟搞定版
#预先安装好R-3.6.3, Rstudio-1.2.5033,Rtools-35
#预先设置好环境变量
install.packages("officer")
install.packages("rvg")
install.packages("openxlsx")
install.packages("ggplot2")
install.packages("flextable")
install.packages("xtable")
install.packages("rgl")
install.packages("stargazer")
install.packages("tikzDevice")
install.packages("xml2")
install.packages("broom")
install.packages("devtools")
library(devtools)
devtools::install_github("tomwenseleers/export")
remove.packages("officer")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/officer/officer_0.3.6.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
remove.packages("rvg")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/rvg/rvg_0.2.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
太长不看版(各种报错版)
first try
install.packages("export")
出现警告:package"export" is not available(for R version 3.6.3)
。
以为是R版本问题折腾了好久,去CRAN上一查,目瞪口呆.jpg。
Package ‘export’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2020-02-11 as check problems were not corrected in time.
second try
从github上下载安装总行吧,试一试。https://github.com/tomwenseleers/export
# Get the lastest development version
install.packages("officer")
install.packages("rvg")
install.packages("openxlsx")
install.packages("ggplot2")
install.packages("flextable")
install.packages("xtable")
install.packages("rgl")
install.packages("stargazer")
install.packages("tikzDevice")
install.packages("xml2")
install.packages("broom")
install.packages("devtools")
library(devtools)
devtools::install_github("tomwenseleers/export")
安装了之后看起来没什么问题,那尝个鲜。输个命令?graph2ppt
就报错:
error: 'ph_with_vg_at' is defunct.
Use 'officer::ph_with' instead.
See help("Defunct")
瞅一瞅别人有没有遇到相同的问题,结果一看,还真有。https://github.com/tomwenseleers/export/issues/23
提出的解决办法嘛,值得一试。
To avoid this error you need to install rvg package with old 2.1 version using CRAN.
鉴于安装旧版本的包需要Rtools,再加上时不时的警告:WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding
下载并安装Rtools,一路点击确定,安装位置不要改动C:/Rtools
,容易有坑。将C:/Rtools/bin
和C:/Rtools/mingw_64/bin
添加进环境变量。保险起见,打开R,写入:
Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(PATH = paste("C:/Rtools/mingw_64/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")
OK,安装rvg 0.2.1。
remove.packages("rvg")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/rvg/rvg_0.2.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
然后在一番焦急等待之下,迎来了新的报错。省略前阶段的编译,只看最后几行:
** R
** inst
** byte-compile and prepare package for lazy loading
错误: object 'location_eval' is not exported by 'namespace:officer'
停止执行
ERROR: lazy loading failed for package 'rvg'
* removing 'D:/Mxt/Documents/R/win-library/3.6/rvg'
Warning in install.packages :
installation of package ‘C:/Users/Mxt/AppData/Local/Temp/RtmpUFWe1R/downloaded_packages/rvg_0.2.1.tar.gz’ had non-zero exit status
officer? non-zero exit status? google一下,感觉问题可能是依赖包冲突,依赖包版本过低。查看一下rvg的description:
Imports: grDevices, Rcpp (>= 0.12.12), officer (>= 0.3.5), gdtools (>=0.1.6), xml2 (>= 1.0.0), rlang。
装个officer0.3.5试试:
remove.packages("officer")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/officer/officer_0.3.5.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
然后再次安装rvg 0.2.1。
remove.packages("rvg")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/rvg/rvg_0.2.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
这下子总可以了吧??加载export包,又出新bug:
library(export)
#错误: package or namespace load failed for ‘export’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
载入了名字空间‘officer’ 0.3.5,但需要的是>= 0.3.6
Oh My God
来吧,officer0.3.6:
remove.packages("officer")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/officer/officer_0.3.6.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
没问题啦,到此为止,万幸,万幸,没有新的bug。