Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all R Markdown templates in a package?

Tags:

r

r-markdown

General Problem

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?

Example Package: reprex

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?

What I've Looked Through

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.

like image 636
merv Avatar asked Oct 26 '25 08:10

merv


1 Answers

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.

like image 129
merv Avatar answered Oct 27 '25 23:10

merv