Search code examples
databaserobjectr-faq

Storing R Objects in a relational database


I frequently create nonparametric statistics (loess, kernel densities, etc) on data I pull out of a relational database. To make data management easier I would like to store R output back inside my DB. This is easy with simple data frames of numbers or text, but I have not figured out how to store R objects back in my relational database. So is there a way to store a vector of kernel densities, for example, back into a relational database?

Right now I work around this by saving the R objects to a network drive space so others can load the objects as needed.


Solution

  • Use the serialization feature to turn any R object into a (raw or character) string, then store that string. See help(serialize).

    Reverse this for retrieval: get the string, then unserialize() into a R object.