Examples for 'base::Quotes'


Quotes

Aliases: Quotes backtick backquote ' " `

Keywords: documentation

### ** Examples

'single quotes can be used more-or-less interchangeably'
[1] "single quotes can be used more-or-less interchangeably"
"with double quotes to create character vectors"
[1] "with double quotes to create character vectors"
## Single quotes inside single-quoted strings need backslash-escaping.
## Ditto double quotes inside double-quoted strings.
##
identical('"It\'s alive!", he screamed.',
          "\"It's alive!\", he screamed.") # same
[1] TRUE
## Backslashes need doubling, or they have a special meaning.
x <- "In ALGOL, you could do logical AND with /\\."
print(x)      # shows it as above ("input-like")
[1] "In ALGOL, you could do logical AND with /\\."
writeLines(x) # shows it as you like it ;-)
In ALGOL, you could do logical AND with /\.
## Single backslashes followed by a letter are used to denote
## special characters like tab(ulator)s and newlines:
x <- "long\tlines can be\nbroken with newlines"
writeLines(x) # see also ?strwrap
long	lines can be
broken with newlines
## Backticks are used for non-standard variable names.
## (See make.names and ?Reserved for what counts as
## non-standard.)
`x y` <- 1:5
`x y`
[1] 1 2 3 4 5
d <- data.frame(`1st column` = rchisq(5, 2), check.names = FALSE)
d$`1st column`
[1] 1.0399732 2.0719397 1.8257723 1.1271399 0.6048309
## Backslashes followed by up to three numbers are interpreted as
## octal notation for ASCII characters.
"\110\145\154\154\157\4\127\157\162\154\144\4"
[1] "Hello World!"
## \x followed by up to two numbers is interpreted as
## hexadecimal notation for ASCII characters.
(hw1 <- "\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21")
[1] "Hello World!"
## Mixing octal and hexadecimal in the same string is OK
(hw2 <- "\110\x65\154\x6c\157\x20\127\x6f\162\x6c\144\x21")
[1] "Hello World!"
## \u is also hexadecimal, but supports up to 4 digits,
## using Unicode specification.  In the previous example,
## you can simply replace \x with \u.
(hw3 <- "\u48\u65\u6c\u6c\u6f\u20\u57\u6f\u72\u6c\u64\u21")
[1] "Hello World!"
## The last three are all identical to
hw <- "Hello World!"
stopifnot(identical(hw, hw1), identical(hw1, hw2), identical(hw2, hw3))

## Using Unicode makes more sense for non-latin characters.
(nn <- "\u0126\u0119\u1114\u022d\u2001\u03e2\u0954\u0f3f\u13d3\u147b\u203c")
[1] "Ħęᄔȭ Ϣ॔༿Ꮣᑻ‼"
## Mixing \x and \u throws a _parse_ error (which is not catchable!)
## Not run: 
##D   "\x48\u65\x6c\u6c\x6f\u20\x57\u6f\x72\u6c\x64\u21"
## End(Not run)
##   -->   Error: mixing Unicode and octal/hex escapes .....

## \U works like \u, but supports up to six hex digits.
## So we can replace \u with \U in the previous example.
n2 <- "\U0126\U0119\U1114\U022d\U2001\U03e2\U0954\U0f3f\U13d3\U147b\U203c"
stopifnot(identical(nn, n2))

## Under systems supporting multi-byte locales (and not Windows),
## \U also supports the rarer characters outside the usual 16^4 range.
## See the R language manual,
## https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Literal-constants
## and bug 16098 https://bugs.r-project.org/show_bug.cgi?id=16098
## This character may or not be printable (the platform decides)
## and if it is, may not have a glyph in the font used.
"\U1d4d7" # On Windows this used to give the incorrect value of "\Ud4d7"
[1] "𝓗"
## nul characters (for terminating strings in C) are not allowed (parse errors)
## Not run: ##D 
##D   "foo\0bar"     # Error: nul character not allowed (line 1)
##D   "foo\u0000bar" # same error
## End(Not run)

## A Windows path written as a raw string constant:
r"(c:\Program files\R)"
[1] "c:\\Program files\\R"
## More raw strings:
r"{(\1\2)}"
[1] "(\\1\\2)"
r"(use both "double" and 'single' quotes)"
[1] "use both \"double\" and 'single' quotes"
r"---(\1--)-)---"
[1] "\\1--)-"

[Package base version 4.2.3 Index]