Skip to content

Instantly share code, notes, and snippets.

@potterzot
Last active October 10, 2017 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potterzot/0ead18ad52ec77f6b47843349a933d25 to your computer and use it in GitHub Desktop.
Save potterzot/0ead18ad52ec77f6b47843349a933d25 to your computer and use it in GitHub Desktop.
Using Make to compile multiple Rmd files in a directory
# This lets you type `make`
# and will pandoc all *.Rmd files in the letters directory
# into pdfs stored in the output directory
all: readme letters
#generate all letters
SRC=$(wildcard letters/*.Rmd)
OUT=$(patsubst letters/%.Rmd, output/%.pdf, $(SRC))
letters: $(OUT)
#CLEAN
#remove any output (non-data) files
clean:
rm -f README.md
cleanall:
rm -f README.md
rm -f output/*
#OUTPUT
#Project README
readme: README.Rmd
R -e "rmarkdown::render('$(<F)')"
#Generate a specific letter
output/%.pdf: letters/%.Rmd
cd $(<D); R -e "rmarkdown::render('$(<F)', output_format = 'all', output_dir = '../output/')"
#output/$(OUT): $(SRC)
# cd $(<D); R -e "rmarkdown::render('$(<F)', output_format = 'all', output_dir = '../output/')"
#output/%: $(SRC)
# cd letters; R -e "lapply($@, rmarkdown::render, output_format = 'all')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment