R Can I use .rds files for my data in a package?

Viewed 2001

I'm trying to convert some code into a package. According to the documentation, only .RData files should be in the data directory, but I'd rather use .rds files because they don't retain the file name. There are times when I save with a different name than I want to use when reading in later. And I really only want to have one data set for file, so the ability of .RData files to store more is actually a negative.

So my question is why not allow .rds files in the package data directory? Or is there another way to solve this problem?

2 Answers

Old question - but you can. It is a two step process.

  1. save your data as .rds file
  2. create an R file in the data directory which loads the rds data.

I am doing this as followed:

rdsFile <- paste0(schemeName, "_example.rds")
saveRDS(
      dmdScheme_example,
      file = here::here( "data", rdsFile )
    )
cat(
      paste0(schemeName, "_example <- readRDS(\"./", rdsFile, "\")"),
      file = here::here( "data", paste0(schemeName, "_example.R") )
    )
Related