[R] Saving R-objects to a database

Christian Ruckert cruckert at uni-muenster.de
Thu Sep 25 15:58:28 CEST 2008


Someone solved the problem of saving R-objects to a database?

These are the two varaints I've tried so far without success:

1)
ser = rawToChar(serialize(obj, NULL, ascii=TRUE))
dbSendQuery(link, paste("insert into table values(1, '",ser,"')",sep=''))

The field to save the object in the MySQL Database is of type text.

unser = dbGetQuery(link,"select * from table where id=1")
Warning message:
In mysqlFetch(res, n, ...) :
   RS-DBI driver warning: (internal error: row 0 field 1 truncated)


2)
ser = serialize(obj, NULL)
dbSendQuery(link, paste("insert into table values(1, '",ser,"')",sep=''))

The field to save the object in the MySQL Database is of type blob.

result = dbGetQuery(link,"select * from table where id=1")

unser = unserialize(result[1,"object_column"], NULL)
Error in unserialize(result[1, "object_column"], NULL) : unknown input 
format
In addition: Warning message:
In unserialize(result[1, "object_column"], NULL) :
   unserialize()from a character string is deprecated and will be 
withdrawn in R 2.8.0


Any suggestion is welcome.

Best,
Christian



More information about the R-help mailing list