欢迎来到代码驿站!

当前位置:首页 >

基于R/RStudio中安装包“无法与服务器建立连接”的解决方案

时间:2021-04-04 03:06:46|栏目:|点击:

这几天在用RStudio写程序的时候突然出现无法从网络直接安装r包的问题,也无法从本地直接安装。

通过多方尝试找到了问题解决的办法,现在记录在这里。

程序报错如下:

> install.packages('REmap')
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 :
 unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib:
 cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'
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 :
 unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib:
 cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'
Warning in install.packages :
 package ‘REmap' is not available (for R version 3.4.1)
Warning in install.packages :
 unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.4:
 cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/PACKAGES'
Warning in install.packages :
 unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4:
 cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4/PACKAGES'
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
 cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib:
 cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'

网络上主流的解决方式是在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”] <- “http://mirrors.tuna.tsinghua.edu.cn/CRAN/”
options(repos=r)}

这也是设置镜像的方法,与方法一相同。对我也没用。

之后了解到R中install.packages()是从ie浏览器中连接镜像的,所以无法连接服务器很可能是在ie这一环节出现了问题。

打开电脑的ie浏览器看能不能正常上网,如果显示代理问题,在工具-internet选项-连接中将局域网设置里的代理服务器这一项去掉勾选。这样就可以正常上网了。再检查RStudio也能够正常安装r包了。

之后出现另外一个问题:  

> install.packages('sp')
trying URL 'https://cran.wu.ac.at/bin/windows/contrib/3.4/sp_1.2-5.zip'
Content type 'application/zip' length 1538503 bytes (1.5 MB)
downloaded 1.5 MB

package ‘sp' successfully unpacked and MD5 sums checked
Warning in install.packages :
 unable to move temporary installation ‘D:\Program Files\R\R-3.4.1\library\file4041367c44\sp' to ‘D:\Program Files\R\R-3.4.1\library\sp'

The downloaded binary packages are in
 C:\Users\asus\AppData\Local\Temp\RtmpWOz6Xu\downloaded_packages

无法将安装包从临时目录中转移,原因是杀毒软件可能禁止了这样的操作。

在杀毒软件的白名单中加入R安装在的文件夹,重新启动RStudio问题即可解决。

或者比较麻烦一点的话就是在临时目录中解压这个压缩文件到R安装目录中的library文件夹中。

补充:R或RStudio下载包时出错解决方案

当我们想要在R&RStudio中下载包时可能会出现如下类似错误

在如下目录中的Rprofile.site文件中对应位置增加一条代码即可:

options(download.file.method="libcurl")

修改好后,再次下载即可成功!

上一篇:R语言 install.packages 无法读取索引的解决方案

栏    目:

下一篇:Powershell小技巧之通过EventLog查看近期电脑开机和关机时间

本文标题:基于R/RStudio中安装包“无法与服务器建立连接”的解决方案

本文地址:http://www.codeinn.net/misctech/94637.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有