Re: [R] Storing data frame in a RDBMS

From: Joe Conway <mail_at_joeconway.com>
Date: Sun 05 Jun 2005 - 06:18:06 EST

Gabor Grothendieck wrote:

> On 6/4/05, Adam Witney <awitney@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';

create table saved_df (id int, df text);

insert into saved_df
  select 1, f from test_serialize('select oid, typname from pg_type

                                   where typname = ''oid''
                                   or typname = ''text''') as t(f);

create or replace function restore_df(text)   returns setof record as '
   unserialize(arg1)
' language 'plr';

select * from restore_df((select df from saved_df where id =1))   as t(oid oid, typname name);
  oid | typname
-----+---------

   25 | text
   26 | oid
(2 rows)

HTH, Joe



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jun 05 06:27:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST