【发布时间】:2016-07-07 07:05:48
【问题描述】:
如何在不写入磁盘的情况下将原始向量转换回 R 对象?我想读取 base64 数据流并将其转换为它的 R 对象表示。这是一个示例 - 我如何从原始向量中取回 lm 对象?
## some rdata -- writes to temp file!
mod <- lm(mpg ~ cyl, data=mtcars)
f1 <- tempfile()
save(mod, file=f1, compress="bzip2")
library(base64enc)
r1 <- readBin(f1, "raw", n=file.info(f1)[1, "size"])
r2 <- base64decode(base64encode(file(f1, "rb"))) # emulate input base64
identical(r1, r2)
## I can get mod back by writing to file and loading, but how to just
## load from a raw vector?
rm(mod) # get rid of mod
f2 <- tempfile()
writeBin(r2, f2)
load(f2) # mod is back
【问题讨论】:
标签: r base64 type-conversion