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?
rds extension. To read a R data file, invoke the readRDS() function. As with a CSV file, you can load a RDS file straight from a website, however, you must first run the file through a decompressor before attempting to load it via readRDS . A built-in decompressor function called gzcon can be used for this purpose.
Rds files store a single R object. According to R documentation: These functions provide the means to save a single R object to a connection (typically a file) and to restore the object, quite possibly under a different name.
rdata or . rda) is a format designed for use with R, a system for statistical computation and related graphics, for storing a complete R workspace or selected "objects" from a workspace in a form that can be loaded back by R.
The default R datasets included in the base R distribution Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.
The only acceptable data files in /data
are those saved with 'save', which means they are in the .RData format. Hadley's link, which @r2evans points to, says this. As does section 1.1.6, which @rawr points to.
Old question - but you can. It is a two step process.
.rds
fileI 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") )
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With