這幾天在用RStudio寫程序的時(shí)候突然出現(xiàn)無(wú)法從網(wǎng)絡(luò)直接安裝r包的問(wèn)題,也無(wú)法從本地直接安裝。
通過(guò)多方嘗試找到了問(wèn)題解決的辦法,現(xiàn)在記錄在這里。
程序報(bào)錯(cuò)如下:
> install.packages('REmap') Warning in install.packages : unable to access index for repository https://cran.rstudio.com/src/contrib: cannot open URL 'https://cran.rstudio.com/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://cran.rstudio.com/src/contrib: cannot open URL 'https://cran.rstudio.com/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 ‘REmap' is not available (for R version 3.4.1) Warning in install.packages : unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.4: cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/PACKAGES' Warning in install.packages : unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4: cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4/PACKAGES' Warning: unable to access index for repository https://cran.rstudio.com/src/contrib: cannot open URL 'https://cran.rstudio.com/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'
網(wǎng)絡(luò)上主流的解決方式是在tools-global options-packages中切換下載的鏡像,有很多人反映他們的問(wèn)題通過(guò)這個(gè)方法得到了解決,但是我換過(guò)很多鏡像都沒(méi)有用。
另一種方式是修改文件,在安裝文件夾中找到Rprofile.site文件,我的路徑是D:\Program Files\R\R-3.4.1\etc,用記事本打開(kāi),在里面添加語(yǔ)句:
# set a CRAN mirror local({r <- getOption(“repos”) r[“CRAN”] <- “http://mirrors.tuna.tsinghua.edu.cn/CRAN/” options(repos=r)}
這也是設(shè)置鏡像的方法,與方法一相同。對(duì)我也沒(méi)用。
之后了解到R中install.packages()是從ie瀏覽器中連接鏡像的,所以無(wú)法連接服務(wù)器很可能是在ie這一環(huán)節(jié)出現(xiàn)了問(wèn)題。
打開(kāi)電腦的ie瀏覽器看能不能正常上網(wǎng),如果顯示代理問(wèn)題,在工具-internet選項(xiàng)-連接中將局域網(wǎng)設(shè)置里的代理服務(wù)器這一項(xiàng)去掉勾選。這樣就可以正常上網(wǎng)了。再檢查RStudio也能夠正常安裝r包了。
之后出現(xiàn)另外一個(gè)問(wèn)題:
> install.packages('sp') trying URL 'https://cran.wu.ac.at/bin/windows/contrib/3.4/sp_1.2-5.zip' Content type 'application/zip' length 1538503 bytes (1.5 MB) downloaded 1.5 MB package ‘sp' successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation ‘D:\Program Files\R\R-3.4.1\library\file4041367c44\sp' to ‘D:\Program Files\R\R-3.4.1\library\sp' The downloaded binary packages are in C:\Users\asus\AppData\Local\Temp\RtmpWOz6Xu\downloaded_packages
無(wú)法將安裝包從臨時(shí)目錄中轉(zhuǎn)移,原因是殺毒軟件可能禁止了這樣的操作。
在殺毒軟件的白名單中加入R安裝在的文件夾,重新啟動(dòng)RStudio問(wèn)題即可解決。
或者比較麻煩一點(diǎn)的話就是在臨時(shí)目錄中解壓這個(gè)壓縮文件到R安裝目錄中的library文件夾中。
補(bǔ)充:R或RStudio下載包時(shí)出錯(cuò)解決方案
當(dāng)我們想要在R&RStudio中下載包時(shí)可能會(huì)出現(xiàn)如下類似錯(cuò)誤
在如下目錄中的Rprofile.site文件中對(duì)應(yīng)位置增加一條代碼即可:
options(download.file.method="libcurl")
修改好后,再次下載即可成功!
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
原文鏈接:https://blog.csdn.net/truffle528/article/details/77200710