简体   繁体   English

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

[英]Installing R Packages Error in readRDS(file) : error reading from connection

Whenever I try to install any package in R on Ubuntu 14.04, I'm getting the following error:每当我尝试在 Ubuntu 14.04 上的 R 中安装任何软件包时,都会收到以下错误:

Error in readRDS(file) : error reading from connection

I already tried the methods given here but could not solve the problem.我已经尝试过这里给出的方法但无法解决问题。

1- Install the latest version of R form the CRAN and try to install a package. 1-从CRAN安装最新版本的R并尝试安装软件包。

2- If it is possible check it with another user account. 2-如果可以,请使用其他用户帐户进行检查。

3- Try to install the R package locally . 3-尝试在本地安装R软件包。

4- If there is an RDS file created by the old version of R you may have another sort of problem, this is the warning from R help: 4-如果旧版本的R创建了RDS文件,则可能存在其他类型的问题,这是来自R帮助的警告:

Warning 警告

These functions have provided a stable interface since R 2.4.0 (when the storage of serialized objects was changed from character to raw vectors). 这些函数提供了一个稳定的接口,因为R 2.4.0(当序列化对象的存储从字符变为原始向量时)。 However, the serialization format may change in future versions of R, so this interface should not be used for long-term storage of R objects. 但是,序列化格式可能会在将来的R版本中发生变化,因此不应将此接口用于R对象的长期存储。

On 32-bit platforms a raw vector is limited to 2^31 - 1 bytes, but R objects can exceed this and their serializations will normally be larger than the objects. 在32位平台上,原始向量限制为2 ^ 31 - 1个字节,但R对象可能超过此值,并且它们的序列化通常会大于对象。

Ref: help(serialize) 参考:帮助(序列化)

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

I had this error on Windows 10 after installing R 3.4.0 from 3.3.1 (all 64-bit). 从3.3.1(所有64位)安装R 3.4.0后,我在Windows 10上出现此错误。 It was resolved by manually installing an unrelated package from CRAN (I used ggplot2 ). 通过从CRAN手动安装不相关的软件包解决了这个问题(我使用了ggplot2 )。 No idea what the root cause was, but perhaps this will work for you as well. 不知道根本原因是什么,但也许这对你也有用。

Output from my code: 我的代码输出:

> 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’ 

Then I restarted R, and ran the same code: 然后我重新启动了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

Ie same code, different error. 即相同的代码,不同的错误。 Odd. 奇。 Then I restarted R again and installed a random package, then reran my code and it worked. 然后我再次重新启动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

So, error seems to have had something to do with pacman trying to install effsize . 因此,错误似乎与pacman试图安装effsize有关

I also had the same problem. 我也有同样的问题。 I followed the instructions given here http://www.ryantmoore.org/files/ht/htrtargz.pdf and installed all the required dependencies separately as and when they were required. 我按照http://www.ryantmoore.org/files/ht/htrtargz.pdf中的说明进行操作,并在需要时单独安装所有必需的依赖项。

If you have one or more incorrectly installed packages (eg because you had to force-reboot during installation) you need to re-install this/these package(s). 如果您有一个或多个未正确安装的软件包(例如,因为您必须在安装期间强制重新启动),则需要重新安装此/这些软件包。 You can find them using this code: 您可以使用以下代码找到它们:

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)
    })
})

This will return a nested list containing the broken packages: 这将返回包含已损坏包的嵌套列表:

$`/home/yourname/R`
[1] "brokenpkg"

$`/usr/lib64/R/library`
character(0)

$`/usr/share/R/library`
character(0)

You might need to delete the directories 00LOCK-<pkgname> that R created in the library location while trying to install the packages. 在尝试安装软件包时,您可能需要删除在库位置创建的R的目录00LOCK-<pkgname>

I was getting error running install.packages("mice") 运行install.packages("mice")出错

  1. I tried everything suggested by user1436187. 我尝试了user1436187建议的所有内容。
  2. After this I tried running update.packages(). 在此之后我尝试运行update.packages()。 received same error. 收到同样的错误。 I also got an error message where it was unable to run some command due to permissions. 我还收到一条错误消息,由于权限,它无法运行某些命令。
  3. I closed my current session of R and restarted it again as an administrator. 我关闭了当前的R会话并以管理员身份重新启动它。
  4. Ran command which was giving error earlier install.packages("mice") Ran命令早先发出错误install.packages("mice")

This worked for me. 这对我有用。

I was facing the same error when i installed most recent version of R. many a times most recent version is not stable( for me, it was 3.4.2 on 08/11/2017). 当我安装最新版本的R时,我遇到了同样的错误。很多次,最新版本不稳定(对我来说,它是2017年11月8日的3.4.2)。 I uninstalled it and installed 3.4.1( earlier stable version), now there is no issue. 我卸载它并安装了3.4.1(早期稳定版),现在没有问题。

I had the same problem: 我有同样的问题:

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

I found file.rds in folder Downloads , then made copy of file and put in another folder. 我在文件夹Downloads找到了file.rds ,然后复制了文件并放入另一个文件夹。 And then I chose directory in: 然后我选择了目录:

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

After this action it works 这个动作完成后就可以了

And one interesting thing. 还有一件有趣的事情。 When I copied the file downloaded by the function download.file(" http://..../file.rds ", "file.rds") and put the file in folder-directory, the problem remained. 当我复制下载函数download.file(“ http://..../file.rds ”,“file.rds”)下载的文件并将文件放在文件夹目录中时,问题仍然存在。 But when I copied the link http://....../file.rds and pasted it into the address bar, the file was downloaded in the folder Downloads on my computer from which I copied it and moved to the directory -folder. 但是,当我复制链接http://....../ file.rds并将其粘贴到地址栏中时,文件被下载到我的计算机上的文件夹下载中,我将其复制并移至目录 -夹。 So I did not download file by the function of R download.file, copied file from Downloads and put it in the folder-directory. 所以我没有通过R download.file的功能下载文件,从Downloads下载文件并将其放在文件夹目录中。 In this case, it works 在这种情况下,它的工作原理

Hit the same error related to readRDS when I went to load "tidyverse".当我去加载“tidyverse”时,遇到了与 readRDS 相关的相同错误。 I had been working with VS Code in R. Maybe something glitched.我一直在使用 R 中的 VS Code。也许出了点问题。

Solution that worked for me.对我有用的解决方案。 Update all package s, it was a big list.更新所有包,这是一个很大的列表。 and I had to reinstall some individually again following the error outputs.在错误输出之后,我不得不再次单独重新安装一些。

Error in readRDS(file) : error reading from connection #went away and tidiverse loaded. readRDS(file) 中的错误:从连接读取错误 #went away 并加载 tidiverse。

Make sure you are saving the rds file in correct format : 确保以正确的格式保存rds文件:

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

Then read the .rds file using 然后使用读取.rds文件

model <- readRDS("path/file.rds")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM