R Markdown documents allow you to pass almost any object -- including large data frames and functions -- to the document as parameters, letting you only define them once to use them in both your document generator and the generated document. This function makes it slightly easier to do so, by adding your objects to the YAML header and then initializing them so you can use the same object names in your generated document as in your generator.

use_parameters(template, ..., init.params = TRUE, is.file = FALSE)

Arguments

template

An atomic (length(template) == 1) character vector containing either the template to manipulate OR the path to the file storing the template, which will be imported via import_pattern.

...

Objects to be included as parameters. Objects should be unquoted and exist in the current session environment. This function currently will always assign parameters NA as a default value, and does not yet provide an option to override that.

init.params

A boolean (TRUE/FALSE) value indicating if a chunk initalizing the parameters (that is, assigning them via object <- params$object) should be included. Default TRUE.

is.file

A boolean value indicating if the template argument is a vector containing the template (FALSE, default) or the path to the template file (TRUE).

See also

Other manipulation functions: create_yaml_header(), heddle(), make_template(), provide_parameters()

Examples

template <- make_template("---\ntitle: Cool Report\noutput: html_document\n---\n")
use_parameters(template, data)
#> [1] "---\ntitle: Cool Report\noutput: html_document\nparams:\n  data: NA\n---\n```{r}\n\ndata <- params$data\n```\n\n"