Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{lipsum} % for lorem ipsum text
\begin{document}
\title{Test sweave}
\maketitle

%fake text
\lipsum[1]

%just a boxplot text
<<fig=TRUE>>=
test <- c(-10,8,6,4,2,0,2,4,6,8,10)
boxplot(test)
@

%fake text
\lipsum[2]

\end{document}

enter image description here

share|improve this question
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 –  Swiss12000 Feb 4 '13 at 13:01

2 Answers 2

up vote 1 down vote accepted

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)

share|improve this answer
    
Hello, interesting. By the way do you recommend me to use knitr instead of sweave ? –  Swiss12000 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? –  Swiss12000 Feb 5 '13 at 2:54
    
@Swiss12000 you can call knit2pdf(..., compiler = 'xelatex') if you want to use XeLaTeX –  Yihui 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 ... –  Swiss12000 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 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.

share|improve this answer
    
Welcome to TeX.SX. –  Claudio Fiandrino Feb 3 '13 at 18:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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