Rstudio中安装包时“无法连接服务器”问题解决方法

形如

> install.packages("randomforeast")
Warning in install.packages :
  unable to access index for repository https://mran.microsoft.com/snapshot/2018-08-01/src/contrib:
  cannot open URL 'https://mran.microsoft.com/snapshot/2018-08-01/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://mran.microsoft.com/snapshot/2018-08-01/src/contrib:
  cannot open URL 'https://mran.microsoft.com/snapshot/2018-08-01/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 ‘randomforeast’ is not available (for R version 3.5.1)
Warning in install.packages :
  unable to access index for repository https://mran.microsoft.com/snapshot/2018-08-01/bin/windows/contrib/3.5:
  cannot open URL 'https://mran.microsoft.com/snapshot/2018-08-01/bin/windows/contrib/3.5/PACKAGES'
Warning in install.packages :
  unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5:
  cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5/PACKAGES'
Warning message:
In download.file(mirrors_csv_url, destfile = mirrors_csv, quiet = TRUE) :
  InternetOpenUrl failed: ''
Warning: unable to access index for repository https://mran.microsoft.com/snapshot/2018-08-01/src/contrib:
  cannot open URL 'https://mran.microsoft.com/snapshot/2018-08-01/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'

一类安装包时“无法连接服务器”的问题

(疯狂BB:因为习惯之前一直没用R的IDE,今天瞄到眼anaconda里面的Rstudio想换个高大上的试试,结果因为以前用R的习惯和Rstudio兼容得不是很好,搞得灰头土脸,找了一晚上,这里整理记录下大佬的方法。改成国内镜像这方法基本都会尝试,就不提了。)

  1. IE浏览器问题
    由于Rstudio使用的是IE浏览器进行下载,出现这个问题先检查下IE浏览器有没有网络,多半是IE挂了,解决方案:
    关闭代理服务器。非win10大概位置在IE属性→工具→Internet选项→连接→局域网设置→关掉代理服务器;因为我是win10,所以要到设置→网络和Internet→代理→关掉代理服务器。这种应该是梯子架多了或者是被什么乱七八糟的软件改了设置。

  2. 安装包时出现无法连接到uk服务器的问题
    像这样

Warning in install.packages :
  package ‘randomforeast’ is not available (for R version 3.5.1)
Warning in install.packages :
  unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5:
  cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5/PACKAGES'

这种注意了,这应该是和我一样老习惯直接在脚本里面用install.packages()命令直接安装的。出现这个问题是因为最新的Rstudio用的R版本是3.5的,而UK的服务器并没有更新3.5的包,即使你用浏览器进去也是404!
所以这时候安装包必须从Rstudio的工具栏里面点Tools→Install packages,这样安装的过程中Rstudio会自动检索另外一个服务器去下载!
效果如下所示:

> install.packages("randomForest")
Warning in install.packages :
  unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5:
  cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.5/PACKAGES'
trying URL 'https://mran.microsoft.com/snapshot/2018-08-01/bin/windows/contrib/3.5/randomForest_4.6-14.zip'
Content type 'application/zip' length 248635 bytes (242 KB)
downloaded 242 KB

package ‘randomForest’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\hasee\AppData\Local\Temp\RtmpIjXmBI\downloaded_packages

就可以正常安装包了,问题解决。

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值