JD Long JD Long - 1 year ago 122
R Question

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download