base64编码一个.Rda文件 [英] Base64 encoding a .Rda file
问题描述
所有,
我试图找出如何把.Rda文件到Base64编码它被运到并从一个API。我真的有如何做到这一点挣扎。下面是我得到了什么,但我认为这是遥远的目标:
I'm trying to figure out how to put a .Rda file into Base64 encoding for it to be shipped to and from an API. I am really struggling with how to do this. Here's what I've got, but I think it's way off target:
cuse <- read.table("http://data.princeton.edu/wws509/datasets/cuse.dat", header=TRUE)
lrfit <- glm( cbind(using, notUsing) ~ age + education + wantsMore , family = binomial, data=cuse)
filename <- "C:/test.Rda"
save(lrfit, file=filename)
library("base64enc")
tst <- base64encode(filename)
save(tst, file="C:/encode.Rda")
base64decode(file="C:/encode.Rda", output = "C:/decode.Rda")
当我尝试打开德code.Rda文件时,它抛出一个神奇的数字错误。就像我说的,我觉得我的路要走基地在这里,任何帮助将是AP preciated。谢谢你这么多。
When I try to open the decode.Rda file, it throws a magic number error. Like I said, I think I'm way off base here, and any help would be appreciated. Thank you so much.
推荐答案
步骤下面一个正确的顺序应该允许正确的编码/解码
Here a correct sequence of steps that should allow for the correct encoding/decoding
#sample data
dd<-iris
fn <- "test.rda"
fnb4 <- "test.rdab64"
#save rda
save(iris, file=fn)
#write base64 encoded version
library(base64enc)
txt<-base64encode(fn)
ff<-file(fnb4, "wb")
writeBin(txt, ff)
close(ff)
#decode base64 encoded version
base64decode(file=fnb4, output = "decode.rda")
(load("decode.rda"))
# [1] "iris"
问题是你的第二个保存()
。这是创建具有的base64数据连接在codeD另一RDA文件。它不是写一个base64连接的RDA文件刻录到光盘的codeD版本。
The problem was your second save()
. That was creating another RDA file with the base64 data encoded inside. It was not writing a base64 encoded version of the RDA file to disc.
这篇关于base64编码一个.Rda文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!