When I run a RNW file inside RStudio compilation is working. But when I try to run the same RNW file through a BAT file, compilation is not working. I am a Win 7 user, using MixTex...

Actually my aim is to work on a LaTeX editor like TeXMaker and compile a RNW files through a BAT file. After compilation I would like to get a PDF file...

On Rstudio I create a file named "main.Rnw" then I simply press on "Compile PDF" then I get a nice PDF output.

But on texmaker I created the same "main.Rnw" but when I create my a "run.bat" file on the same directory, nothing is working. My "run.bat" contains:

Sweave main.Rnw

I don't find a solution to my issue...

My "main.Rnw" code:

\usepackage{lipsum} % for lorem ipsum text
\title{Test sweave}

%fake text

%just a boxplot text
test <- c(-10,8,6,4,2,0,2,4,6,8,10)

%fake text


enter image description here

  • 4
    Instead of Sweave main.Rnw in your run.bat file, use R.exe CMD Sweave --pdf main.Rnw and run it. :) – Paulo Cereda Feb 3 '13 at 16:36
  • @PauloCereda thank you this solved my issue. But before I had to change create a PATH "C:\Program Files\R\R-2.15.2\bin\x64" Thank you – S12000 Feb 4 '13 at 13:01

I do not think there is such a thing as Sweave.exe in R under Windows. There is only R CMD Sweave.

The other way is to define a custom command as illustrated here: http://yihui.name/knitr/demo/editors/ (it is using knitr instead of Sweave, but the basic idea is the same)

  • Hello, interesting. By the way do you recommend me to use knitr instead of sweave ? – S12000 Feb 5 '13 at 2:25
  • Hello, actually I've just seen that knitr is like an impovement of Sweave, I'm interested to use it. It's working very well with classic latex (pdflatex). However, what's the .bat to get it with xelatex? – S12000 Feb 5 '13 at 2:54
  • @Swiss12000 you can call knit2pdf(..., compiler = 'xelatex') if you want to use XeLaTeX – Yihui Xie Feb 5 '13 at 3:41
  • Ok actually I got it "C:/Program Files/R/R-2.15.2/bin/Rscript.exe" -e "knitr::knit2pdf('%.Rnw', compiler = 'xelatex')" However, now I still don't get how to use knitr when i have some input it's working on the main file but not on the child rnw ... – S12000 Feb 5 '13 at 4:19
  • are you using <<child='foo.Rnw'>>=? Sweave uses \SweaveInput{} but knitr does not support it any more: yihui.name/knitr/demo/sweave – Yihui Xie Feb 5 '13 at 5:44

Have you made sure that Sewave is in your Path? Try running Sweave main.Rnw at the Windows command line. If it doesn't work, you will have to use the complete path to the file, e.g. C:\Program Files\...\sweave.exe to get it to work.

If that doesn't work, try calling the batch file like this:

cmd /C " "batch_file" "arg1" "arg2" ... " 

This may, for some reason, be required if UAC is off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.