Writing a thesis in R Markdown

Published

March 14, 2020

Abstract

A short discussion about my experiences using R Markdown to write my PhD thesis.

At the start of my PhD I had never even heard of R/R Markdown let alone considered using it to write my thesis. However, thanks in part to the numerous amount of resources out there showing what is possible within R for writing lengthy technical documents, I made the decision to give it a go - and haven’t looked back since.

The purpose of this post is to pay homage to the resources I used throughout writing my PhD and highlight some of the issues I came across while doing so, in the hope that a future reader may find something useful…

My only advice to someone who was considering using R Markdown to write a thesis would be just go for it - there are ample resources out there to help, and the process is incredibly rewarding.

For those interested, the repository of my completed thesis can be found here: https://github.com/hfshr/phd-thesis

Benefits

Combine text and code

The ability to integrate text and R code in the same document to produce tables and figures is extremely useful. No more copy/pasting from Excel to Word for tables and figures!

Separate files for each chapter

Large word documents can quickly become unwieldy, and increasingly frustrating to work with as the document grows in length. R Markdown lets you easily combine multiple chapters/files into one document when you press knit.

Learn a new skill

I found writing in Markdown really satisfying. Writing a thesis can certainly be a little dull at times, but there were always new things to learn while using Markdown, and this certainly helped keep me motivated when writing wasn’t going so well…

Potential downsides

Comments

This was the only major issue I faced using Markdown. While my supervisors were happy enough for me to use R Markdown, they were not too keen on learning how to use git and start opening pull requests on my draft chapters… So for feedback, I ended up knitting to .docx so comments could be tracked using Microsoft word. The downside to this was that formatting often went astray, but over time they were ok with this after seeing the aesthetically pleasing PDF outputs that were possible.

Inevitably you will need to learn some LaTeX

R markdown does a fantastic job and can get you 95% of the way there without ever having to open a .tex file. However there will likely be some fine tuning that is either not easy or not possible to do with R Markdown, and using If unfamiliar with LaTeX, this can be a steep learning curve, but there are ample resources out there to help figure things out.

Potential to get distracted from writing

Occasionally I would spend time fiddling with the layout of certain pages, or trying to get a specific table looking a certain way, when I really should have just saved that till after the writing was finished. My tip would be dedicate time to writing and time to editing and try not to mix the two. That way you can dedicate your full focus to each task, and not get distracted by one when you need to be working on the other.

Credits

Below are some of the key resources I used during my write up.

  • R Markdown: Providing the tools Xie, Allaire, and Grolemund (2018)
  • Bookdown: Excellent package by yihui for writing all kinds of documents Xie (2016) https://github.com/rstudio/bookdown
  • Thesisdown: Extension to bookdown focusing specifically on thesis style documents https://github.com/ismayc/thesisdown Solomon (2020)
  • Really useful blog by Ed Berry I found early on in R markdown journey (Thanks Ed) https://eddjberry.netlify.com/post/writing-your-thesis-with-bookdown/
  • Another useful blog for some additional formatting tips https://rpubs.com/theycke/380678
  • Papaja: Fantastic package for formatting in APA style https://github.com/crsh/papaja Aust and Barth (2018)

References

Aust, Frederik, and Marius Barth. 2018. Papaja: Create APA Manuscripts with r Markdown. https://github.com/crsh/papaja.
Solomon, Nick. 2020. Thesisdown: An Updated r Markdown Thesis Template Using the Bookdown Package.
Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.