Skip to content
Prev 31437 / 398506 Next

Working comfortably with (X)Emacs + Sweave

Assuming that you work on GNU/Linux, here's my setup (mostly borrowed from 
Doug Bates):

My .emacs has (apart from the usual ESS and auc-tex stuff):


(defun Rnw-mode ()
  (require 'ess-noweb)
  (noweb-mode)
  (if (fboundp 'R-mode)
      (setq noweb-default-code-mode 'R-mode)))
(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
(add-to-list 'auto-mode-alist '("\\.Snw\\'" . Rnw-mode))
(setq reftex-file-extensions
      '(("Snw" "Rnw" "nw" "tex" ".tex" ".ltx") ("bib" ".bib")))
(setq TeX-file-extensions
      '("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))



I have the following script installed:

deepayan 12:59:03 $ cat /usr/local/bin/Sweave.sh
#!/bin/sh
echo "library(tools);Sweave('"$1"')" | /usr/bin/R --vanilla --silent




In the working directory, I have a Makefile similar to:

deepayan 13:01:15 $ cat Makefile

DEFAULT_PDF = filename
DEFAULT_PS = filename

all : $(DEFAULT_PDF:=.pdf) $(DEFAULT_PS:=.ps)

%.tex : %.Rnw
        Sweave.sh $<

%.pdf : %.tex
        texi2dvi --pdf $<

%.dvi : %.tex
        texi2dvi $<

%.ps : %.dvi
        dvips -o -q $<




With all this (customized according to your tastes), just edit the 
filename.Rnw file, and invoke make (I tend to keep a gv open in 'watch file' 
mode).

Hope that helps.

Deepayan
On Wednesday 30 April 2003 12:11 pm, Tamas Papp wrote: