Change: 2 years later, I can’t reproduce this error with R 3.6, so I suggest fixing it to update R. Anyone who can reproduce the error, please post your version of R as a comment.
I don’t know where the problem came from, but if you do not find anything better, here is the solution. Before returning to saveRDS, it will return an error for str, so you will not have a problem with damage
saveRDS2 <- function(object,file){str(object);saveRDS(object,file)}
df <- data.frame(a = c(1,2), b = c(3,4))
saveRDS2(df, "test.rds")
readRdsFile <- readRDS("test.rds")
saveRDS2(df1, "test.rds")
readRdsFile2 <- readRDS("test.rds")