[R-sig-DB] How to store R objects in blob in MySQL?
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Fri Feb 8 16:32:56 CET 2008
On 8 February 2008 at 14:31, Rainer M Krug wrote:
| Hi
|
| I was thinking - how can I store R objects in a blob field? Normal
| dataframes can be nicely stored in a table - but is theree a mechanism to
| store objects in a blob field?
I tried to answer that question in an email I sent you two days ago:
From: Dirk Eddelbuettel <edd using eddelbuettel.com>
To: Rainer M Krug <r.m.krug using gmail.com>
Cc: Richard Pearson <richard.pearson using postgrad.manchester.ac.uk>,
R-help using r-project.org
Subject: Re: [R] advice requested re: building "good" system (R, SQL db)
for handling large datasets
Date: Wed, 6 Feb 2008 09:58:56 -0600
On Wed, Feb 06, 2008 at 02:34:52PM +0200, Rainer M Krug wrote:
> R objects in blobs - I never thought about that. Could you elaborate on how
> to do something like that (I am using RMySQL)?
Look at help(serialize) -- any R object can be turned into a suitable
representation, either binary (more efficient) or ascii (possibly
'safer').
Store that, retrieve it later, reconstruct the object and be merry :)
> tmpDf <- data.frame(a=1:10, b=LETTERS[1:10], c=rnorm(10))
> serDf <- serialize(tmpDf, NULL, ascii=TRUE)
> rm(tmpDf)
> head(unserialize(serDf))
a b c
1 1 A -0.6945820
2 2 B -0.2960084
3 3 C -0.2514302
4 4 D -0.7318635
5 5 E -0.1698489
6 6 F 0.4331521
>
Dirk
Now, look at what serDf actually is -- an ascii vector. You can simply write
that to virtually any db system into a char field of variable length. You
could also create an actual blob object via
serDfBin <- serialize(tmpDf, NULL, ascii=FALSE)
but you can't print that easily to the console for checks pp. It is however
a binary blob, so if you wanted to write that, you could.
Does this help?
Dirk
| I am using MySQL under Linux.
|
| Thanks
|
| Rainer
|
|
| --
| Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
|
| Plant Conservation Unit Department of Botany
| University of Cape Town
| Rondebosch 7701
| South Africa
|
| [[alternative HTML version deleted]]
|
| _______________________________________________
| R-sig-DB mailing list -- R Special Interest Group
| R-sig-DB using stat.math.ethz.ch
| https://stat.ethz.ch/mailman/listinfo/r-sig-db
--
Three out of two people have difficulties with fractions.
More information about the R-sig-DB
mailing list