在Rstudio中安装package时出现错误如何解决?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
一、 install.packages('REmap')无法安装package:错误:“无法与服务器建立连接”
解决方式:切换下载的镜像
方法一:在Rstudio菜单栏:tools-global options-packages中切换下载的镜像
方法二:修改文件,在安装文件夹中找到Rprofile.site文件,我的路径是D:\Program Files\R\R-3.4.1\etc,用记事本打开,在里面添加语句:
# set a CRAN mirrorlocal({r <- getOption(“repos”)r[“CRAN”] <- “http://mirrors.tuna.tsinghua.edu.cn/CRAN/”options(repos=r)}
二、手动安装package
在网站:https://mirrors.tuna.tsinghua.edu.cn/CRAN/下载好需要的package
在R studio下,选择packages
选择Install
Install from栏选择Package Archive File(.zip;.tar.gz)
Package archive栏点击Browser,选择刚才下载的文件
点击Install,进行安装
致此,手动安装R包完成。安装提示如下
推荐第一种安装方式:因为第一种安装方式会自动安装依赖的包,而第二种方式,除了下载你想安装的包还要下载所有依赖的包,这就有一定的难度了。
补充:Rstudio安装packages时报错,原因可能是这样
最近接触R语言,安装好Rstudio后,需要安装R的第三方包mirt。
执行步骤如下:
正当满心欢喜地期待包的安装时,结果出现了下面的情况:
install.packages("mirt")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/Installing package into ‘C:/Users/likailei/Documents/R/win-library/3.6'(as ‘lib' is unspecified)Warning in install.packages : unable to access index for repository https://cran.rstudio.com/src/contrib: cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'Warning in install.packages : package ‘mirt' is not available (for R version 3.6.0)Warning in install.packages : unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.6: cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/PACKAGES'
什么鬼?!
此处省略5000字的辛苦排错的历程描述,直接贴上解决方案:
Rstudio默认使用的国外镜像源,国内无法正常访问。
Rstudio设置如下
Tools>global options>packages
更改镜像源后,重新执行安装操作。
install.packages("mirt")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/Installing package into ‘C:/Users/likailei/Documents/R/win-library/3.6'(as ‘lib' is unspecified)also installing the dependencies ‘permute', ‘GPArotation', ‘Rcpp', ‘vegan', ‘Deriv', ‘dcurver', ‘RcppArmadillo'trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/permute_0.9-5.zip'Content type 'application/zip' length 505181 bytes (493 KB)downloaded 493 KBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/GPArotation_2014.11-1.zip'Content type 'application/zip' length 162104 bytes (158 KB)downloaded 158 KBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/Rcpp_1.0.1.zip'Content type 'application/zip' length 4494896 bytes (4.3 MB)downloaded 4.3 MBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/vegan_2.5-5.zip'Content type 'application/zip' length 3861520 bytes (3.7 MB)downloaded 3.7 MBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/Deriv_3.8.5.zip'Content type 'application/zip' length 133828 bytes (130 KB)downloaded 130 KBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/dcurver_0.9.1.zip'Content type 'application/zip' length 639915 bytes (624 KB)downloaded 624 KBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/RcppArmadillo_0.9.400.3.0.zip'Content type 'application/zip' length 2276463 bytes (2.2 MB)downloaded 2.2 MBtrying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/mirt_1.30.zip'Content type 'application/zip' length 2572772 bytes (2.5 MB)downloaded 2.5 MBpackage ‘permute' successfully unpacked and MD5 sums checkedpackage ‘GPArotation' successfully unpacked and MD5 sums checkedpackage ‘Rcpp' successfully unpacked and MD5 sums checkedpackage ‘vegan' successfully unpacked and MD5 sums checkedpackage ‘Deriv' successfully unpacked and MD5 sums checkedpackage ‘dcurver' successfully unpacked and MD5 sums checkedpackage ‘RcppArmadillo' successfully unpacked and MD5 sums checkedpackage ‘mirt' successfully unpacked and MD5 sums checked
看完上述内容,你们掌握在Rstudio中安装package时出现错误如何解决的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网行业资讯频道,感谢各位的阅读!