15.1 Declaring parameters

Parameters are specified using the params field within the YAML section. We can specify one or more parameters with each item on a new line. As an example:

---
title: My Document
output: html_document
params:
  year: 2018
  region: Europe
  printcode: TRUE
  data: file.csv
---

All standard R types that can be parsed by yaml::yaml.load() can be included as parameters, including character, numeric, integer, and logical types. We can also use R objects by including !r before R expressions. For example, we could include the current date with the following R code:

---
title: My Document
output: html_document
params:
  date: !r Sys.Date()
---

Any R expressions included within the parameters are executed before any code in the document, therefore any package dependencies must be explicitly stated using the package::function notation (e.g., !r lubridate::today()), even if the package is loaded later in the Rmd document.