3

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.

Ramnath
  • 54,439
  • 16
  • 125
  • 152

2 Answers2

0

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.

agstudy
  • 119,832
  • 17
  • 199
  • 261
0

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.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Tried this `Rscript -e '(knitr::knit2html(text = "## good\n `r 1 + 1`", fragment.only = TRUE))'` and got this. `ARGUMENT '~+~`r~+~1~+~+~+~1`",~+~fragment.only~+~=~+~TRUE))' __ignored__` – Ramnath Dec 11 '12 at 03:19
  • OK. It looks like an issue of your specific shell; this works for me: Rscript -e '(knitr::knit2html(text = "## good\n `r 1 + 1`", fragment.only = TRUE))' (backticks were eaten by SO). I'm under Ubuntu, and my `$SHELL` is `bash`. I do not know what is the default shell for Mac (is there such a thing `echo $SHELL`?) – Yihui Xie Dec 11 '12 at 04:24
  • I did `echo $SHELL` and it returned `bin/bash`. I need to dig deeper what the source of error is. – Ramnath Dec 11 '12 at 16:01