I am trying to create a series of documents (e.g. book chapters) where each chapter is created in an Rmarkdown (.Rmd) document. Each of these documents contains a yaml header where I would like it to take a chapter title (I have a custom pandoc template .html document, so chapter: in the yaml header provides the chapter name). Therefore the top of each document looks like:
---
title: "This is my book"
author: "A. Student"
chapter: "Chapter 1: Genesis"
output:
html_document:
template: my_template.html
---
I then have an R script which lifts all the .Rmd documents in my directory and runs them through the render() function.
for(i in list.files(pattern = "[.]Rmd%"){
rmarkdown::render(input=i, output_dir="outputs")
}
The only part of the yaml header that differs between the chapters is the value of the variable chapter, everything else remains the same. I would like to run this with an external yaml file to determine the variables title, author, output and template, while having a separate yaml header embedded within each .Rmd document giving the chapter name. I therefore created a yaml document, main.yaml, containing all of the above excluding the chapter variable, left only the chapter variable in the .Rmd document yaml header and ran render() with the output_yaml="main.yaml" argument included. However, it simply doesn't seem to pick up the contents of the main.yaml file - is it not possible to do this? I'm think that perhaps the .Rmd yaml header outranks that external?
I aim to do this so I can easily update the output type, template document, book title or author variables across all outputs by just changing the main.yaml document.
Note, it doesn't seem to pick up my main.yaml file even without the embedded yaml