Last active
September 9, 2023 06:02
-
-
Save charliejhadley/5abd8faef91e8ab829addf0a14d75804 to your computer and use it in GitHub Desktop.
nested parallelisation of .Rmd
This file contains 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(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") |
This file contains 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
--- | |
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) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! this was useful for me today