Recommendations for developing Sweave documents Recommendations for developing Sweave documents r r

Recommendations for developing Sweave documents


A few other R users I talked to use a 'one-directory-per-project' setup, and a simple Makefile. As you suspected, that works well with Emacs/ESS.

I tend to just call a simple shell script sweave which I wrote before before 'R CMD Sweave' was added (as I find re-creating or copying the Makefile unappealing, YMMV). I also use Emacs and an auto-refreshing pdf viewer (like okular or kpdf). Emacs23 can preview pdf files directly too but I have yet to switch my work flow to that.

edd@ron:~$ cat bin/sweave#!/bin/bash -efunction errorexit () {    echo "Error: $1"    exit 1}function filetest () {    if [ ! -f $1 ]; then       errorexit "File $1 not found"    fi    return 0}if [ "$#" -lt 1 ]; then    errorexit "Need to specify argument file"fiBASENAME=$(basename $1 .Rnw)RNWFILE=$BASENAME.Rnwfiletest $RNWFILEecho "library(tools); Sweave(\"$RNWFILE\")" \      | R --no-save --no-restore --slaveLATEXFILE=$BASENAME.texfiletest $LATEXFILE && pdflatex $LATEXFILE


You can do everything that you suggest there with the StatET plugin for Eclipse. That's what I use for Sweave development; it understands both latex and R very well, including syntax highlighting, etc.

You can get it here: http://www.walware.de/goto/statet.

Longhow Lam has written a nice guide: http://www.splusbook.com/Rintro/R_Eclipse_StatET.pdf.

http://www.statalgo.com/?p=93


I use TeXShop on OS X to produce all of my LaTeX and Sweave reports. For me, a new compilation pipeline is as simple as adding a file, called Sweave.engine to ~/Library/TeXShop/Engines/ which contains the following:

#!/usr/bin/env Rscriptargs <- commandArgs(T)fname <- strsplit(args[1],'\\.')[[1]][2]Sweave(paste(fname,'Rnw',sep='.'))system(paste('pdflatex',paste(fname,'tex',sep='.')))

Sweave is now a selectable method of compiling a document inside TeXShop. I can set it to be the default for a document by adding the following TeX hash-bang to the top of the file:

% !TEX TS-program = Sweave

Hitting Cmd-T will typeset the document- the pdf automatically pops up in a separate window. TeXShop also incorporates SyncTeX technology so a Cmd-Click in the Rnw source will highlight the corresponding output in the PDF window and a Cmd-Click in the PDF window will highlight the corresponding input in the Rnw source.

TeXShop is mac-only but a great Qt/poppler-based clone, TeXworks, is available for Linux, Windows and Mac and supports many of the same features-- including TeX hash-bangs and SyncTeX. TeXworks has reached a level of maturity where it is included in version 2.8 of the MikTeX package for Windows.