R - 无法访问软件包安装的URL

7
我最近在个人电脑(windows 8)上安装了R Studio(版本0.99.892),并尝试安装以下软件包: ggplot2; dplyr; rmarkdown; tidyr。
无论是R还是R Studio都不能安装这些软件包。每次我尝试安装一个软件包,我都会收到我在本文底部包含的警告信息。
我已经使用了install.packages命令以及内置的软件包安装工具。我尝试过几个不同的镜像。
我曾经尝试公共大学的网络来源,我的私人网络来源和手机热点。我尝试通过VPN连接。我已将R Studio添加到我的Windows防火墙例外列表中,并完全禁用了Windows防火墙。我没有运行其他防火墙。
我切换了全局选项中“软件包”选项卡中的各种连接选项。
我可以在浏览器中访问这些URL。
下面是来自R Studio的警告:
> install.packages("devtools")
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  unable to access index for repository https://cran.fhcrc.org/src/contrib:
  cannot open URL 'https://cran.fhcrc.org/src/contrib/PACKAGES'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be     resolved'
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'
Installing package into ‘C:/Users/Nikhailovich/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  unable to access index for repository https://cran.fhcrc.org/src/contrib:
  cannot open URL 'https://cran.fhcrc.org/src/contrib/PACKAGES'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
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 ‘devtools’ is not available (for R version 3.2.3)
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  unable to access index for repository https://cran.fhcrc.org/bin/windows/contrib/3.2:
  cannot open URL 'https://cran.fhcrc.org/bin/windows/contrib/3.2/PACKAGES'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning in install.packages :
  unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.2:
  cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.2/PACKAGES'

以下是来自R(3.2.3)的警告信息:
> install.packages("ggplot2")
Installing package into ‘C:/Users/Nikhailovich/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in download.file(url, destfile = f, quiet = TRUE) : 
  cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
  InternetOpenUrl failed: 'The server name or address could not be resolved'
Warning: unable to access index for repository https://dirichlet.mat.puc.cl/src/contrib:
  cannot open URL 'https://dirichlet.mat.puc.cl/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'
Warning: unable to access index for repository https://dirichlet.mat.puc.cl/bin/windows/contrib/3.2:
  cannot open URL 'https://dirichlet.mat.puc.cl/bin/windows/contrib/3.2/PACKAGES'
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.2:
  cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.2/PACKAGES'
Warning message:
package ‘ggplot2’ is not available (for R version 3.2.3) 

有几篇关于在R和R Studio中安装软件包的StackExchange文章,但我没有找到任何能够回答我的特殊情况的文章。提前感谢任何知道情况的人。

8个回答

16

运行这个命令:

options(repos="https://CRAN.R-project.org")

之后尝试安装install.packages;应该会起作用。已在我的系统上测试。


救命稻草。谢谢! - Noah_Seagull

8

我之前也遇到过这个问题。尝试明确指定位置:

install.packages("devtools", repos="https://cran.rstudio.com/")

2
你应该尝试以下代码:

install.packages("ggbiplot",dependencies = TRUE, repos = 'http://cran.rstudio.com/')

这将帮助您安装与以下错误相关的软件包:

此版本不可用的软件包


2
在R终端中运行以下命令- options(repos="https://CRAN.R-project.org") 然后- use-install.packages('library')

这个答案与Awinash Singh的顶部答案有何不同? - undefined

2

当使用install.packages()函数并指定参数repos=时,您可以确切地指定位置。但是,您也可以选择自己喜欢的存储库,每次下载软件包时都会使用它。

    options(repos="my_favorite_CRAN_mirror")

您可以在CRAN网站上查看所有可用镜像列表。只需复制/粘贴最接近您的CRAN存储库的地址。

完成此步骤后,您应该能够重试install.packages('ggplot2')


1
我想补充一下,我遇到了这个问题,但解决方法不在R中,而是在我们的系统中。我们的IT人员说:由于某些未知原因,DNS解析器服务无法解析主机名。我重新启动了resolvd服务。服务器现在可以解析主机名。
他那边出现的错误是:名称解析临时失败。

0

我在安装 dplyrtidyr 包时遇到了类似的错误。 通过检查我的 R.version 并下载新版本的基础 R(3.3.3),我解决了这个问题。


0

尝试这个...

工具-->全局选项-->包

将“主要CRAN存储库”更改为htpps位置

这种方法解决了我的问题


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接