How to handle binary strings in R? How to handle binary strings in R? database database

How to handle binary strings in R?


You need

stringModel <- as.character(serialModel)

for a character representation of the raw bit codes. rawToChar will try to convert the raw bit codes, which is not what you want in this case.

The resulting stringModel can be converted later on back to the original model by :

newSerialModel <- as.raw(as.hexmode(stringModel))newModel <- unserialize(newSerialModel)all.equal(model,newModel)[1] TRUE

Regarding the writing of binary types to databases through RODBC : as for today, the vignette of RODBC reads (p.11) :

Binary types can currently only be read as such, and they are returned as column of class "ODBC binary" which is a list of raw vectors.


A completely different approach would be to simply store the output of capture.output(dput(model)) along with a descriptive name and then reconstitute it with <- or assign(). See comments below regarding the need for capture.output().

> dput(Mat1)structure(list(Weight = c(7.6, 8.4, 8.6, 8.6, 1.4), Date = c("04/28/11", "04/29/11", "04/29/11", "04/29/11", "05/01/11"), Time = c("09:30 ", "03:11", "05:32", "09:53", "19:52")), .Names = c("Weight", "Date", "Time"), row.names = c(NA, -5L), class = "data.frame")> y <- capture.output(dput(Mat1))> y <- paste(y, collapse="", sep="")  # Needed because capture output breaks into multiple lines> dget(textConnection(y))  Weight     Date   Time1    7.6 04/28/11 09:30 2    8.4 04/29/11  03:113    8.6 04/29/11  05:324    8.6 04/29/11  09:535    1.4 05/01/11  19:52> new.Mat <- dget(textConnection(y))