3 frameworks into one — Write your next paper with R Studio!

Here, I will show you my current workflow to writing research papers in my studies. This is an approach to come up with a coherent and simple setup, which weaves together the literature and data related aspects of a project.

3 frameworks into one — Write your next paper with R Studio!
Photo by Dan Dimmock / Unsplash

Start using R Markdown

R Markdown brings together code, its output and text, creating one coherent document. The package bookdown extends this feature, as it compiles multiple R Markdown files into one coherent book or paper.

Why is it beneficial to use R Markdown?  Let’s consider an example for the workflow with a standard setup (Word + Statistical Software) and compare it to the one with the R Markdown setup: In your final proofread, you discover that you have a typo in the x-axis label of your most important plot. If you are writing your paper in the standard framework, you face some painful steps:

  1. Re-run your analysis script
  2. Adjust your plot’s code
  3. Export the new plot as an image file
  4. Copy and paste the image into Word
  5. Fidget with your word editor until you get the formatting right
  6. (😡 the new image messed up your whole document)
  7. Notice that the plot uses the wrong colours
  8. Step 1

Here, R Markdown can help: It allows you to weave together your analysis code and the text of your paper into one file. Do you need to rename your x-axis label? No problem. Just adjust the label directly in the code of your plot and compile your document – done.

Even better: If you write your own plotting functions, you could also adjust the colour schemes of all of your plots by changing one function. Not only is this more efficient, but it is also coherent and less error-prone than adjusting each plot manually. R Studio 1.4 even adds a “Visual Editor”, which makes editing more beginner-friendly.

To tailor R Markdown towards academic papers, I am using bookdown and a custom project template, which I derived from Lucy D'Agostino McGowan’s fantastic blog post: “One year to dissertate”. The template’s formatting is based on a Latex, and hence you can simply import the parameters from your current Latex preamble to the bookdownproject.

In my project template, I also incorporated the option to generate beamer slides. Having your slides in the same project is helpful, as you can refer to the same "assets" as your main paper: There won't be any differences in the citations, plots, or tables, because you are importing the same objects. In the R Markdown document for you slides, you can even directly adjust the scaling of a plot's font or title to improve its presentability.

McGowan’s template can be found here, and my derivation of it can be found here.

Collect your Literature in Zotero

I collect my literature in Zotero. It is an open-source software, which allows you to build up your database of research papers. You can easily import new ones by passing Zotero the studies' DOI. While there are many other software packages which allow you to manage your literature, Zotero has a direct integration with R Studio: You will be able to cite any paper in R, which is filed away in your Zotero database. The Visual Editor even offers a GUI where you can search through your papers.

Screenshot of the citation manager in R

Take great Notes with Notion

For note-taking, I use Notion. Its advantage over other note-taking software is, that it allows you to quickly link ideas and make connections between the content you collect. In our context, that could mean to link two papers with each other, that discuss the same topic, cite each other, or offer contrasting explanations.

Notion integrates well with Zotero. The handy community plug-in Notero creates a designated page for each element of your Zotero library in Notion. This makes it easy to take extensive notes on your literature. Make sure to visit their GitHub, as they also provide a great Notion template for this!

There are endless possibilities of clever note-taking with Notion: Connecting different research papers, summarising their findings, comparing papers in tables, or creating a Kanban board to keep track of your reading progress. This structure facilitates creativity and mitigates the risk of losing your notes.

Kanban board of academic papers synced by Notero

The Big-Picture

Below, I tried to visualise the big-picture idea behind this setup. Notice, how the existing literature and your data are the only two external inputs? Your intellectual work (mainly) takes place in Notion, while you conduct your data analysis and writing in R Studio. The engine behind all of this is R Markdown, as it ties together all steps into one paper.pdf or slides.pdf.

Some other things I learned:

  • Search for literature in bulk, then download the papers and pass their DOIs to Zotero. It helps, if you come up with a file naming convention.
  • If you run into trouble with "Citeproc" errors (i.e. Latex does not find a citation in your references), then activate the Visual Editor and implement the respective citations again via their menu. This causes R Studio to sync with Zotero and updates the collection of references.
  • Do not use special characters when assigning a label to tables or figures. For example "_" appears to cause trouble and prints Latex commands to your paper rather than executing them.
  • Make use of websites like https://elicit.org/search and https://www.researchrabbit.ai, which employ AI to help you find the literature you are looking for.
  • Take notes in Notion and use the provided property fields in the “advanced template”, so you can display information at a glance in tables. Link papers to each other, if you see a connection between them.
  • If your computer has a “dictation” feature, then dictate your first draft of text with it. Editing is easier than writing from scratch, hence “speak something” onto the page first. There's no such thing as "speaker's block".

Do you want to write papers and create slides with R & Python?
Get the ready-to-go template for your next project! Sign-up below!
(When signed in, a link to the template will show up)

This post is for subscribers only

Already have an account? Sign in.

Subscribe to ds-econ

Sign up now to get access to the library of members-only issues.
Jamie Larson