Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does R CMD Sweave --pdf do?

Tags:

r

sweave

I noticed this in the changes of R 2.14:

R CMD Sweave now has a --pdf option to produce a PDF version of the processed Sweave document.

Trying it out, I noticed that it not only ran pdfLaTeX on the resulting tex but also correctly included bibTeX references and cleaned up afterwards. Seems like a very very nice way of using Sweave now (not to mention how easy it now is to implement the whole routine in editors).

But what exactly is this now running? I couldn't find any more details on it. It seems Sweave -> pdflatex -> bibtex -> pdflatex -> pdflatex at least?

like image 430
Sacha Epskamp Avatar asked Nov 18 '11 14:11

Sacha Epskamp


1 Answers

Thanks for the question. I had wondered myself about the code behind that 'automagical' process.

R CMD Sweave --pdf ultimately calls tools::texi2dvi, which:

Run[s] latex and bibtex until all cross-references are resolved and create[s] either a dvi or PDF file.

(See here for more texi2dvi details).

Here is the chain of events set into motion by an R CMD Sweave --pdf call:

  • The source file rcmdfn.c has code that instructs R CMD Sweave to run utils:::.Sweave() --args" through Rterm.exe.

  • If --pdf is set, utils:::.Sweave() calls tools::texi2pdf() to process the Sweave file.

  • texi2pdf() in turn calls tools::texi2dvi().

  • Finally, texi2dvi() looks at the environment to learn which tools are available to it, and does the work described in the help file linked above.

like image 172
Josh O'Brien Avatar answered Nov 03 '22 00:11

Josh O'Brien