Is there an equivalent R of equivalent three-local quotes of other languages?

I know that you can escape special characters with "\", but I am interested in creating commands that will be sent to a terminal that includes special characters, and they cannot read backslashes well.

As a simplified example, I would like to have a command that looks like this:

echo hello "w" or'l'd 

What can be accomplished with something like

 system(command="""echo hello "w" or'l'd""") 

But R does not handle triple quotes. Is there another way? Even catching exit from cat () would be ok. e.g. newCommand = cat ("echo hello \" w \ "orld")

Thanks.

+8
r system cat
source share
2 answers

You can avoid using \" . I would also use shQuote if you intend to run system commands. He takes care of the appropriate escape for you ...

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

You should know that what you see on the screen in the R interpreter is not exactly what the shell will see. For example,

 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 
+7
source share

You can use single quotes:

 system(command='echo hello "w" orld') 
+3
source share

All Articles