目录:
1. ggplot2包安装报错
2,安装rlange1.0.0
3. 安装Rtools3.6
4. 重新安装ggplot2
5. 安装ellipsis包
6. 安装pillar包
7. 重新安装ggplot2
8. 测试成功安装ggplot2
现在最新的R版本是4.2.1,因为有些包只能运行在3.6版本中,因此我需要安装3.6,这里安装常用的ggplot2时报错了,总结一下问题解决的方法。
1. ggplot2包安装报错
本来,我安装R3.6,然后直接运行install.packages("ggplot2"),报错如下:
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'rlang' 0.4.11 is already loaded, but >= 1.0.2 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
停止执行
ERROR: lazy loading failed for package 'pillar'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/pillar'
Warning in install.packages :
installation of package 'pillar’ had non-zero exit status
* installing *source* package 'scales' ...
** 成功将'scales'程序包解包并MD5和检查
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'rlang' 0.4.11 is being loaded, but >= 1.0.0 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
停止执行
ERROR: lazy loading failed for package 'scales'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/scales'
Warning in install.packages :
installation of package 'scales’ had non-zero exit status
ERROR: dependency 'scales' is not available for package 'ggplot2'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/ggplot2'
Warning in install.packages :
installation of package 'ggplot2’ had non-zero exit status
The downloaded source packages are in
'C:\Users\dave\AppData\Local\Temp\Rtmpg3apRU\downloaded_packages’
看起来,主要是因为rlange这个包版本太低,应该是大于1.0.0,现在是0.4.11。问题来了,我有两个选择:
第一个:下载旧版本的ggplot2,它支持rlang0.4.11版本,但是很多更新的函数我无法使用了。测试了一下,可以实现。但我要用第二个。
第二个:下载rlang1.0,然后安装最新版的ggplot2,这条路很曲折,但是解决好之后就可以用最新的版本了,也算物有所值了。
用第二个,搞起!
2,安装rlange1.0.0
如果现在网上搜索R包的地址,包括其不同的版本,可以键入:
https://cran./src/contrib/Archive/
如果知道包的名称,比如ggplot2,键入:
https://cran./src/contrib/Archive/ggplot2
可以看到,旧版本的ggplot2,下载到本地,然后安装就可以了。这里我们不用这种方法,我们要安装最新版的。
在这里插入图片描述找到rlang包的链接:https://cran./src/contrib/Archive/rlang/rlang_1.0.1.tar.gz
然后复制包的链接,运行下面命令:
install.packages("https://cran./src/contrib/Archive/rlang/rlang_1.0.1.tar.gz", repo=NULL, type="source")
相当于将包下载到本地安装,这里报错了,显示我没有make命令。
所以,我要安装编译的工具Rtools。
* installing *source* package 'rlang' ...
** 成功将'rlang'程序包解包并MD5和检查
** using staged installation
** libs
Warning in system(cmd) : 'make' not found
ERROR: compilation failed for package 'rlang'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/rlang'
* restoring previous 'C:/Users/dave/Documents/R/win-library/3.6/rlang'
Warning in install.packages :
installation of package 'C:/Users/dave/AppData/Local/Temp/Rtmpg3apRU/downloaded_packages/rlang_1.0.1.tar.gz’ had non-zero exit status
3. 安装Rtools3.6
安装Rtools3.6,然后加入到环境变量中,重启R语言,然后键入:
install.packages("https://cran./src/contrib/Archive/rlang/rlang_1.0.1.tar.gz", repo=NULL, type="source")
成功,可以看到rlang1.0安装好了,重新本地编译安装是可以解决问题的。
vector-construction html
vector-old-ctors html
with_env html
with_handlers html
wref_key html
zap html
zap_srcref html
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (rlang)
测试:
> library(rlang)
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rlang_1.0.1
loaded via a namespace (and not attached):
[1] compiler_3.6.3 cli_2.5.0 tools_3.6.3
可以看到,上面的R版本是3.6.3,rlang的版本是1.0.1,搞定。
4. 重新安装ggplot2
install.packages("ggplot2")
安装ggplot2,还是报错:
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called 'ellipsis'
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
停止执行
ERROR: lazy loading failed for package 'ggplot2'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/ggplot2'
Warning in install.packages :
installation of package 'ggplot2’ had non-zero exit status
从日志可以看到,是因为没有ellipsis这个包,那就单独安装试试。
5. 安装ellipsis包
install.packages("ellipsis")
安装成功:
> install.packages("ellipsis")
Installing package into 'C:/Users/dave/Documents/R/win-library/3.6’
(as 'lib’ is unspecified)
trying URL 'https://mirrors.tuna./CRAN/bin/windows/contrib/3.6/ellipsis_0.3.2.zip'
Content type 'application/zip' length 49192 bytes (48 KB)
downloaded 48 KB
package 'ellipsis’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\dave\AppData\Local\Temp\RtmpWqZTPD\downloaded_packages
再重新安装ggplot2:
install.packages("ggplot2")
还是报错,显示pillar包没有安装好,那就继续单独安装。
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called 'pillar'
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
停止执行
ERROR: lazy loading failed for package 'ggplot2'
* removing 'C:/Users/dave/Documents/R/win-library/3.6/ggplot2'
Warning in install.packages :
installation of package 'ggplot2’ had non-zero exit status
6. 安装pillar包
继续安装pillar,编译安装,安装成功后,继续安装ggplot2,如果哪个包报错,就安装哪个包。
安装好之后,再安装ggplot2,如果还有包报错,就单独安装。
一路走来,哪里报错安哪里,本来自动化安装依赖的R语言让我整成了手动。
7. 重新安装ggplot2
安装成功,终于安装成功了:
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggplot2)
The downloaded source packages are in
'C:\Users\dave\AppData\Local\Temp\RtmpMhrQc1\downloaded_packages’
8. 测试成功安装ggplot2
测试,载入,然后看一下R的版本和ggplot2的版本:
> library(ggplot2)
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.6
loaded via a namespace (and not attached):
[1] fansi_0.4.2 withr_2.5.0 utf8_1.2.1 grid_3.6.3
[5] R6_2.5.1 lifecycle_1.0.1 gtable_0.3.0 magrittr_2.0.1
[9] scales_1.2.1 pillar_1.8.1 rlang_1.0.4 cli_2.5.0
[13] vctrs_0.3.8 ellipsis_0.3.2 tools_3.6.3 glue_1.4.2
[17] munsell_0.5.0 compiler_3.6.3 pkgconfig_2.0.3 colorspace_2.0-1
[21] tibble_3.1.1
可以看到,我的R版本是3.6.3,ggplot2的版本是3.3.6,搞定!
这种方法可以推广到R3.5,R4.0,R4.1,windows系统安装Rtools就是为了防止本地编译时出错,里面有C,C++,Fortran等各种编译器,一篮子满满的。有了它,就不怕R包安装了。