Lately, I’ve been using Rmarkdown + Make to perform statistical analysis and generate reports.
I saw Shaun Jackman’s slideshow “Open, reproducible science using Make, RMarkdown and Pandoc” and thought it was lacking a key example: how do you use Make to generate reports from RMarkdown files? So I put together a little recipe for doing just that. It is a basic project directory structure and a tiny Makefile that automatically renders Rmarkdown files to HTML.
In the example repo, there is a
Makefile which defines a couple of rules for
.md files into
%.html: %.Rmd @Rscript -e "rmarkdown::render('$<')" %.pdf: %.Rmd @Rscript -e "rmarkdown::render('$<')"
After adding this to your
Makefile you can type
make my-analysis.pdf to
To automatically convert all
.md files to
.Rmd files in the
current working directory:
# define targets SOURCES=$(shell find notebooks -name *.Rmd) TARGETS=$(SOURCES:%.Rmd=%.pdf) default: $(TARGETS) # type `make clean` to delete all of the target PDFs clean: rm -rf $(TARGETS)