R Run knitr from a batch-file (windows)

Viewed 3844

I run some automatic reports each day with batch-files on my windows-computer. But how do I do this with a .rmd file and generate the html-output?

So, this works for me using a batchfile with a normal .R file:

"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods 
"C:\R\R-3.0.1\bin\x64\Scripts\models.R"

But, this won't:

"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods,knitr 
"C:\R\R-3.0.1\bin\x64\Scripts\test_knitr.Rmd"

I've tried some variations inspired by command-line like:

"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods,knitr 
knit("C:\R\R-3.0.1\bin\x64\Scripts\test_knitr.Rmd")

But no succes so far! Im a total knitr/.rmd newbee, so I'm not even sure it can be done.

2 Answers

I use

"C:\Program Files\R\R-3.5.1\bin\Rscript.exe" -e "library('knitr'); knit('C:/Users/test_doc.Rmd')"
pause

Like "cbeleites supports Monica" said using the full path.

Don't forget that in R we must use "/" and not "\" like in Windows.

So in the R call we use "\" because we are talking to Windows and in the knit we use "/" because we are talking to R.

I hope it help.

Related