In my R Markdown document, I have successfully overridden the Knit button behavior using the examples posted at https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html. I understand that the custom knit function itself doesn't take any arguments other than 'input', but I'm wondering if there is a way to access a params value set earlier in the yaml of the R Markdown document?
Here's a simplified example--ideally, I would purrr::walk() across a character vector of regions set in the params and render each region to a different output file.
---
params:
regions: !r c('county','city')
output: html_document
knit: (function(input, ...) {
purrr::walk(
.x = params$regions,
.f = ~ rmarkdown::render(
input,
output_file = paste0(xfun::sans_ext(input), '_', .x, '.html'),
envir = globalenv()
)
)
})
---
When I try to knit this example, I get this error:
Error in map(.x, .f, ...) : object 'params' not found
Calls: <Anonymous> -> <Anonymous> -> map
Execution halted
Thank you for any help you can provide!