在readRDS(文件)中安装R软件包错误:从连接读取错误

问题描述 投票:20回答:9

每当我尝试在Ubuntu 14.04上安装R中的任何软件包时,我都会收到以下错误:

Error in readRDS(file) : error reading from connection

我已经尝试过给here的方法,但无法解决问题。

r package ubuntu-14.04
9个回答
6
投票

1-从CRAN安装最新版本的R并尝试安装软件包。

2-如果可以,请使用其他用户帐户进行检查。

3-尝试安装R包locally

4-如果旧版本的R创建了RDS文件,则可能存在其他类型的问题,这是来自R帮助的警告:

警告

这些函数提供了一个稳定的接口,因为R 2.4.0(当序列化对象的存储从字符变为原始向量时)。但是,序列化格式在R的未来版本中可能会更改,因此不应将此接口用于R对象的长期存储。

在32位平台上,原始向量限制为2 ^ 31 - 1个字节,但R对象可能超过此值,并且它们的序列化通常会大于对象。

参考:帮助(序列化)


1
投票

从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有关。


1
投票

我也有同样的问题。我按照这里给出的说明http://www.ryantmoore.org/files/ht/htrtargz.pdf,并在需要时分别安装所有必需的依赖项。


1
投票

如果您有一个或多个未正确安装的软件包(例如,因为您必须在安装期间强制重新启动),则需要重新安装此/这些软件包。您可以使用以下代码找到它们:

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>


1
投票

我遇到了同样的错误,我重新启动了R会话,它对我有用。


0
投票

我在运行install.packages("mice")时遇到错误

  1. 我尝试了user1436187建议的所有内容。
  2. 在此之后我尝试运行update.packages()。收到同样的错误。我还收到一条错误消息,由于权限,它无法运行某些命令。
  3. 我关闭了当前的R会话并以管理员身份重新启动它。
  4. Ran命令早先给错误install.packages("mice")

这对我有用。


0
投票

当我安装最新版本的R时,我遇到了同样的错误。很多次,最新版本不稳定(对我来说,它是2017年11月11日的3.4.2)。我卸载它并安装了3.4.1(早期稳定版),现在没有问题。


0
投票

我有同样的问题:

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下载文件并将其放在文件夹目录中。在这种情况下,它的工作原理


-1
投票

确保以正确的格式保存rds文件:

saveRDS(model, "path/file.rds")

然后使用阅读.rds文件

model <- readRDS("path/file.rds")
© www.soinside.com 2019 - 2024. All rights reserved.