Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
knitr makefile
################################################################################
# Copyright 2011
# Andrew Redd
# 11/23/2011
#
# Description of File:
# Makefile for knitr compiling
#
################################################################################
all:pdf # default rule DO NOT EDIT
################################################################################
MAINFILE := test
RNWFILES :=
RFILES :=
TEXFILES :=
CACHEDIR := cache
FIGUREDIR := figures
LATEXMK_FLAGS :=
##### Explicit Dependencies #####
################################################################################
RNWTEX = $(RNWFILES:.Rnw=.tex)
ROUTFILES = $(RFILES:.R=.Rout)
RDATAFILES= $(RFILES:.R=.Rdata)
MAINTEX = $(MAINFILE:=.tex)
MAINPDF = $(MAINFILE:=.pdf)
ALLTEX = $(MAINTEX) $(RNWTEX) $(TEXFILES)
# Dependencies
$(RNWTEX): $(RDATAFILES)
$(MAINTEX): $(RNWTEX) $(TEXFILES)
$(MAINPDF): $(MAINTEX) $(ALLTEX)
.PHONY:pdf tex clean clearcache cleanall
pdf: $(MAINPDF)
tex: $(RDATAFILES) $(ALLTEX)
$(CACHEDIR):
mkdir $(CACHEDIR)
$(FIGUREDIR):
mkdir $(FIGUREDIR)
%.tex:%.Rnw
Rscript \
-e "library(knitr)" \
-e "knitr::opts_chunk[['set']](fig.path='$(FIGUREDIR)/$*-')" \
-e "knitr::opts_chunk[['set']](cache.path='$(CACHEDIR)/$*-')" \
-e "knitr::knit('$<','$@')"
%.R:%.Rnw
Rscript -e "Sweave('$^', driver=Rtangle())"
%.Rout:%.R
R CMD BATCH "$^" "$@"
%.pdf: %.tex
latexmk -pdf $<
clean:
-latexmk -c -quiet $(MAINFILE).tex
-rm -f $(MAINTEX) $(RNWTEX)
-rm -rf $(FIGUREDIR)
-rm *tikzDictionary
-rm $(MAINPDF)
clearcache:
-rm -rf cache
cleanall: clean clearcache
@yihui
yihui commented Jan 20, 2012

prefix.string and prefix.cache have been renamed to fig.path and cache.path respectively, so you might want to tweak line 28 and 29

@halpo
Owner
halpo commented Jan 20, 2012

I replaced it in my personal copy but forgot here. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment