Sacha Epskamp
Sacha Epskamp

Reputation: 47582

What exactly does R CMD Sweave --pdf do?

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?

Upvotes: 10

Views: 1560

Answers (3)

gregmacfarlane
gregmacfarlane

Reputation: 2283

I don't know much about the interior workings, but I know the development version of RStudio will let you select between knitr and Sweave as well as between pdflatex and xelatex, and gives bibtex as an option.

Upvotes: 0

Josh O'Brien
Josh O'Brien

Reputation: 162411

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.

Upvotes: 10

Paul Hiemstra
Paul Hiemstra

Reputation: 60964

You could try to perform the conversion from Rnw to pdf manually en see how many times the respective steps are needed to get the same result as R CMD Sweave.

Upvotes: 0

Related Questions