He estado usando un archivo MAKE para automatizar el funcionamiento de Sweave para mis informes de análisis en R usando el enfoque descrito por Jeromy Anglim con gran éxito. Hace poco escuché sobre el paquete cacheSweave y me gustaría incorporar esa funcionalidad a mi archivo Rnw. Utilizo el paquete ProjectTemplate para cargar todos los archivos necesarios al inicio, y eso lleva algo de tiempo porque tengo que preprocesar los archivos de datos en bruto. Los ejemplos en el show viñeta cacheSweave cómo ejecutar Sweave con el conductor dentro de una sesión cacheSweave R:Cómo usar el cacheSweave en un lote ¿Quieres llamar a Sweave a través de make?
library(cacheSweave)
Sweave("foo.Rnw", driver = cacheSweaveDriver)
¿Cómo iba a utilizar el cacheSweaveDriver en mi comando para ejecutar Sweave en modo batch? En mi makefile así es como invoco Sweave:
$(TEXFILE).tex: $(TEXFILE).Rnw
R CMD SWeave $(TEXFILE).Rnw
R CMD Stangle $(TEXFILE).Rnw
estoy usando Emacs + ESS para crear el archivo .Rnw y ejecutar make. Aquí está el resto de mi makefile para referencia:
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