Qiang Wang
2013-Aug-02 06:53 UTC
[R] cannot base64decode string which is base64encode in R
Hi, I'm struggling with encode/decode strings in R. Don't know why the second example below would fail. Thanks in advance for your help. succeed: s <- "saf" x <- base64encode(s) y <- base64decode(x, "character") fail: s <- "safs" x <- base64encode(s) y <- base64decode(x, "character") [[alternative HTML version deleted]]
Enrico Schumann
2013-Aug-03 07:49 UTC
[R] cannot base64decode string which is base64encode in R
On Fri, 02 Aug 2013, Qiang Wang <unsown at gmail.com> writes:> Hi, > > I'm struggling with encode/decode strings in R. Don't know why the second > example below would fail. Thanks in advance for your help. > succeed: s <- "saf" x <- base64encode(s) y <- base64decode(x, "character") > fail: s <- "safs" x <- base64encode(s) y <- base64decode(x, "character") >And the first example works for you? require("base64enc") s <- "saf" x <- base64encode(s) ## Error in file(what, "rb") : cannot open the connection ## In addition: Warning message: ## In file(what, "rb") : cannot open file 'saf': No such file or directory ?base64encode says that its first argument is "data to be encoded/decoded. For ?base64encode? it can be a raw vector, text connection or file name. For ?base64decode? it can be a string or a binary connection." Try this: rawToChar(base64decode(base64encode(charToRaw("saf")))) ## [1] "saf" -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net