What is the advised way to evaluate R expression in yaml headers retrieved with rmarkdown:::yaml_front_matter

!expr is a built in handler inside the r yaml package (yes the one from your link). So it will work and should be used most of the time, as long as eval.expr = TRUE in the function yaml_load(). See their documentation.

  • knitr can evaluated inline code chunk wirtten like `r expr` - This can be used in any place where evaluation will hapen by knitr for expression to be replaced by their value.
  • !expr is the way to evaluate R code when loading a YAML file. that is yaml package feature.
  • !r is something I have forgotten about and rediscovered with your question TBH. So the form above should be the more generic to use. !r will only work in the params field as this is a possible trhough a custom handler defined in knitr when loading params. Quite specific
1 Like