How-to 💡

Modified

October 6, 2023

Notebooks 📒

conditional cell execution based on format

if (knitr::is_html_output()) {
  print("code block run")
}
[1] "code block run"
if (!knitr::is_html_output()) {
  print("code block not run")
}

Run all 🏃🏼‍♀️

Run all R scripts and render notebooks in current folder

purrr::map(fs::dir_ls(".", glob = "*.R"), callr::rscript)
purrr::map(fs::dir_ls(".", glob = "*.Rmd"), rmarkdown::render)

Use script and save output

callr::rscript("z-run-all.R", stdout="z-run-all.log")  # R console
Rscript z-run-all.R > "z-run-all.log"                  # terminal