mindlessgreen
mindlessgreen

Reputation: 12102

Use YAML variables within rmarkdown document

Say, I have an Rmd file that looks like this.

---
title: This is a title
subtitle: This is a subtitle
---

How can I access this variable title in the Rmd file like below?

```{r}
print(title)
```

or

`r print(title)`

Upvotes: 2

Views: 769

Answers (1)

joshpk
joshpk

Reputation: 769

You can access YAML metadata with rmarkdown::metadata.

---
title: "This is a title"
output:
  html_document
---

The title of this document is **`r rmarkdown::metadata$title`**

Upvotes: 2

Related Questions