Search code examples
rpackagedevtoolsr-package

Storing a trained Model in an R Package


I have a trained model that I have saved as an rda file. I would like to put this rda file into an R package (among several other trained models) and call it.

Example:

  lm_good <-readRDS("data/boosted_fit_good.RDS")
  lm_medium <-readRDS("data/boosted_fit_medium.RDS")
  lm_poor <-readRDS("data/boosted_fit_poor.RDS")

I then use devtools to compile the package. When I try to use the package in another instance, I get the trace back error (gzfile(file, "rb") : cannot open the connection).

Any idea?


Solution

  • I found an inelegant solution which included creating a data folder and saving the rda trained/saved models in said directory. I could then call the models from within the package. Only downside is that my users can get to the trained models, but the package works at least.