Is there an R equivalent of other languages triple quotes?

You can use single quotes:

system(command='echo hello "w" orld')

You can escape the " with \". I would also use shQuote if your intention is to run system commands. It takes care of the relevant escaping for you...

shQuote( "hello \"w\" orld" , type = "cmd" )
#[1] "\"hello \\\"w\\\" orld\""

You should be aware that what you see on-screen in the R interpreter is not exactly what the shell will see.. e.g.

paste0( "echo " , shQuote( "hello \"w\" orld" , type = "sh") )
#[1] "echo 'hello \"w\" orld'"

system( paste0( "echo " , shQuote( "hello \"w\" orld" , type = "sh") ) )
#hello "w" orld

Raw characters were introduced in R 4.0.0, released 2020-04-27:

There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence ‘⁠)"⁠’. This makes it easier to write strings that contain backslashes or both single and double quotes. For more details see ?Quotes.

> cat(r"(echo hello "w" or'l'd)")
echo hello "w" or'l'd

Tags:

System

R

Cat