I've been using a makefile to automate the running of Sweave for my analysis reports in R using the approach outlined by Jeromy Anglim with great success. I recently heard about the cacheSweave package and I would like to incorporate that functionality into my Rnw file. I use the ProjectTemplate package to load all of the necessary files at startup, and that takes some time because I have to preprocess the raw data files. The examples in the cacheSweave vignette show how to run Sweave with the cacheSweave driver within an R session:
library(cacheSweave)
Sweave("foo.Rnw", driver = cacheSweaveDriver)
How would I use the cacheSweaveDriver in my command to run Sweave in batch mode? In my makefile this is how I invoke Sweave:
$(TEXFILE).tex: $(TEXFILE).Rnw
R CMD SWeave $(TEXFILE).Rnw
R CMD Stangle $(TEXFILE).Rnw
I am using Emacs+ESS to create the .Rnw file and run make. Here is the rest of my makefile for reference:
TEXFILE=report_presentation
PLOTDIR= ../graphs
PLOTS=
FIGURES= $(PLOTDIR)/$(PLOTS)
INPUTS=
all: $(TEXFILE).pdf; make clean
.PHONY: all clean
$(TEXFILE).pdf: $(TEXFILE).tex $(FIGURES) $(INPUTS)
# Initial run
pdflatex $(TEXFILE)
# Run bibtex if missing citations
@if(grep "Citation" $(TEXFILE).log > /dev/null);\
then \
bibtex $(TEXFILE);\
pdflatex $(TEXFILE); \
fi
# Recompile if instructed
@if(grep "Rerun" $(TEXFILE).log > /dev/null);\
then \
pdflatex $(TEXFILE); \
fi
$(TEXFILE).tex: $(TEXFILE).Rnw
R CMD Sweave $(TEXFILE).Rnw
R CMD Stangle $(TEXFILE).Rnw
## Remove unnecessary files
clean:
-rm -f $(TEXFILE).log $(TEXFILE).aux $(TEXFILE).out $(TEXFILE).blg $(TEXFILE).bbl $(TEXFILE).nav $(TEXFILE).snm $(TEXFILE).toc Rplots.pdf
Gregor Gorjanc has a shell script to allow this:
http://ggorjan.blogspot.com/2008/11/sweavesh-plays-with-cachesweave.html
It is more elegant than my homemade solution: which is to make a simple file called "runcachesweave.R" containing:
library(cacheSweave)
Sweave("foo.Rnw", driver = cacheSweaveDriver)
And then calling R CMD BATCH runcachesweave.R;latexmk -pdf foo.tex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With