每当我尝试在Ubuntu 14.04上安装R中的任何软件包时,我都会收到以下错误:
Error in readRDS(file) : error reading from connection
我已经尝试过给here的方法,但无法解决问题。
从3.3.1(所有64位)安装R 3.4.0后,我在Windows 10上出现此错误。通过从CRAN手动安装不相关的软件包解决了这个问题(我使用了ggplot2)。不知道根本原因是什么,但也许这对你也有用。
我的代码输出:
> library(pacman)
> p_load(plyr, XLConnect, ggplot2, stringr, magrittr, kirkegaard, lubridate, weights, psych, psychometric, polycor, effsize, readr)
Installing package into ‘C:/Users/Emil/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
Error in install.packages : error reading from connection
Error in loadNamespace(name) : there is no package called ‘BiocInstaller’
然后我重新启动了R,并运行相同的代码:
> library(pacman)
> p_load(plyr, XLConnect, ggplot2, stringr, magrittr, kirkegaard, lubridate, weights, psych, psychometric, polycor, effsize, readr)
Installing package into ‘C:/Users/Emil/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
Error in readRDS(dest) : error reading from connection
即相同的代码,不同的错误。奇。然后我再次重新启动R并安装了一个随机软件包,然后重新编写代码并运行起来。
> install.packages("ggplot2")
Warning in install.packages :
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES.rds': HTTP status was '404 Not Found'
Installing package into ‘C:/Users/Emil/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4/PACKAGES.rds': HTTP status was '404 Not Found'
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/ggplot2_2.2.1.zip'
Content type 'application/zip' length 2782171 bytes (2.7 MB)
downloaded 2.7 MB
package ‘ggplot2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Emil\AppData\Local\Temp\RtmpCq4cFX\downloaded_packages
> library(pacman)
> p_load(plyr, XLConnect, ggplot2, stringr, magrittr, kirkegaard, lubridate, weights, psych, psychometric, polycor, effsize, readr)
Installing package into ‘C:/Users/Emil/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/effsize_0.7.1.zip'
Content type 'application/zip' length 36713 bytes (35 KB)
downloaded 35 KB
package ‘effsize’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Emil\AppData\Local\Temp\RtmpCq4cFX\downloaded_packages
effsize installed
因此,错误似乎与pacman试图安装effsize有关。
我也有同样的问题。我按照这里给出的说明http://www.ryantmoore.org/files/ht/htrtargz.pdf,并在需要时分别安装所有必需的依赖项。
如果您有一个或多个未正确安装的软件包(例如,因为您必须在安装期间强制重新启动),则需要重新安装此/这些软件包。您可以使用以下代码找到它们:
library(purrr)
.libPaths() %>%
set_names() %>%
map(function(lib) {
.packages(all.available = TRUE, lib.loc = lib) %>%
keep(function(pkg) {
f <- system.file('Meta', 'package.rds', package = pkg, lib.loc = lib)
tryCatch({readRDS(f); FALSE}, error = function(e) TRUE)
})
})
这将返回包含已损坏包的嵌套列表:
$`/home/yourname/R`
[1] "brokenpkg"
$`/usr/lib64/R/library`
character(0)
$`/usr/share/R/library`
character(0)
您可能需要在尝试安装软件包时删除R在库位置创建的目录00LOCK-<pkgname>
。
我遇到了同样的错误,我重新启动了R会话,它对我有用。
我在运行install.packages("mice")
时遇到错误
install.packages("mice")
这对我有用。
当我安装最新版本的R时,我遇到了同样的错误。很多次,最新版本不稳定(对我来说,它是2017年11月11日的3.4.2)。我卸载它并安装了3.4.1(早期稳定版),现在没有问题。
我有同样的问题:
readRDS(file) : error reading from connection.I did follow:
我在file.rds
文件夹中找到Downloads
,然后制作文件副本并放入另一个文件夹。然后我选择了目录:
R Session->Set working Directory->Choose directory->my new folder
这个动作完成后就可以了
还有一件有趣的事情。当我复制下载函数download.file(“http://..../file.rds”,“file.rds”)下载的文件并将文件放在文件夹目录中时,问题仍然存在。但是当我复制链接http://....../file.rds并将其粘贴到地址栏中时,文件被下载到我的计算机上的文件夹下载中,我将其复制并移动到目录文件夹。所以我没有通过R download.file的功能下载文件,从Downloads下载文件并将其放在文件夹目录中。在这种情况下,它的工作原理
确保以正确的格式保存rds
文件:
saveRDS(model, "path/file.rds")
然后使用阅读.rds
文件
model <- readRDS("path/file.rds")