I am working on a function which is part of a package. This package contains a template for a new package, and a function which creates R data for the new package which has to have a dynamic name provided to this function.
At the moment I am doing the following:
makedata <- function(schemeName, data) {
rdsFile <- paste0(schemeName, ".rds")
varName <- paste0(schemeName)
saveRDS(
data,
file = file.path( ".", "data", rdsFile )
)
cat(
paste0(varName, " <- readRDS(\"./", rdsFile, "\")"),
file = file.path( ".", "data", paste0(varName, ".R") )
)
}
makedata(name = "test", data = letters)
which results in two files in the data directory:
a file
test.rds
containingletters
but which is not loaded by R when the package is loaded (rds is not supported)a file
test.R
which has the codetest <- readRDS("./test.rds")
and which causes, when the package is loaded, the data intest.rds
to be loaded in the variabletest
which than containsletters
.
Now CRAN does not like rds files in the data directory.
Is there another way that I can use the standard formats (preferably RData
) to achieve this?