Reproducible research: An introduction to knitr
A workshop presented by Sahir Bhatnagar (McGill University)
Date: Thursday, May 28, 2015, 13:00-‐16:00
Location: Purvis Hall, Room 25, McGill University
Slides: The slides used for this presentation can be found here
Sponsored by the CRM Statistics Laboratory and the Montreal Biostatistics Seminar Series
Description: With the ever increasing size of data and complexity of methods required to analyze them, the reproducibility of results is necessary to ensure a high quality of scientific research. In this workshop, we will discuss the main concepts and motivations for reproducible research (RR). Mr. Bhatnagar will then introduce useful tools for RR, including RStudio, knitr, and Markdown. We will work through several examples to see how these tools can be used to perform efficiently common tasks such as writing reports, Beamer presentations, running simulations, repetitive function calls that require single or multiple inputs to be changed, and sharing results. Basic knowledge of R
and LaTeX
is assumed.
Participants must bring their own laptops, with the following programs and packages installed:
- R
- RStudio v0.99.441 Preview
R
packagesknitr
,magrittr
,data.table
,ggplot2
,devtools
- A working instance of
LaTeX
- TeXStudio (optional)
All the examples in this repository are reproducible. To compile please follow these instructions:
- For a given directory, open the associated
.Rproj
file in RStudio - Open the
.Rnw
corresponding to the name of the folder - In RStudio, make sure files are weaved using
knitr
(Tools -> Global Options -> Sweave -> Weave .Rnw files using: select knitr in the dropdown menu) - In RStudio, click on
Compile PDF
or in theR
console enterknitr::knit2pdf("*.Rnw")
where * is the name of the.Rnw
to compile
- In each of the folders there is a
packages.R
file, which automatically tests for required packages, and install them if they are missing from your library - There is no need to set any working directories, since you have opened the
.Rproj
file - To be able to compile the slides, you need to have a Perl interpreter installed. If you do not have one, simply comment out
knit_hooks$set(crop = hook_pdfcrop)
in the setup chunk of themcgill-knitr.Rnw
file