2016-09-27 64 views
0

操作系统:Ubuntu的12R:不能在Ubuntu安装与install.packages()封装

[R版本:3.3.1

当我尝试安装由install.packages包()显示以下错误:

install.packages("cluster") 
 
--- Please select a CRAN mirror for use in this session --- 
 
Warning: failed to download mirrors file (cannot download all files); using local file '/opt/R/lib/R/doc/CRAN_mirrors.csv' 
 
Warning: unable to access index for repository http://mirrors.opencas.cn/cran/src/contrib: 
 
    cannot open URL 'http://mirrors.opencas.cn/cran/src/contrib/PACKAGES' 
 
Warning messages: 
 
1: In download.file(url, destfile = f, quiet = TRUE) : 
 
    URL 'https://cran.r-project.org/CRAN_mirrors.csv': status was 'Couldn't connect to server' 
 
2: package ?.luster?.is not available (for R version 3.3.1)

我已经尝试过其他的镜子,但仍然简化版,工作。看来R无法连接到网络。在我的公司中,需要通过代理连接网络。因此,我已通过编辑〜/ .Renviron R上的代理,这已得到遏制:

> Sys.getenv("http_proxy") 
 
[1] "http://proxy.zte.com.cn:80/" 
 
> Sys.getenv("https_proxy") 
 
[1] "https://proxy.zte.com.cn:80/" 
 
> Sys.getenv("ftp_proxy") 
 
[1] "ftp://proxy.zte.com.cn:80/"

但它仍然无法正常工作。然后,我测试R是否可以通过以下函数连接到网络,并返回FALSE。

library('curl') 
 

 
has_internet <- function(){ 
 
+ !is.null(curl::nslookup("r-project.org", error = FALSE)) 
 
+ } 
 
       
 
> has_internet() 
 
[1] FALSE

有想法有任何人这件事吗?非常感谢您的关注。

+2

您对无法运行的内容使用“运行代码段”。这是JS。 –

+0

你说的问题只是网络访问。对服务器故障进行故障排除是最容易的,但是您可以做的一些诊断是尝试从终端ping Google.com,如果它能正常工作,则只需复制终端使用的设置即可。此外,请查看此主题中提到的各种设置,并查看是否有任何工作为您提供参数“方法”(https://support.rstudio.com/hc/en-us/community/posts/200660383-Proxy-settings –

+0

)在使用'download.file'中的方法的'install.packages'中,根据'?download.file',你可以将它设置为“wget”或“curl”,这些使用系统调用,所以如果这些工作正常你的系统,这应该绕过代理。 – Shape

回答

0

首先,我认为您使用的CRAN镜像不起作用。试试

options(repos = "https://cloud.r-project.org") 

你用什么操作系统?如果您使用的是Windows,你怎么获得:

curl::ie_proxy_info() 
curl::ie_get_proxy_for_url("https://cloud.r-project.org") 

尝试method = "wininet"让通过Windows API R下载文件,而不是的libcurl:

install.packages("MASS", repos = "https://cran.r-project.org") method = "wininet) 

如果不工作的机器基本上是离线。 如果curl::has_internet()失败,则意味着根本没有连接,至少没有正常运行的DNS服务器。

+0

我的操作系统是Ubuntu,因此它似乎不工作。不管怎样,谢谢你。 –