What is the knitr equivalent of `R CMD Sweave myfile.rnw`?

Jeromy Anglim picture Jeromy Anglim · Jun 8, 2012 · Viewed 10.2k times · Source

What is the command-line knitr equivalent of R CMD Sweave myfile.rnw?

Answer

Maiasaura picture Maiasaura · Jun 8, 2012

The general solution (works regardless of the R version):

Rscript -e "library(knitr); knit('myfile.Rmd')"

Since R 3.1.0, R CMD Sweave has started to support non-Sweave documents (although the command name sounds a little odd), and the only thing you need to do is to specify a vignette engine in your document, e.g.

%\VignetteEngine{knitr::knitr}

To see the possible vignette engines in knitr, use

library(knitr)
library(tools)
names(vignetteEngine(package = 'knitr'))
# "knitr::rmarkdown" "knitr::knitr" "knitr::docco_classic" "knitr::docco_linear"