This document describes how to create ‘child’ R Markdown documents that are incorporated into a parent document during the rendering process.
For example, Rick uses this to generate a full syllabus from the various parts of the course website (Rmd | docx | PDF).
You could use this to create separate R Markdown documents for different plots, or sections of a bigger piece of work.
setup
chunk, or you will get an error. There can’t be more than one chunk with the same name in your (combined) document.pagetitle:
parameter is all that is needed:---
pagetitle: "my-child"
---
```{r child = 'my-child.Rmd'}
```
That’s it. When you render the parent document, the contents of the child will be included.
To prove it, here are the contents of the my-child.Rmd
document:
I am from the child document even though my unformatted text doesn’t really show it.
I love both of my children equally.
As much as I love R Markdown, I love my children more.
The nice auto-numbering table of contents feature in the html_document
and related output formats isn’t so smart. You’ll need to think about the header levels in your parent and child documents, and make sure that they work.
Your ‘child’ documents may or may not have information about variables you define in the parent document or other child documents.