初学R语言出现了无法安装R包的情况:
install.packages(“vcb”)
Warning in install.packages :
unable to access index for repository https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib:
无法打开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/PACKAGES’
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
unable to access index for repository https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib:
无法打开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/PACKAGES’
Warning in install.packages :
package ‘vcb’ is not available (for R version 3.6.2)
Warning in install.packages :
unable to access index for repository https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/3.6:
无法打开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/3.6/PACKAGES’
解决方法:
我试了以下几个步骤最终成功了。
1.进入到R的安装目录,编辑/etc/Rprofile.site,加上一行添加 options(download.file.method=“libcurl”),重新打开Rstudio。
2.在tools-global options-packages中切换下载的镜像,选择一个中国的镜像,如https://mirrors.tuna.tsinghua.edu.cn。
3.有可能是自己把R包的名字打错了,犯了低级错误,如把vcd写成了vcb,哈哈,尴尬。
运行成功:
试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/3.6/vcd_1.4-7.zip’
length 1561131 bytes (1.5 MB)
downloaded 1.5 MB
package ‘zoo’ successfully unpacked and MD5 sums checked
package ‘colorspace’ successfully unpacked and MD5 sums checked
package ‘lmtest’ successfully unpacked and MD5 sums checked
package ‘vcd’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Administrator\AppData\Local\Temp\RtmpSm2usd\downloaded_packages