[R] Storing data frame in a RDBMS

Rajarshi Guha rxg218 at psu.edu
Sat Jun 4 23:08:58 CEST 2005


On Sat, 2005-06-04 at 13:18 -0700, Joe Conway wrote:
> Gabor Grothendieck wrote:
> > On 6/4/05, Adam Witney <awitney at sgul.ac.uk> wrote:
> >>I am using PL/R in PostgreSQL amd have written some functions to
> build my
> >>data frame. However this can take some time with some large datasets
> and I
> >>would like to not have to repeat the process and so I would like to
> save the
> >>data frame. Rather than save/load into the file system I would like
> to be
> >>able to save the entire data frame as a single object in the
> database
> >>
> >>Is this possible?
> > 
> > Check out ?serialize
> 
> Looks like serialize should work nicely:
> 
> create or replace function test_serialize(text)
>   returns text as '
>    mydf <- pg.spi.exec(arg1)
>    return (serialize(mydf, NULL, ascii = TRUE))
> ' language 'plr';

I was trying to do something similar but I needed to this from R itself.
That is, I'd like to save a data.frame or a lm object to a DB.

I looked at serialize but as it just takes a connection object I'm not
sure as to how I would specify say a table in a given DB.

I'm using R 2.0.1, PostgreSQL and Rdbi and Rdbi.PostgreSQL.

I've looked at the docs and I see that there are helper functions to
write a table containing text, numeric or boolean. But its not clear to
me how I would write an arbitrary object to a DB.

Any pointers would be appreciated.

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Eureka!
-- Archimedes




More information about the R-help mailing list