2016-09-27 87 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,因此它似乎不工作。不管怎樣,謝謝你。 –