4.3 Access the document metadata in R code

When an Rmd document is compiled, all of its metadata in the YAML section will be stored in the list object rmarkdown::metadata. For example, rmarkdown::metadata$title gives you the title of the document. You can use this metadata object in your R code, so that you do not need to hard-code information that has been provided in the YAML metadata. For example, when you send an email with the blastula package (Iannone and Cheng 2020) within an Rmd document, you may use the title of the document as the email subject, and get the sender information from the author field:

title: An important report
author: John Doe
email: john@example.com

We have done an important analysis, and want to email
the results.

  from = setNames(metadata$email, metadata$author),
  subject = metadata$title


Iannone, Richard, and Joe Cheng. 2020. Blastula: Easily Send HTML Email Messages. https://github.com/rich-iannone/blastula.