Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Last active September 9, 2023 06:02
Show Gist options
  • Save charliejhadley/5abd8faef91e8ab829addf0a14d75804 to your computer and use it in GitHub Desktop.
Save charliejhadley/5abd8faef91e8ab829addf0a14d75804 to your computer and use it in GitHub Desktop.
nested parallelisation of .Rmd
library(tidyverse)
library(rmarkdown)
library(tictoc)
library(furrr)
wait_time <- 10
# intermediates_dir needed to guard against processes targeting the same files
# https://github.com/rstudio/rmarkdown/issues/1632#issuecomment-804649226
tic()
walk(1:4,
{
future_walk(1:10, ~render("report_template.Rmd",
output_file = str_glue("{.x}.html"),
params = list(rmd_wait = wait_time, report_name = .x),
intermediates_dir = tempdir(),
quiet = TRUE))
})
toc("parallelised")
---
params:
rmd_wait: 10
report_name: "foo"
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This is report `r params$report_name`
## R Markdown
```{r}
Sys.sleep(params$rmd_wait)
```
```{r}
print(params$rmd_wait)
```
@CGMossa
Copy link

CGMossa commented Sep 9, 2023

Thanks! this was useful for me today

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