[R] backslash quirk in paste
wdunlap at tibco.com
Sat Dec 6 20:35:12 CET 2014
"\\" is stored as a single backslash, just as "\n" is a single newline
character. It is printed with an extra backslash.
> cat(paste0("\\", "\n"))
On Sat, Dec 6, 2014 at 11:00 AM, Prof J C Nash (U30A) <nashjc at uottawa.ca>
> This is NOT critical. It arose due to a fumble fingers when developing
> an R example, but slightly intriguing.
> How could one build a string from substrings with a single backslash (\)
> as separator. Here's the reproducible example:
> fname = "John"; lname = "Smith"
> paste(fname, lname)
> paste(fname, lname, sep=" / ")
> # BUT there's a glitch with backslash
> paste(fname, lname, sep=" \ ") # because of escaping character
> paste(fname, lname, sep=' \ ')
> paste(fname, lname, sep=' \\ ') # because of escaping character
> bslash <- "\\"
> paste(fname, lname, sep=bslash)
> Possibly the answer is that R never allows a single backslash in its
> strings, but I can imagine possible cases where I might want to output
> such lines, for example, in documenting this.
> Best, JN
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help