readRDS(file) in R

2020-01-25 00:36发布

Whenever I try to install a package in R, I get the following error:

Error in readRDS(file) : unknown input format

This just started occurring after I had a system crash. I am running 32 bit R 2.13.0 under windows 7. I tried removing and re-installing R, but continue to get the error. Is there any way I can fix this without deleting everything (i.e. all the packages I've installed) and starting over?

Thanks

标签: r crash packages
10条回答
叼着烟拽天下
2楼-- · 2020-01-25 01:01

Run find /usr/local/lib/R/site-library/ /usr/lib/R/library/ /usr/lib/R/site-library/ ~/.local/lib/ -iname '*rds' -a -size 0 and then delete the files found.

查看更多
对你真心纯属浪费
3楼-- · 2020-01-25 01:03

I also had several problems opening an .RDS file, either "error reading from connection" or "unknown input format". I tried with several R versions, with version 3.4.2. the following worked: (I accidentally uninstalled rstudio and installed it again, also installed older R version 3.4.2, I don't know if that changes anything)

  1. set up a new working directory
  2. I opened the RDS file directly instead of downloading it (so only saved to temp files), then I was able to open it in R
  3. I moved it from temp files to my new working directory and used the Data_Essay_Account <- readRDS("C:/.../newdirectory/Data_Essay_Account.RDS") command and it worked.

Somehow properly downloading it and then moving it did not work, only after I had it in the temp files. Hard deleting packages did not work for me as I tried that initially.

查看更多
We Are One
4楼-- · 2020-01-25 01:04

Unlike the top few answers here, my issue was resolved not by doing anything with my installation of RStudio or cleaning local files, but by re-writing the RDS file.

I could confirm this because the file was stored in the cloud, and reading it from a variety of windows and mac laptops all failed, but similar RDS files from the same S3 bucket worked without a problem.

When I re-wrote the RDS file, the problem went away.

查看更多
Melony?
5楼-- · 2020-01-25 01:05

Chunxiao Xu and Rando Hinn's solution above worked for me, with a minor tweak.

First, change directories to your personal R package directory, then run: find -iname '*rds' -a -size 0

Delete the directories containing any 0 length files in the above list. Then reopen R (or RStudio) and reinstall the deleted packages.

You should now be able to list the packages again.

Chunxiao Xu's original suggestion above lists ALL of the R package directories. But the exact locations of these directories will vary from installation to installation, and their addresses will have to be edited for your installation.

Larry Hunsicker

查看更多
登录 后发表回答