最近有個(gè)任務(wù)要在新服務(wù)器上安裝R包,stringr是其中之一
新服務(wù)器的R版本是4.0.5,比我之前使用的4.0.2高一些
不知道是不是版本問(wèn)題,在其他服務(wù)器上只要一條install.packages('stringr')就能搞定的事,結(jié)果費(fèi)了我一下午。。。
用常規(guī)的install.packages命令安裝會(huì)報(bào)錯(cuò),
installation of package ‘stringr’ had non-zero exit status
仔細(xì)看輸出的錯(cuò)誤信息,是因?yàn)閟tringr依賴的stringi包安裝失敗。
而stringi包安裝失敗的原因是有個(gè)文件無(wú)法下載:
Error in download.file(paste(href, fname, sep = ""), icudtzipfname, mode = "wb"): cannot open URL 'https://raw.githubusercontent.com/gagolews/stringi/master/src/icu69/data/icu4c-69_1-data-bin-l.zip'
icudt download failed
Error: Stopping on error
In addition: Warning messages:
1: In download.file(paste(href, fname, sep = ""), icudtzipfname, mode = "wb") :
URL 'https://raw.githubusercontent.com/gagolews/stringi/master/src/icu69/data/icu4c-69_1-data-bin-l.zip': status was 'Couldn't connect to server'
2: In download.file(paste(href, fname, sep = ""), icudtzipfname, mode = "wb") :
URL 'http://raw.githubusercontent.com/gagolews/stringi/master/src/icu69/data/icu4c-69_1-data-bin-l.zip': status was 'Couldn't connect to server'
Execution halted
*** *********************************************************************
*** stringi cannot be built.
*** Failed to download the ICU data library (icudt). Stopping now.
*** For build environments that have no internet access,
*** see the INSTALL file for a workaround.
*** *********************************************************************
ERROR: configuration failed for package ‘stringi’
好在這條錯(cuò)誤信息貼心的給出了icu文件的下載鏈接!
然而,直接用wget 下載鏈接中的文件也是不行滴~
根本原因在于下載這個(gè)包需要翻墻?。?!
好在這個(gè)庫(kù)文件不大,用瀏覽器+翻墻軟件可以輕松下載,然后上傳到服務(wù)器。
再?gòu)腻e(cuò)誤信息中找到stringi包的版本和下載鏈接(再次感謝R提供了詳盡的錯(cuò)誤信息)
trying URL 'https://mirrors.sjtug.sjtu.edu.cn/cran/src/contrib/stringi_1.7.8.tar.gz'
最后,當(dāng)下載安裝包和庫(kù)文件都下載完成后執(zhí)行手動(dòng)安裝
R CMD INSTALL --configure-vars='ICUDT_DIR=~/R/x86_64-pc-linux-gnu-library/' stringi_1.7.8.tar.gz
注: ICUDT_DIR是下載的icu4c-69_1-data-bin-l.zip庫(kù)文件所在目錄
安裝好stringi后再執(zhí)行install.packages('stringr')就很順利的安裝完成了
trying URL 'https://mirrors.sjtug.sjtu.edu.cn/cran/src/contrib/stringr_1.4.0.tar.gz'
Content type 'application/gzip' length 135777 bytes (132 KB)
==================================================
downloaded 132 KB
* installing *source* package ‘stringr’ ...
** package ‘stringr’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** 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 (stringr)