Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access yaml metadata from knitr

Does knitr know the value of YAML data e.g. title: or date: or some_custom_field: while it is compiling an rmarkdown doc with a YAML header?

I would like to be able to do this (pseudocode)

---
title: my title
---

The title of this document is `r knitrs_yaml_array("title")`
like image 695
Steve Powell Avatar asked Jul 04 '15 13:07

Steve Powell


People also ask

Where is the YAML header?

YAML header is a short blob of text, specially formatted with key: value pairs tags, that seats at the top of our Rmarkdown document. The header not only dictates the final file format, but a style and feel for our final document.

How does R knitr work?

When you run render , R Markdown feeds the . Rmd file to knitr, which executes all of the code chunks and creates a new markdown (. md) document which includes the code and its output. The markdown file generated by knitr is then processed by pandoc which is responsible for creating the finished format.

What does knitr :: Opts_chunk set echo true mean?

The first code chunk: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` is used to specify any global settings to be applied to the R Markdown script. The example sets all code chunks as “echo=TRUE”, meaning they will be included in the final rendered version.


1 Answers

That is stored in rmarkdown::metadata as a list of the form list(title = ...).

like image 84
Yihui Xie Avatar answered Nov 01 '22 17:11

Yihui Xie