本來我這個段位,就不應(yīng)該為安裝包發(fā)愁了,畢竟統(tǒng)計學(xué)不會可以理解,編程學(xué)不好忍忍就過去了,但是說安裝包出錯,是可忍孰不可忍?
目錄:
1. ggplot2包安裝報錯
2,安裝rlange1.0.0
3. 安裝Rtools3.6
4. 重新安裝ggplot2
5. 安裝ellipsis包
6. 安裝pillar包
7. 重新安裝ggplot2
8. 測試成功安裝ggplot2
現(xiàn)在最新的R版本是4.2.1,因為有些包只能運行在3.6版本中,因此我需要安裝3.6,這里安裝常用的ggplot2時報錯了,總結(jié)一下問題解決的方法。
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
停止執(zhí)行
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
停止執(zhí)行
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這個包版本太低,應(yīng)該是大于1.0.0,現(xiàn)在是0.4.11。問題來了,我有兩個選擇:
第一個:下載舊版本的ggplot2,它支持rlang0.4.11版本,但是很多更新的函數(shù)我無法使用了。測試了一下,可以實現(xiàn)。但我要用第二個。
第二個:下載rlang1.0,然后安裝最新版的ggplot2,這條路很曲折,但是解決好之后就可以用最新的版本了,也算物有所值了。
用第二個,搞起!
2,安裝rlange1.0.0
如果現(xiàn)在網(wǎng)上搜索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
然后復(fù)制包的鏈接,運行下面命令:
install.packages("https://cran./src/contrib/Archive/rlang/rlang_1.0.1.tar.gz", repo=NULL, type="source")
相當(dāng)于將包下載到本地安裝,這里報錯了,顯示我沒有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,然后加入到環(huán)境變量中,重啟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
停止執(zhí)行
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包沒有安裝好,那就繼續(xù)單獨安裝。
** 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
停止執(zhí)行
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包
繼續(xù)安裝pillar,編譯安裝,安裝成功后,繼續(xù)安裝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系統(tǒng)安裝Rtools就是為了防止本地編譯時出錯,里面有C,C++,F(xiàn)ortran等各種編譯器,一籃子滿滿的。有了它,就不怕R包安裝了。