Why are data in my package "serialized" and not being read in the most-recent version of R?

Viewed 570

I've written a small package that is useful for sharing functions and example data with colleagues, and I recently added a few more data files to it. The computer I was using when I did that was running R version 4.0.0. However, when I tried to use devtools to install that package from github onto a computer running R version 4.0.2, I get the following message:

NB: this package now depends on R (>= 3.5.0)

WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: 'LaurasHelpers/data/Candidates.RData'

I don't know what it means that my data are serialized. I haven't changed how I save things. Here's how I saved a data.frame called "MyData" to the "data" folder of my package:

 save(MyData, "MyData.RData")

After seeing the initial answer to my post, I then tried

 save(MyData, "MyData.RData", version = 2)

Next, I updated everything:

 devtools::document()
 devtools::build()

From git bash, I pushed my changes to my github repo. Then, back in RStudio, I did:

 remove.packages("LaurasHelpers")
 devtools::install_github(repo = "shirewoman2/LaurasHelpers")

But when I load my package, I still can't load certain data files into my workspace using data(MyData).

Two questions:

  1. Why are data files that I've saved using R 4.0.0 not able to be loaded in R 4.0.2? Both of those are more recent than R 3.5.0.
  2. How do I avoid this problem so that anyone who loads my package can open my pretty simple data set?
1 Answers

The warning doesn't mean/isn't telling you that you can't load files saved in 4.0.0 in 4.0.2. Rather, it's warning you that others using R < 3.5.0 won't be able to load your saved files.

When you save your data, use

save(MyObject, file = "MyObject.RData", version = 2)

to maintain back-compatibility and avoid the warning.

From the R 3.x news file, under version 3.6.0:

Serialization format version 3 becomes the default for serialization and saving of the workspace (save(), serialize(), saveRDS(), compiler::cmpfile()). Serialized data in format 3 cannot be read by versions of R prior to version 3.5.0. Serialization format version 2 is still supported and can be selected by version = 2 in the save/serialization functions. The default can be changed back for the whole R session by setting environment variables R_DEFAULT_SAVE_VERSION and R_DEFAULT_SERIALIZE_VERSION to 2. For maximal back-compatibility, files ‘vignette.rds’ and ‘partial.rdb’ generated by R CMD build are in serialization format version 2, and resave by default produces files in serialization format version 2 (unless the original is already in format version 3).

Related