Processing .Rnw files through Sweave ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To process the file rbasics.Rnw, place the file rbasics.Rnw in your intended working directory, start up R, and type in Sweave("rbasics.Rnw") or Sweave("rbasics") If all goes well (it should, provide you do not tinker too inexpertly with the file contents!), this will generate the latex file rbasics.tex, and graphs that will be included when rbasics.tex is processed through latex or pdflatex. The R code from rbasics.Rnw (much of it also in rbasics.tex) is in the file rbasics.R. You can obtain this code file by typing, from within R Stangle("rbasics.Rnw") or Stangle("rbasics") Files for the exercises ~~~~~~~~~~~~~~~~~~~~~~~ The files rbasics.Rnw, rpractice.Rnw, etc, are designed to generate latex include files. The file wrapper12.Rnw (which is pure latex) can be processed through Sweave(), with the argument stylepath=TRUE, to generate the necessary wrapper file wrapper12.tex. This has the effect of inserting the \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. Another possibility, which generates a LaTeX file that is portable between systems and avoids potential problesm with paths that include one or more spaces, is to include \usepackage{Sweave.sty} in the preamble of wrapper12.Rnw. Then ensure that Sweave.sty is in the LaTeX path. To find the path the the file Sweave.sty that is part of the R installation type, on the R command line: paste(R.home(),"share/texmf/", sep="/") Once you have processed rbasics.Rnw, rpractice.Rnw and wrapper12.Rnw through Sweave, you can then process wrapper12.tex through latex to generate (if all goes well) the pdf file wrapper12.pdf The file r-exercises.Rnw can be processed through Sweave to generate one wrapper file, r-exercises.tex, for all the exercises. 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 Dec 27, 2008.