简体   繁体   中英

R: cannot install packages with install.packages() in ubuntu

Operation system: Ubuntu 12

R version: 3.3.1

When I try to install packages by install.packages() shows the following errors:

 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) 

I have tried other mirrors but still does't work. It seems that the R cannot connect to the network. In my company there is neccessary to connect network by proxy. Therefore, I have set the proxy for R by edit ~/.Renviron and this has been checked:

 > 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/" 

But it still cannot work. And then, I test the R whether can connect to network by the following function and the FALSE is returned.

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

Is there anybody having idea about this? Many thanks for attention.

First of all, I think the CRAN mirror you use does not work. Try

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

What OS do you use? If you are on windows, what do you get for:

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

Try method = "wininet" to let R download files via the windows API rather than libcurl:

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

If that does not work the machine is basically offline. If curl::has_internet() fails it means you don't have a connection at all, at least not a functioning DNS server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM