Set R Markdown HTML output name dynamically

Hello,

Is it possible to save the R Markdown HTML output file by a variable I set in the code?

Help/guidance much appreciated.

This might not be what you're looking for, but something I've done in the past with parameterized templates in Quarto projects is to use purrr::walk() to pass the parameters in and name the output file with those values. I think this could be achieved in a similar way using rmarkdown::render() (non-working example below). If you wanted this to be included in the actual .rmd file, I'm not sure if you can achieve something similar by putting the render command in its own chunk and setting the chunk option eval = FALSE, but maybe that would work. Keeping a small external R script was cleaner for me to maintain, however.

notebook_params <- c("A", "B", "C")

purrr::walk(
  notebook_params,
  function(param) {
    rmarkdown::render(
      input = "<path_to_template_file.rmd>",
      output_file = glue::glue("{param}.html"),
      params = param
    )
  }
)