使用 install.packages() 安装R包时,总是比较慢,有时甚至安装失败,失败情形如下:
> install.packages('gridExtra')
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/src/contrib:
无法打开URL'https://cran.rstudio.com/src/contrib/PACKAGES'
为避免这种情况,可以设置CRAN使用清华大学镜像,命令如下:
options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))
之后再来安装包,速度很快:
> install.packages('gridExtra')
试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/macosx/el-capitan/contrib/3.5/gridExtra_2.3.tgz'
Content type 'application/octet-stream' length 1102824 bytes (1.1 MB)
==================================================
downloaded 1.1 MB
The downloaded binary packages are in
/var/folders/kl/9xr58rsj4md0f1ngtxhq0bqh0000gn/T//RtmpuSD541/downloaded_packages
或者不用Rstudio,直接用R安装: