How to use cacheSweave in a Sweave batch call through make?

I used the makefile to automate the work of Sweave for my analysis reports in R, using the approach indicated by Jeromy Anglim with excellent success. Recently I heard about the cacheSweave package, and I would like to include this functionality in my Rnw file. I use the ProjectTemplate package to load all the necessary files at startup, and this takes some time because I have to pre-process the raw data files. The examples in the cacheSweave widgets show how to start Sweave using the cacheSweave driver in an R session:

library(cacheSweave) Sweave("foo.Rnw", driver = cacheSweaveDriver) 

How to use cacheSweaveDriver in my command to run Sweave in batch mode? In my makefile, I call Sweave:

 $(TEXFILE).tex: $(TEXFILE).Rnw R CMD SWeave $(TEXFILE).Rnw R CMD Stangle $(TEXFILE).Rnw 

I am using Emacs + ESS to create a .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 
+7
source share
1 answer

Gregor Gordian has a shell script to allow this:

http://ggorjan.blogspot.com/2008/11/sweavesh-plays-with-cachesweave.html

This is more elegant than my home solution: to create 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

+3
source

All Articles