I had the same problem as the OP, but in my case the problem .rds files were not 0 bytes but had file size >0 and were full of NULL
characters (at least that's what I saw when I opened them in Notepad++)
By using debugonce(loadNamespace)
before loading the library that was giving me the error (in my example it was the VIM
package) I eventually traced my problem to corrupted .rds files in the META folder of the forcats
package, which was installed as a 5th generation import when I installed VIM
(In the rstudio environment pane)
__NamesSpacesLoading__ chr[1:5] "forcats" "haven" "rio" "car" "VIM"
I then fixed by VIM
problem simply by removing and reinstalling forcats
Adapting the code in @csgillespie accepted answer, I could have found this by trying to read all the rds files as below
paths = .libPaths()
l <- list.files(paths,
pattern = "*\\.rds$",
ignore.case = T,
recursive = T,
full.names = TRUE)
checkRDS <- function(file) {
tryCatch({
readRDS(file)
"OK"
},
error = function(cond) {
return("Error")
})
}
l[sapply(l,checkRDS)=="Error"]