【问题标题】:Installing R Packages Error in readRDS(file) : error reading from connection在 readRDS(file) 中安装 R 包错误:从连接读取错误
【发布时间】:2015-11-03 07:25:39
【问题描述】:

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

Error in readRDS(file) : error reading from connection

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

【问题讨论】:

  • @Pascal 错误不同,OP 指出链接中提供的解决方案没有解决问题。
  • @Pascal 我的评论更多是为了引起你的注意,以防你继续前进。
  • 你试过不同的镜像吗?这是在 RStudio 中还是在基础 R 中?
  • 您是否在代理后面,例如在公司办公室或大学?
  • 您应该:A) 发布导致错误的代码,B) 发布 sessionInfo() 的输出,c) 回答上述所有未解决的问题。

标签: r package ubuntu-14.04


【解决方案1】:

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

2- 如果可能,请使用另一个用户帐户进行检查。

3- 尝试安装R包locally

4- 如果有旧版本的 R 创建的 RDS 文件,您可能会遇到另一种问题,这是来自 R 帮助的警告:

警告

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

在 32 位平台上,原始向量限制为 2^31 - 1 个字节,但 R 对象可以超过这个,它们的序列化通常是 比物体大。

参考:帮助(序列化)

【讨论】:

  • 请让我们知道上述 cmets 是否有效。
【解决方案2】:

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

【讨论】:

  • It was resolved by manually installing an unrelated package from CRAN (I used ggplot2) 也为我工作。奇怪...还是谢谢。
【解决方案3】:

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

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

这对我有用。

【讨论】:

    【解决方案4】:

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

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

    然后使用

    读取.rds文件
    model <- readRDS("path/file.rds")
    

    【讨论】:

      【解决方案5】:

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

      【讨论】:

        【解决方案6】:

        我遇到了同样的问题:

        readRDS(file) : error reading from connection.I did follow:
        

        我在文件夹Downloads 中找到file.rds,然后复制文件并放入另一个文件夹。然后我选择了目录:

        R Session->Set working Directory->Choose directory->my new folder
        

        执行此操作后,它起作用了

        还有一件有趣的事情。当我复制函数download.file(“http://..../file.rds”,“file.rds”)下载的文件并将文件放在文件夹目录中时,问题仍然存在。但是,当我复制链接http://....../file.rds 并将其粘贴到地址栏中时,该文件已下载到我的计算机上的“下载”文件夹中,我从中复制了该文件并移至目录-文件夹。所以我没有通过R download.file的功能下载文件,从Downloads复制文件并将其放在文件夹目录中。在这种情况下,它可以工作

        【讨论】:

          【解决方案7】:

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

          【讨论】:

            【解决方案8】:

            如果您有一个或多个错误安装的软件包(例如,因为您在安装过程中必须强制重启),您需要重新安装这个/这些软件包。您可以使用以下代码找到它们:

            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-&lt;pkgname&gt;

            【讨论】:

            • 删除我所有的包然后重新安装对我有用
            【解决方案9】:

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

            【讨论】:

              【解决方案10】:

              当我加载“tidyverse”时遇到与 readRDS 相关的相同错误。我一直在使用 R 中的 VS Code。也许有什么问题。

              对我有用的解决方案。 更新所有软件包,这是一个很大的列表。我不得不在错误输出之后再次单独重新安装一些。

              readRDS(file) 中的错误:从连接中读取错误 #went away 并加载了 tidiverse。

              【讨论】:

                猜你喜欢
                • 2021-07-30
                • 1970-01-01
                • 2021-07-30
                • 2017-12-05
                • 1970-01-01
                • 1970-01-01
                • 2018-04-24
                • 1970-01-01
                • 2021-08-28
                相关资源
                最近更新 更多