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:
Dear List, I am trying to become more familiar with Sweave at the moment, beacuse I am convinced that it will eventually make my life easier. However, I have not found anything relevant in the mail archives about the following problem. Both the article in R-News and the Sweave FAQ suggest that Emacs would be a great development environment for working with Sweave. So far, it doesn't seem to fit that description... Maybe I'm doing something wrong. I am going to describe the way I do things, and hope that people on this list can suggest something more comfortable. I edit the file in one buffer and keep one open for the R prompt. Every time I need to recompile the whole document (Sweave to, say, DVI) I go through the following: 1. call sweave manually via the R prompt 2. open the resulting LaTeX file (I have not found a way to refresh this, maybe there's some magical XEmacs keystroke that rereads the file from the disk?, so I keep opening/closing it) 3. compile the LaTeX file This is a bit tedious as I like to compile often, because I like to see the way my document looks (I know that TeX is WYSIWYM, but I prefer to check my formulas instantly). I would appreciate if people told me how they solve these problems or have found any other way to make Xemacs more comfortable. A "call sweave and then latex on this file in one go" and "show the DVI that was produced from this Rnw file" command would be very useful. Emacs init.el files and similar would help a lot, too. Or maybe I am just trying to use things the wrong way, if so, please enlighten me ;-) If this is not how people use Sweave+Emacs, then tell me how I should do it. Thanks in advance, Tamas Papp