二维码

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

3112 人阅读 | 时间:2019年09月25日 13:56


  这几天在用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'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

  网络上主流的解决方式是在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
1
2
3
4
5
6
7
8
9
10
11

  无法将安装包从临时目录中转移,原因是杀毒软件可能禁止了这样的操作。在杀毒软件的白名单中加入R安装在的文件夹,重新启动RStudio问题即可解决。或者比较麻烦一点的话就是在临时目录中解压这个压缩文件到R安装目录中的library文件夹中。

————————————————



©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
◎已有 0 人评论
搜索
作者介绍
30天热门
×
×
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×