Base64 encoding a .Rda file

前端 未结 1 342
闹比i
闹比i 2021-01-27 00:29

All,

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 w

相关标签:
1条回答
  • 2021-01-27 01:04

    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"
    

    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.

    0 讨论(0)
提交回复
热议问题