Processing .Rnw files through Sweave ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To process the file sec1-1.Rnw, ensure that it is in your working directory, start up R, and type Sweave("sec1-1.Rnw") or Sweave("sec1-1") If all goes well (it should, providing you do not tinker too inexpertly with the file contents!), this will generate the latex file sec1-1.tex, and graphs that will be included when sec1-1.tex is processed through latex or pdflatex. For this purpose the contents of sec1-1.tex need to be enclosed between LaTeX preamble commands and \end{document}. The wrapper file wrapper.tex that is generated when wrapper.Rnw is processed through LaTeX is designed for this purpose. Both pdf and postscript versions of the graphics file are generated in the working directory, and the necessary \includegraphics statement is placed in sec1-1.tex. The R code from sec1-1.Rnw (much of it also in sec1-1.tex) is in the file sec1-1.R. You can extract this code by typing, from within R Stangle("sec1-1.Rnw") or Stangle("sec1-1") The wrapper file ~~~~~~~~~~~~~~~~ By processing the file wrapper.Rnw (which is pure latex) through Sweave() the wrapper file wrapper.tex is generated. The effect is to insert a \usepackage{} command that tells latex where to find the Sweave latex package. This will certainly, on a PC, be in a different place from a Mac. Thus, do not use the existing file wrapper.tex on your machine. Process wrapper.Rnw through Sweave() to generate a file wrapper.tex that is right for your setup. Once you have processed both sec1-1.Rnw and wrapper.Rnw through Sweave, you can then process wrapper.tex through pdflatex to generate (if all goes well) the pdf file wrapper.pdf. Or, you can use latex and dvipdf. What is Sweave? ~~~~~~~~~~~~~~ To quote from the help file for Sweave() "'Sweave' provides a flexible framework for mixing text and S code for automatic report generation. The basic idea is to replace the S code with its output, such that the final document only contains the text and the output of the statistical anlysis. [It allows] automatic generation of reports by mixing word processing markup (like latex) and S code. The S code gets replaced by its output (text or graphs) in the final markup file. This allows to re-generate a report if the input data change and documents the code to reproduce the analysis in the same file that also produces the report." The Sweave syntax is based on the Noweb literate syntax. Reference: Friedrich Leisch: Sweave User Manual, 2002 John Maindonald March 7, 2013.