4

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.

Thorst
  • 1,590
  • 1
  • 21
  • 35

2 Answers2

9

I use something along the lines

Rscript -e "require ('knitr'); knit ('test.Rmd')"
cbeleites unhappy with SX
  • 13,717
  • 5
  • 45
  • 57
  • But this is for use with the command-line right? The syntax for batch files are different? At least I've tried a lot of variations of what you've written and can't get it to work. – Thorst Jan 02 '14 at 14:58
  • 2
    If you find a difference between batch and command line, it mostly caused by different paths involved. Try to do a `cd ` first in the batch file. – Dieter Menne Jan 02 '14 at 15:12
  • 1
    It's also possible you might have to define the path to Rscript. This worked for me: `"C:\Program Files\R\R-3.2.2\bin\x64\Rscript.exe" -e "library(knitr); knit('myFile.Rmd')"` – Amit Kohli Oct 20 '16 at 18:59
0

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.