Evaluating R code in YAML header

Viewed 3192

Consider the following Rmd file,

---
title: "Untitled"
author: "baptiste"
date: "`r Sys.Date()`"
output: html_document
test: "`r paste('_metadata.yaml')`"
---

```{r}
cat(rmarkdown::metadata$test)
```

enter image description here

The date is processed (knitted) by R before being passed to pandoc for conversion to md and html. The custom field test, however, is unevaluated.

What's the difference? Can one force knitr/rmarkdown to evaluate an arbitrary field in the yaml header?

Note: the actual purpose is not to just print() a filename as in this dummy example, but to load an external yaml file containing metadata (author information), process it with R, and output a string that will be injected in the document.

2 Answers
Related