Doing reproducible research with R Markdown

Since the concepts and methods of reproducible research have their own range of topics that could easily fill several books, we would like to focus on the abilities of R Markdown in conjunction with RStudio in this chapter. But first, we will give you a few introductory statements.

This simplification, and the fact that it is akin to the markup language, enables authors to perform a fast and intuitive formatting of text. Following are some examples:

Literate programming refers to the writing of computer programs in such as a way that they are mainly readable for human beings. Technically, it means that both the documentation and the source code of a respective program are available in a single file. The following characteristics of a literate programming system are required:

The process of creating human-readable documents is called weaving, while the creation of machine-readable documents is called tangling.

To use the principles of literate programming with R and RStudio, you can either use Sweave or the knitr package.

 

The knitr package was designed to be a transparent engine for dynamic report generation with R, solve some long-standing problems in Sweave, and combine features in other add-on packages into one package (knitr ≈ Sweave + cacheSweave + pgfSweave + weaver + animation::saveLatex + R2HTML::RweaveHTML + highlight::HighlightWeaveLatex + 0.2 * brew + 0.1 * SweaveListingUtils + more).

 
 --Yihui Xie, Creator of knitr (http://yihui.name/knitr/)

Since knitr is actively maintained and does not have the technical limitations of Sweave, we will only use this package in the following sections to create R Markdown files. Knitr uses R as the programming language, but it is also feasible to use other languages such as Python, SAS, Perl, Ruby, and others. Furthermore, it is possible to use different formats or languages such as HTML, LaTeX, AsciiDoc, and Markdown as the documentation language.

R Markdown is the integration of plain R code and Markdown, and is based on the knitr package and the open-source document converter, pandoc. It further combines dynamic documents, literate programming, and reproducible research. With the help of R Markdown, you can easily use R code and Markdown to create a report with human-readable documentations along with the results of your code. As an output option, you can choose between an HTML file, PDF, Microsoft Word, ioslides, and others.