Sweave: run a bat file in Windows 7

1,406

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:
1,406

Related videos on Youtube

S12000
Author by

S12000

Updated on February 04, 2020

Comments

  • S12000
    S12000 almost 4 years

    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

    • Paulo Cereda
      Paulo Cereda almost 11 years
      Instead of Sweave main.Rnw in your run.bat file, use R.exe CMD Sweave --pdf main.Rnw and run it. :)
    • S12000
      S12000 almost 11 years
      @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
  • Claudio Fiandrino
    Claudio Fiandrino almost 11 years
  • S12000
    S12000 almost 11 years
    Hello, interesting. By the way do you recommend me to use knitr instead of sweave ?
  • S12000
    S12000 almost 11 years
    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?
  • Yihui Xie
    Yihui Xie almost 11 years
    @Swiss12000 you can call knit2pdf(..., compiler = 'xelatex') if you want to use XeLaTeX
  • S12000
    S12000 almost 11 years
    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 ...
  • Yihui Xie
    Yihui Xie almost 11 years
    are you using <<child='foo.Rnw'>>=? Sweave uses \SweaveInput{} but knitr does not support it any more: yihui.name/knitr/demo/sweave
  • S12000
    S12000 almost 11 years
    yeah ok is good working, I'll also read the documentation and see your website. Thanks a lot for your package ;)