可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
These are suggestions I have come across:
- Delete your
.Rhistory
and .RData
files in the directory in which you are running R.
- Run
update.packages()
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.
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
回答2:
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:
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
回答4:
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
回答5:
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:
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.
回答7:
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.
回答8:
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.
回答9:
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)
- set up a new working directory
- 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
- 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.
回答10:
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.