Rstudio中安装package出现的问题及解决
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 mirror
local({r <- getOption(“repos”)
r[“CRAN”] <- “mirrors.tuna.tsinghua.edu/CRAN/”
options(repos=r)}
⼆、⼿动安装package
1.在R studio下,选择packages
2.选择Install
3.Install from栏选择Package Archive File(.zip;.)
4.Package archive栏点击Browser,选择刚才下载的⽂件
5.点击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: cran.rstudio/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 cran.rstudio/src/contrib:
cannot open URL 'cran.rstudio/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 cran.rstudio/bin/windows/contrib/3.6:
cannot open URL 'cran.rstudio/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: cran.rstudio/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 'ji.edu/CRAN/bin/windows/contrib/3.6/permute_0.9-5.zip'
Content type 'application/zip' length 505181 bytes (493 KB)
downloaded 493 KB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/GPArotation_2014.11-1.zip'
Content type 'application/zip' length 162104 bytes (158 KB)
downloaded 158 KB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/Rcpp_1.0.1.zip'
Content type 'application/zip' length 4494896 bytes (4.3 MB)下载安装
downloaded 4.3 MB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/vegan_2.5-5.zip'
Content type 'application/zip' length 3861520 bytes (3.7 MB)
downloaded 3.7 MB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/Deriv_3.8.5.zip'
Content type 'application/zip' length 133828 bytes (130 KB)
downloaded 130 KB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/dcurver_0.9.1.zip'
Content type 'application/zip' length 639915 bytes (624 KB)
downloaded 624 KB
trying URL 'ji.edu/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 MB
trying URL 'ji.edu/CRAN/bin/windows/contrib/3.6/mirt_1.30.zip'
Content type 'application/zip' length 2572772 bytes (2.5 MB)
downloaded 2.5 MB
package ‘permute' successfully unpacked and MD5 sums checked
package ‘GPArotation' successfully unpacked and MD5 sums checked
package ‘Rcpp' successfully unpacked and MD5 sums checked
package ‘vegan' successfully unpacked and MD5 sums checked
package ‘Deriv' successfully unpacked and MD5 sums checked
package ‘dcurver' successfully unpacked and MD5 sums checked
package ‘RcppArmadillo' successfully unpacked and MD5 sums checked
package ‘mirt' successfully unpacked and MD5 sums checked
完美
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。如有错误或未考虑完全的地⽅,望不吝赐教。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。