Skip to content

Instantly share code, notes, and snippets.

@sglyon
Forked from halpo/knitr.mk
Created March 15, 2014 23:59
Show Gist options
  • Save sglyon/9575843 to your computer and use it in GitHub Desktop.
Save sglyon/9575843 to your computer and use it in GitHub Desktop.
################################################################################
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment