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 00:45

This happened to me after I had to reboot my machine in the middle of installing several R packages. I removed the latest installed packages by physically removing the files in the appropriate library directory, reinstalled them, and all was well. I also had to remove a 00LOCK directory in the library directory.

查看更多
放我归山
3楼-- · 2020-01-25 00:49

I checked for this issue on several forums and then I tried this and it worked for me:

1) Remove the ggplot2 package first

remove.packages("ggplot2")

2) Install the package again

install.packages("ggplot2")

3) restart rstudio and install your package again, hope this helps

Seems that the issue was with the required package (ggplot2 in my case) got corrupt and was hampering the installation of any new dependent package.

查看更多
啃猪蹄的小仙女
4楼-- · 2020-01-25 00:50

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
查看更多
劫难
5楼-- · 2020-01-25 00:52

Something simple to try: if it is an .rda file use load instead of readRDS. You can then save the loaded file as an .rds and try readRDS again.

查看更多
何必那么认真
6楼-- · 2020-01-25 00:59

Here is what I had to do to solve this error:

  • Open your Rstudio, go to install tab under packages
  • Note your install to library path.(where your package will be saved)
  • Go to the install library path.And hard delete the recent packages
  • Refresh you package details in Rstudio
查看更多
\"骚年 ilove
7楼-- · 2020-01-25 00:59

You might have some problem with R packages . See if the problem has occurred after you installed some packed or did you copied the packages.

What you can do is Copy all the packages from Library and save it somewhere, then Copy some packages on the Library and restart the R test it and see how it works you have to try with all the packages one by one . I has the same issue and it was due to package problem.

查看更多
登录 后发表回答