Reputation: 4406
Is there any way to pass parameters in an rmarkdown document outside of a code chunk? For example, I'd love to have the ability to have a parameter value be a heading.
Here is a short example .Rmd
file:
---
title: "param_test"
author: "test"
date: "September 14, 2017"
output: pdf_document
params:
param_test: this_text
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## I want this heading to be the value of params$param_test
```{r cars}
params$param_test
print(params$param_test)
```
Does anyone have any ideas on this?
Upvotes: 4
Views: 2451
Reputation: 96
You just need to add results='asis'
to the chunk then you can print out the header from within the code.
cat("#", params$param_test, "\n")
Another option would be to use the pander library and run
pandoc.header(params$param_test)
Upvotes: 8