Abteilung Biostatistik

Consulting Templates

Report Templates
R Code for Data Analysis
R Code for Sample Size Calculations
Sweave Documentation
Compiling Sweave Documents


Report Templates

All files referenced on this page can be obtained by contacting Sarah Haile.

Using Sweave

Using OpenOffice


R Code for Data Analysis

The R package "biostatUZH" contains functions useful in data analysis and also teaching. It is available on request from Kaspar Rufibach.

R Code for Sample Size Calculations

A compilation of R code for Sample Size calculations is available from Sarah Haile.


Sweave Documentation

Sweave website
Sweave.sh script
odfWeave
cacheSweave
reporttools
xtable


Compiling Sweave Documents

There are basically four methods for compiling Sweave documents.

Method 1: Run directly using command line (Linux, Mac)

Here's In this method, you type commands directly into the terminal to compile the document.

R CMD Sweave Sample.rnw
R CMD Stangle Sample.rnw

Then, compile Sample.tex in the LaTeX program of your choice. For this method, all R code should be called directly in your .rnw file. You can use source() commands for this.

Method 2: makefile (Linux, Mac)

Save a file called "makefile" (no file extension, all lower case) in the same folder as your .rnw file. It can be used to run all the commands you want to run, including Sweave, Stangle, latex, and bibtex. You will have to change the filename for each document. To run, use the commandline to go to the folder where the file is stored and type make. For this method, all R code should be called directly in your .rnw file. You can use source() commands for this (see Sample.rnw above).

Mac users will need to make sure that Apple Developer's Tools have been installed (Xcode from the disks which came with the computer, or Xtools, which can be downloaded from the apple.com website.) The capability to run a makefile using make is only available with those tools.

Method 3: A Script: Sweave.sh (Linux, Mac), or Sweave.bat (Windows)

For this method, download Sweave.sh (link is above) into ~/bin (in Linux or Mac). Then, make the script executable by running sudo chmod u+x ~/bin/Sweave.sh .This allows you to run the script. For this method, all R code should be called directly in your .rnw file. You can use source() commands for this.

When you want to compile a document, navigate to the folder where your document is located and type in Sweave.sh filename.rnw . By default, the script only runs the Sweave commands, creating a .tex file, and then cleans up extra files (including figures) from the folder. There are, however, a large number of options this script. For example, running Sweave.sh -t -ld -nc filename.rnw means that the script, runs Sweave and Stangle (-t, creates a R file with only the code), compiles a pdf using pdflatex (-ld) and does not delete any extra files (-nc).

There is also a batch file available from CRAN for use on Windows. It should run both Sweave and Latex commands, and while I have not tried it, it might be useful to some of you. The link is below.

Sweave.sh script
Sweave Batch File

Method 4: Using R and your favorite LaTeX program (Linux, Mac, Windows)

This is the easiest method, or the hardest, depending on how you work, but potentially the easiest one that can be used in Windows. (Alternately, there is a batch file that can be used to compile Sweave documents in Windows)

top
Mobile Ansicht | Klassische Ansicht