2 min read

Knitting Club: R Markdown for beginners

Matt Dray (@mattdray)

Knitting simulator by Kara Stone and Gabby DaRienzo (via Giphy)

Knitting simulator by Kara Stone and Gabby DaRienzo (via Giphy)

RAP and the rise of reproducibility

The UK government has got better at producing statistical reports in a reproducible way. A turning point was the creation of Reproducible Analytical Pipelines (RAP) – a method for making releases easier to recreate, test and audit. Matthews Upson and Gregory of Government Digital Service (GDS) have described and enshrined this process and enabled others to continue its spread.

One useful and accessible tool for reproducibility is R Markdown, which allows you to execute R code inside your document and ‘knit’ it into a readable report. You can re-run the code, or alter the parameters and re-knit it without stress. This is much faster and less error-prone versus a workflow that moves data between a database, spreadsheet and word processor.

The R Markdown bible has been released recently by Yihui Xie, JJ Allaire and Garrett Grolemund and is the go-to resource for creating reports, presentations, dashboards, websites, books and blogs in R Markdown.

For something simpler and way more incomplete, I thought I’d expose two resources I created earlier this year to help beginners in my organisationto learn about R Markdown.

These materials a little rough, but I included links to GitHub below so you can fix them.

Knitting Club

Access the Knitting Club document and find the code on GitHub.

I presented this document in a cross-department Coffee & Coding session in April 2018. The blurb was:

Do you have woolly knowledge of document creation in R? Needle little help? Matt Dray will drop some purls of wisdom and unravel a yarn about the knitty-gritty of R Markdown and the ‘knitr’ package for one-click document creation. Don’t get the point? If a deadline is looming, you’ll avoid a stitch-up from endless re-running of code and copy-pasting of outputs into a Word document. Come along and have a ball!

Ha. Ha. Ha.

Quick R Markdown

If the Knitting Club document is too long, you can check out this shorter slide-based introduction to R Markdown below. You can also access the slides alone and find the code on GitHub.