Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

readRDS(file) in R

Tags:

r

crash

packages

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

like image 961
Zach Avatar asked Jun 24 '11 21:06

Zach


People also ask

How do I use readRDS in R?

R has its own data file format–it's usually saved using the . rds extension. To read a R data file, invoke the readRDS() function. As with a CSV file, you can load a RDS file straight from a website, however, you must first run the file through a decompressor before attempting to load it via readRDS .

What is a .RDS file in R?

Rds files store a single R object. According to R documentation: These functions provide the means to save a single R object to a connection (typically a file) and to restore the object, quite possibly under a different name.

How do I open a .RDS file?

If you cannot open your RDS file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a RDS file directly in the browser: Just drag the file onto this browser window and drop it.

What is an .RData file?

The RData format (usually with extension . rdata or . rda) is a format designed for use with R, a system for statistical computation and related graphics, for storing a complete R workspace or selected "objects" from a workspace in a form that can be loaded back by R.


2 Answers

These are suggestions I have come across:

  1. Delete your .Rhistory and .RData files in the directory in which you are running R.
  2. Run update.packages()
  3. Try and detect "bad files" in your library directories. You can do this in R

    # List the library paths # The issue is likely to be in the first directory paths = .libPaths()  ## Try and detect bad files list.files(paths,         pattern = "^00LOCK*|*\\.rds$|*\\.RDS$",        full.names = TRUE)  ## List files of size 0 l = list.files(paths, full.names = TRUE) l[sapply(l, file.size) == 0] 

    Delete any files/directories highlighted. You could use file.remove() if you really wanted to.

  4. Delete the directory in which you have stored your downloaded packages.

Only solution 3 worked for me.

Ref:

  • R-sig-Debian mailing list
  • Option 3 was a combination of answers provided by different people over the last few years, including Chunxiao Xu, Larry Hunsicker and Frank Harrell
like image 142
csgillespie Avatar answered Sep 24 '22 03:09

csgillespie


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.

like image 34
Chunxiao Xu Avatar answered Sep 25 '22 03:09

Chunxiao Xu