I have to run markdown reports for 2 subjects (math and reading) on a regular basis. I currently have to set the subject variable in the title of the markdown, in the output filename (.html file), and again within the R code chunks for data processing. I would like to set this variable one time and have the title, output file, and analyses all adjust. Is there a way to do this?
I know the title can be made dynamic through the params
YAML header but that doesn't help with the output filename or within the R code chunks.
See a portion of my current code below. Notice the reading variable is specified 3 times (title, output file name, and within the R code chunk under "Presets". I would like to specify "reading" one time (preferably at the top of the script).
---
title: Reading Investigation"
author: "xxx"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
code_folding: hide
depth: 3
fig_height: 10
fig_width: 12
highlight: tango
number_sections: no
theme: cerulean
toc: yes
toc_float: yes
knit: (function(inputFile, encoding)
{ rmarkdown::render(inputFile, encoding = encoding,
output_file = paste0('folder/reading_output_', Sys.Date(), '.html') )})
---
```{r, message=FALSE, echo=FALSE, warning=FALSE, results='hide', comment="", fig.height=10, fig.width=12}
# Libraries ------------------------------------------------------------------
library(RODBC)
library(tidyverse)
library(ggplot2)
library(kableExtra)
# Set up ------------------------------------------------------------------
options(scipen=999)
#### Presets
subject = "reading" # "math", "reading"
```