我一直在使用makefile来自动执行Sweave中的分析报告,使用Jeromy Anglim概述的方法取得了巨大成功。我最近听说过cacheSweave软件包,我想将该功能合并到我的Rnw文件中。我使用ProjectTemplate包在启动时加载所有必需的文件,这需要一些时间,因为我必须预处理原始数据文件。在cacheSweave暗角的例子展示如何使用R对话中cacheSweave驱动程序运行Sweave:如何在批量使用cacheSweave通过make进行Sweave调用?
library(cacheSweave)
Sweave("foo.Rnw", driver = cacheSweaveDriver)
我将如何使用cacheSweaveDriver在我的命令在批处理模式下运行Sweave?在我的makefile我这是怎么调用Sweave:
$(TEXFILE).tex: $(TEXFILE).Rnw
R CMD SWeave $(TEXFILE).Rnw
R CMD Stangle $(TEXFILE).Rnw
我使用Emacs + ESS创建.Rnw文件并运行make。这里是我的makefile作参考休息:
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