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
Simon O'Hanlon
source share