[R-sig-DB] Saving R-objects to a database
hpages at fhcrc.org
Fri Oct 3 04:17:19 CEST 2008
Christian Ruckert wrote:
> (Un-)encode with rawToChar now worked for a small object, but for bigger
> objects the string is truncated.
You need to serialize with ascii=TRUE otherwise you get a raw vector with
lots of nul bytes that you won't be able to turn into a text without losing
part of it:
- rawToChar() will truncate the text at the first nul byte
- intToUtf8(as.integer()) will silently ignore those nul bytes.
This is because embedded nuls are not supported in character vectors anymore
(which is a good thing).
I'm not 100% sure but I think you won't get any nul bytes if you use
serialize( , ascii=TRUE). Try this:
objToText <- function(object)
rawToChar(serialize(object, NULL, ascii=TRUE))
textToObj <- function(text)
> x0 <- list(1, 2, 3)
I've not tried this on big objects though.
Note that, despite serialize() man page claiming that ascii=FALSE will produce
a more compact binary representation of the object, my experience turns out
to be the opposite.
More information about the R-sig-DB