Thank you for thinking about this, @cderv! It sounds like this isn't doable exactly how I envisioned. Because running the report for several hundred cities/towns/schools is quite time-consuming (and usually not needed), I typically only want to generate region and/or county reports.
Here is how I'm dealing with it in the near-term:
- custom package that provides this alternative knit behavior:
knit_all_geographies <- function(input, ...) {
# geo_types is a list of all possible geographies for which to generate
# an individual report
geo_types <- c('region','county','city','town','school')
purrr::walk(
.x = geo_types,
.f = ~ rmarkdown::render(
input,
output_file = paste0(xfun::sans_ext(input), '_', .x, '.html'),
params = list(geo_type = .x),
envir = globalenv()
)
)
}
- Front matter in my RMD that includes this:
---
params:
# list of geo_types to render; some/all of: region, county, city, town, school
render_geo_types:
- region
- county
# leave this blank; the custom knit function will purrr::walk over this
geo_type: ''
knit: ptmknit::knit_all_geographies # call to custom knit
---
- A chunk in my RMD document that checks to see whether the current parameterized
params$geo_type is in params$render_geo_types. If not, write a short message and quit knitting that particular geography (though the output file is still generated).
# check to see if the paramterized 'geo_type' is in the 'render_geo_types'
# vector. if not, exit knitting.
if (!(params$geo_type %in% params$render_geo_types)) {
pander::pandoc.p('Report not generated for this geography.')
knitr::knit_exit()
}