Given a package that provides R Markdown templates, how does one get a list of all valid templates that could be given to the rmarkdown::draft function? That is, for
rmarkdown::draft("my_rmd.Rmd", template_name, some_pkg)
where we know some_pkg, how can one programmatically obtain the valid values for template_name?
As a concrete example of a template provider, let's use the reprex package. From the RStudio GUI, I know reprex provides two templates. How can one get the list of template_names for the reprex package?
Skimming through the rmarkdown:: methods, I don't see any such functionality. Searching around, I've only found examples for how to write and use templates, but all eventually resort to showing how to load the template via the RStudio GUI dialog. The documentation of the rmarkdown::draft only describes where the templates are stored, but doesn't provide a programmatic example for listing them.
available_templates()Starting with rmarkdown v2.12, there is now an exported function for this. For example,
rmarkdown::available_templates("reprex")
See v2.12 Release Notes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With