On Fri, 02 Aug 2013, Qiang Wang <uns...@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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.