05.12.2012 Views

What documentation exists for R?

What documentation exists for R?

What documentation exists for R?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: R Miscellanea 90<br />

quote at either end, but there are strings that cannot be represented that way, e.g., strings<br />

that themselves contains the quote character. So<br />

> str str<br />

[1] "This \"text\" is quoted"<br />

> cat(str, "\n")<br />

This "text" is quoted<br />

The escape sequences ‘\"’ and ‘\n’ represent a double quote and the newline character<br />

respectively. Printing text strings, using print() or by typing the name at the prompt will<br />

use the escape sequences too, but the cat() function will display the string as-is. Notice<br />

that ‘"\n"’ is a one-character string, not two; the backslash is not actually in the string, it<br />

is just generated in the printed representation.<br />

> nchar("\n")<br />

[1] 1<br />

> substring("\n", 1, 1)<br />

[1] "\n"<br />

So how do you put a backslash in a string? For this, you have to escape the escape<br />

character. I.e., you have to double the backslash. as in<br />

> cat("\\n", "\n")<br />

\n<br />

Some functions, particularly those involving regular expression matching, themselves use<br />

metacharacters, which may need to be escaped by the backslash mechanism. In those cases<br />

you may need a quadruple backslash to represent a single literal one.<br />

In current versions of R (up to 2.4.0) an unknown escape sequence like ‘\p’ is quietly<br />

interpreted as just ‘p’. The development version now emits a warning.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!