Chapter 6 Reproducible workflows

Reproducible workflows are increasingly important in both business and academia. It’s important to show others (but also your future self!) how you have come to particular results. This means being clear about whether you made changes to data (perhaps you cleaned the data), whether you created new variables to work with, what types of analysis you have forced on your data, and what exactly is visualized in a graph. When you work in R, it’s further important to show what packages you used (and even which versions!).

In R, there are two good ways to save your code: scripts and Rmarkdown-files.

6.1 Scripts

You can save your code as basic text in a script, which has an .R extension. You are currently probably looking at a script editor (image from https://r4ds.had.co.nz/workflow-scripts.html):

6.2 Rmarkdown

You can also save your code in an Rmarkdown-file. The beauty of Rmarkdown is that you can combine text, with code, with output of code, and that you can transform this file into, for instance, a pdf, a word-file, or a website.

Let’s see a brief video:

See also: https://socviz.co/gettingstarted.html#work-in-plain-text-using-rmarkdown

6.3 Code style

It’s nice if your code is clean and consistent. There is no one true way, but some have written sensible things about this: https://style.tidyverse.org/index.html.

Note: how ‘clean’ your code is, is also a part of your grade for each assignment.