ofrendo
3/31/2016 - 8:20 AM

Serialize R object to string

Serialize R object to string

test <- lm(iris)
serialized <- serialize(test, NULL) # this is hex
serializedResult <- paste0(serialized, collapse="") # want to store this

# want to get "test" back from this
toRawSplit <- chop(serializedResult)
toRaw <- as.raw(paste0("0x", toRawSplit))
unserialized <- unserialize(toRaw)


chop <- function(x) {
  substring(x, seq(1,nchar(x),2), seq(2,nchar(x),2))
}