[R] calling sweave function from LaTex re directories, formatting

Sam McClatchie s.mcclatchie at niwa.co.nz
Mon Feb 10 03:12:03 CET 2003

System info:
Mandrake 9.0
R Version 1.6.1
ESS 5.1.21
Emacs 21.2.1


I have followed suggestions by David Whiting, Friedrich Leisch and Frank 
Harrell, but have a few more queries.

1. On formatting:

I added the suggested sweave customization to my .emacs file

; Sweave customisation
(defun Rnw-mode ()
   (require 'ess-noweb)
   (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"))

but I am a bit puzzled that the LaTex color coding is lost in the 
foo.Rnw file. It does work if I rename the file foo.tex.

2. On directories

I like to keep my directories structred under /projects/ with 
subdirectories for ../R/, ../report/, ../figures/ and so forth.
So my foo.Rnw is in /projects/reports.

I set up an executable file to process foo.Rnw by calling Sweave from 
the R tools library, and run this shell from my /projects reports 
directory, as follows:

process foo.Rnw

where *process is

echo "library(tools); Sweave(\"$1\")" | R --no-save --no-restore

In my LaTex document, I set the eval option to FALSE if I don't want the 
Sweave chunks to run


However, I haven't been able to get the code to find the R script when 
called from a directory tree like this when eval=TRUE.

If I put foo.Rnw in /projects/R and Sweave("foo.Rnw") the process runs, 
producing a foo.tex file and foo.eps and foo.pdf files, but the foo.pdf 
gives and empty page error on loading into Acrobat 5.0.

OK, so I'm screwing something up here, but am not sure exactly what. The 
R script runs fine and generates a pdf graph okay on its own. Any help, 
gratefully received.

Best fishes


Sam McClatchie, Research scientist (fisheries acoustics))))))))))
NIWA (National Institute of Water & Atmospheric Research Ltd)
PO Box 14 901, Kilbirnie, Wellington, New Zealand
s.mcclatchie at niwa.cri.nz
Research home page <http://www.smcc.150m.com/>
                    /// \\\
                   //// \\\\
                  ///  <%)Xx><<
                 /////  \\\\\\
     ><(((%>     ..>><xX(?>O<?)Xx><<

More information about the R-help mailing list