Экранирование символов

Простые типы / Строки

# \t tab, \n newline, \r carriage return
# \" double quote, \' single quote, \\ backslash

escaped <- "She said \"Hello!\" to me."
# escaped = She said "Hello!" to me.

# Other quotes: no escape needed
other_quotes <- 'She said "Hello!" to me.'
apostrophe <- "It's fine"

# By hex code and Unicode code
capital_a <- c("\x41", "\u0041")
# capital_a = A A

# \\ is one backslash
path <- "C:\\Temp\\new"
# path = C:\Temp\new

# Add quotes: FALSE gives plain ones
quoted <- dQuote("Hello!", FALSE)
# quoted = "Hello!"

# For a shell command
shell_text <- shQuote("my file")
# shell_text = 'my file'

cat("escaped =", escaped, "\n")
cat("other_quotes =", other_quotes, "\n")
cat("apostrophe =", apostrophe, "\n")
cat("capital_a =", capital_a, "\n")
cat("path =", path, "\n")
cat("quoted =", quoted, "\n")
cat("shell_text =", shell_text, "\n")

# print() shows the escapes again
print(path)