Press "Enter" to skip to content

Reproducible reports for decision making

The problem and the opportunity

Flows of data in organizations today are constant and unstoppable. A report based on a data slice from a specific timestamp is already outdated after half an hour. The infrastructure of R allows us to create documents where tables, plots and other calculation-based insertions are automatically updated every time you regenerate these documents.

This technology is called RMarkdown.

What do you get exactly by employing RMarkdown?

For example, an analyst can prepare a report by mixing a body of text with chunks of R (or other statistical packages) source code. Then when the final document is produced, the code chunks are replaced by the evaluation results: plotting instructions are displaced by graphics, tabulating commands by tables etc.

For dissemination and publication, an RMarkdown file can be converted into a broad range of formats: Word, PDF, HTML web pages etc. That is right: the analyst works with a single document, which can generate output in several formats.

What do you need to generate reproducible reports in RMarkdown

Skills

The Markdown format is very simple. It comprises a bunch of conventions to mark paragraphs, headings of different levels, numbered and unordered lists, links, etc. It is much simpler than LaTeX. Comparing Markdown with preparing documents in MS Word is difficult because they have completely different approaches. You will not likely spend more than 10 minutes learning Markdown.

Learning R is another story!

Software

All software for producing and working with RMarkdown documents is free. You need R and RStudio IDE. RStudio will provide you with all required R-packages and dependencies. If you want to generate documents in PDF format, you must install one of the LaTeX engines. It is more complex but is also free software.

How does RMarkdown work

So RMarkdown consists of two components: documents in Markdown format and chunks of R commands. A specific R-package knitr does the job. It looks through the document and finds R commands. Knitr executes all these commands and creates a new document, where R commands are substituted by their results. At this step, we have a clean Markdown document. Then knitr runs the program Pandoc, which converts the Markdown documents into a file of the desired format.

The original version of the post was written for Rstat.Consulting.

Leave a Reply

Your email address will not be published. Required fields are marked *

Защита от спама *