14
Principles and Practice of Reproducible Research with R Author: Andrea Foulkes, Gregory Matthews, Nicholas Reich Biostatistics in Practice: Research Training in High-Performance Computing with R This material is part of the statsTeachR project Made available under the Creative Commons Attribution-ShareAlike 3.0 Unported License: http://creativecommons.org/licenses/by-sa/3.0/deed.en US

Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Principles and Practice ofReproducible Research with R

Author: Andrea Foulkes, Gregory Matthews, Nicholas Reich

Biostatistics in Practice: Research Training in High-PerformanceComputing with R

This material is part of the statsTeachR project

Made available under the Creative Commons Attribution-ShareAlike 3.0 UnportedLicense: http://creativecommons.org/licenses/by-sa/3.0/deed.en US

Page 2: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Introduction and welcome...

Page 3: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Tools for reproducible data analysis with R

I Version control: git & GitHub.com

I Dynamic documents: knitr, RMarkdown, Sweave

I RStudio

I ggplot2

Page 4: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Version control systems

Page 5: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Version control systems

Page 6: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Version control systems

Common VCS

I git

I subversion (svn)

I mercurial

I ...

Page 7: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

git

Key command-line operations

I git init: initializes a repository locally

I git clone: clones a repository from a remote source (i.e.GitHub.com)

I git add, git rm: manipulating files

I git commit: commits changes you have made

Page 8: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Version control and reproducibility

Page 9: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Dyanamic Documents in R

I Dynamic R documents allow a user to combine text, R code,and R output, including tables and figures, into one document.

I Why is this useful?I Writing code and producing reports are now one document

rather than many.I When the analysis changes, the results in the report change

automatically.I What else?

I There are several options for how to do this.I R MarkdownI SweaveI knitr

Page 10: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Dyanamic R Reports: Summary

I R Markdown: creates HTML document

I Sweave: creates pdf document AND incorporates LaTeX

I knitr: ≈ Sweave + cacheSweave + pgfSweave + weaver +animation::saveLatex + R2HTML::RweaveHTML +highlight::HighlightWeaveLatex + 0.2 * brew + 0.1 *SweaveListingUtils + more

Page 11: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

R Markdown

I R Markdown creates HTML files

I Reference:http://www.rstudio.com/ide/docs/authoring/using markdown

I Markdown files (.Rmd) act just like text files, except theyallow a user to embed R code in chunks

I The syntax for a chunk in R Markdown:

Regular text“‘{r}Code goes here“‘

Page 12: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Sweave

I Sweave creates pdf files as output

I Reference: http://leisch.userweb.mwn.de/Sweave/

I Sweave Manual: http://www.stat.uni-muenchen.de/ leisch/Sweave/Sweave-manual.pdf

I Sweave not only integrates R code, but also LaTeX!

I The syntax for a chunk in Sweave:

Regular text with $LaTeX$ if you want it.<<OPTIONS >>=Code goes here@

Page 13: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

Sweave: Options

I fig=TRUE (or FALSE): This indicates that the code in thechunk will print the figure to the output pdf document

I echo=TRUE (or FALSE): Should the R input code bedisplayed in the output pdf document

I eval=TRUE (or FALSE): Should the R input code beevaluated

Page 14: Principles and Practice of Reproducible Research with Rnickreich.github.io/methods2/assets/lectures/class6_versionControl.pdf · Dyanamic Documents in R I Dynamic R documents allow

knitr

I Created by Ph.D. student Yihui Xie (what have you done?)

I knitr creates pdf files as output.

I It also allows the use of LaTeX, like Sweave, whereas RMarkown does not.

I Syntax for knitr is largely the same as Sweave.

I Xie describes knitr ≈ Sweave + cacheSweave + pgfSweave +weaver + animation::saveLatex + R2HTML::RweaveHTML +highlight::HighlightWeaveLatex + 0.2 * brew + 0.1 *SweaveListingUtils + more