Writing a multi-chapter document with R Markdown
- 2 minsI have previously wrote about manuscript preparation with R Markdown here, and here. These were previously single papers which were relatively simple to construct.
However, I am now in the midst of writing my PhD Upgrade Report (to upgrade from MPhil to Phd), and need to produce a larger document that encompasses multiple chapters and will be approximately 10,000 words long. Therefore I thought I’d best adjust the workflow slightly to allow for working on separate chapters and then getting them joined together, and arrange references all at the end. I shall also adopt this workflow for my final PhD thesis, when and if I get to writing it!
So this is how I’m doing it:
- Create an R Markdown document for each separate chapter (child documents), we can name them
01-intro.Rmd
,02-methods.Rmd
,03-results.Rmd
for this example. - Create a separate R Markdown document (parent document) which will then be used to stitch them together into one output document.
The child documents can contain the usual R Markdown report components, and reference tags [@author_title_year]
and can each be knitted into their own separate documents on their own if necessary (for sharing and review, etc.).
The parent document is then simply:
Once you knit this parent document, each child will then be joined together seamlessly. I am outputting this as a .docx
file and this will allow me to send the draft to my PhD Supervisor for review (and use track changes to provide comments, which is the workflow she is accustomed to). I can point pandoc to a style.docx
file which contains a template of all the necessary styling in order to ensure my output document looks ok.
As usual, thanks to StackOverflow for helping with this code. Particular thanks to user eric!