-
-
Save vfulco/1bd0a5c85a589e8084c2aee70a003587 to your computer and use it in GitHub Desktop.
parallel, parameterized knitr reports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(doParallel) | |
rpts <- list(list(out="one.html", params=list(some_var="One")), | |
list(out="two.html", params=list(some_var="Two")), | |
list(out="three.html", params=list(some_var="Three")), | |
list(out="four.html", params=list(some_var="Four"))) | |
do_rpt <- function(r) { | |
require(rmarkdown) | |
tf <- tempfile() | |
dir.create(tf) | |
rmarkdown::render(input="tstrpt.Rmd", | |
output_file=r$out, | |
intermediates_dir=tf, | |
params=r$params, | |
quiet=TRUE) | |
unlink(tf) | |
} | |
registerDoParallel(cores=3) | |
foreach(r=rpts, .combine=c) %dopar% do_rpt(r) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: Test Report | |
output: html_document | |
params: | |
some_var: "default" | |
some_date: !r as.Date("2015-01-01") | |
--- | |
Report for `r params$some_var` run on `r params$some_date` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment