Search code examples
rpackageroxygen2

Saving text file in the data folder of an R package


I am trying to save a text file in the data folder of a private package I am developing. I tried the following:

my_text <- “Some text string”
save.RDS(my_text, file = “C/…./package_name/data/mytext.rda”)

When I try to build the document, I get the error:

Error in FUN(X[[i]], ...) : 
  bad restore file magic number (file may be corrupted) -- no data loaded
Calls: suppressPackageStartupMessages ... <Anonymous> -> load_all -> load_data -> unlist -> lapply -> FUN
In addition: Warning message:
file mytext.rda' has magic number 'X'
  Use of save versions prior to 2 is deprecated 
Execution halted

Exited with status 1.

What could I do to save the text?


Solution

  • Best way is using devtools::use_data(my_text, internal = TRUE) as mentioned by @PoGibas.