stringr 安装失败的解决办法

最近有个任务要在新服务器上安装R包,stringr是其中之一
新服务器的R版本是4.0.5,比我之前使用的4.0.2高一些

不知道是不是版本问题,在其他服务器上只要一条install.packages('stringr')就能搞定的事,结果费了我一下午。。。
用常规的install.packages命令安装会报错,

installation of package ‘stringr’ had non-zero exit status

仔细看输出的错误信息,是因为stringr依赖的stringi包安装失败。
而stringi包安装失败的原因是有个文件无法下载:

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’

好在这条错误信息贴心的给出了icu文件的下载链接!
然而,直接用wget 下载链接中的文件也是不行滴~
根本原因在于下载这个包需要翻墙!!!
好在这个库文件不大,用浏览器+翻墙软件可以轻松下载,然后上传到服务器。

再从错误信息中找到stringi包的版本和下载链接(再次感谢R提供了详尽的错误信息)

trying URL 'https://mirrors.sjtug.sjtu.edu.cn/cran/src/contrib/stringi_1.7.8.tar.gz'

最后,当下载安装包和库文件都下载完成后执行手动安装

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库文件所在目录

安装好stringi后再执行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)

你可能感兴趣的:(stringr 安装失败的解决办法)