Skip to content
Prev 60076 / 398503 Next

Problem with print() and backslashes.

<snip></snip>
\!

also
chr "\!"


What is important to keep in mind is that the string "\\!" has *two*
characters (when read by R), not three (as on the screen or in your editor);
[1] 2

The first character is "\\", which needs to be escaped in order for the R
parser to recognize it as '\'. The second is of course '!'. I agree that
[1] 1

might be confusing. The thing is that some characters remain the same
escaped or not, whereas others have certain mappings to non-printable ASCII
codes (0-255).
[1] TRUE

and the well known(?) newline character
[1] FALSE

Another good example:
[1] TRUE

Given a string, print() gives you the escaped version of the string, which
can be useful for debugging, if you want to cut'n'paste and so on. Thus,
[1] "Hello world\n!\n"

and
Hello world
!

Hope this helps!

Henrik Bengtsson