简体   繁体   中英

Rscript and Backticks

I need to run knit2html on the command line using Rscript . I tried the following code and it works

Rscript -e "(knitr::knit2html(text = '## good', fragment.only = TRUE))"

However, when I introduce R code chunks (or anything involving backticks), the process hangs. So the following does NOT work

Rscript -e "(knitr::knit2html(text = '## good\n `r 1 + 1`',fragment.only = T))"

For the purpose of my use, I only have access to the contents and hence can NOT pass a file to knit2html , which I know will work.

My question is how do I make this work. I know the problem is the backticks and I have tried looking at escaping them, but nothing seems to be working.

it is a shell issue.

On windows it works.

On linux You need to escape the backtick like \\'

I think the reason , some shell interprets the double-quoted string once.

A related issue has been reported once here . You have to use single quotes to avoid shell expansion. I'm not sure if that applies to Windows as well, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM