r reproducibility

20
R and Reproducibility A Proposal David Smith useR! 2014

Upload: revolution-analytics

Post on 26-Jan-2015

110 views

Category:

Technology


1 download

DESCRIPTION

Presented at useR! 2014, July 2, 2014. The R ecosystem is in a state of near constant change. While a new version of the R engine is now released just once a year, 2-3 patches are usually released in the interim. On top of that, new versions of R packages on CRAN are released at rate of several per day (and that’s not counting packages that are part of the BioConductor project or hosted elsewhere on the Web). While this rapid change is a boon for the advancement of R, it can cause problems for package authors[1] and also for scientists and their peers who may need to reliably reproduce the results of an R script (possibly dependent on a number of packages) months or even years down the line. In this talk we propose a downstream distribution of CRAN packages that provides for the reproducibility of R scripts and reduces the impact of dependencies for packages authors.

TRANSCRIPT

Page 1: R reproducibility

R and ReproducibilityA Proposal

David SmithuseR! 2014

Page 2: R reproducibility

What is Reproducibility?

“The goal of reproducible research is to tie specific instructions to data analysis and experimental data so that scholarship can be recreated, better understood and verified.” CRAN Task View on Reproducible Research (Kuhn)

• Method + Environment -> Results

• A process for:– Sharing the method– Describing the environment– Recreating the results

xkcd.com/242/

Page 3: R reproducibility

3

Why care about reproducibility?

Academic / Research• Verify results• Advance Research

Business• Production code• Reliability• Reusability• Regulation www.nytimes.com/2011/07/08/health/research/08genes.html

http://arxiv.org/pdf/1010.1092.pdf

Page 4: R reproducibility

4

R and Reproducibility

Results

Interfaces

Platform

Packages

R Engine

• Hand-assembled• Sweave/knitr/DeployR/Shiny

• R GUI / DevelopR / RStudio• Batch / Web Services

• OS / Virtualization• Hardware Architecture

• CRAN• BioConductor / GitHub / …

• R Version• Base + Recommended pkgs

Page 5: R reproducibility

5

Observations

• R versions are pretty manageable– Major versions just once a year– Patches rarely introduce incompatible changes

• Good solutions for literate programming– Interfaces help

• OS/Hardware not the major cause of problems

• The big problem is with packages– CRAN is in a state of continual flux

Page 6: R reproducibility

6

Package Problem #1 : The User

http://xkcd.com/234/

I heard you need to create a TPS Report. Here, I’ve got an R script that does that already.

Oh, you need to download these 5

packages first.

I already did, and it

still doesn’t work!

Well, it worked when I wrote it 3 weeks ago.

YOURGrr.

Package updates…

Page 7: R reproducibility

7

Package Problem #2: The Author

http://xkcd.com/970/

Time to update my package on CRAN!

>> Dependent packages that now fail to build: 67

>> Resubmit your package and try again

Crap.

Page 8: R reproducibility

8

Package Problem #3 : The Update

http://xkcd.com/664/

3 days later…Woot! A new version of R is out! I have 10 minutes now, time to download and install!

… package not found …

… can’t install package…

… error …

Page 9: R reproducibility

9

The Proposal

• Change the default way R handles packages– Install packages local to projects

• “Snapshot” CRAN daily– Make it easy to get & use package versions used in script development

Not a new idea!– Ooms, “Possible Directions for Improving Dependency Versioning in

R”, R Journal 5/1– BioConductor Project– Revolution R Enterprise– Linux distros

Page 10: R reproducibility

10

Example

• R script file using 6 most popular packages

Page 11: R reproducibility

11

Sharing a script reproducibly… and simply

# Run with R 3.1.0require(RRT)mran_set(snapshot="2014-06-27")

# find packages used in this project# get package versions used by script author# install locally to this project

require(ggplot2)require(data.table)require(knitr) …

Page 12: R reproducibility

12

RRT: The R Reproducibility Toolkit

• Open Source R Package (GPLv2)• From an R project folder:– Detect packages & dependencies used in project– Download and install from MRAN– Versions selected according to script date– Find and use packages from local install

github.com/RevolutionAnalytics/RRT

Page 13: R reproducibility

13

MRAN - Implementation

A downstream CRAN mirror with daily snapshots• Use rsync to mirror CRAN daily– Only downloads changed packages

• Use zfs to store incremental snapshots– Storage only required for new packages

• Organize snapshots into a labelled hierarchy– Access package versions by date of use

• CRAN snapshot server hosted by cloud provider– Provisioned for availability and latency

Page 14: R reproducibility

14

Future work

• Just getting started!• Snapshot binaries and source packages• Other repos (BioConductor, GitHub, user)• Institution-level package duplication– CRAN “behind the firewall”

• User-defined package versions• Checks on R versions

• Suggestions welcome!github.com/RevolutionAnalytics/RRT

Page 15: R reproducibility

Thank You!

David [email protected]

blog.revolutionanalytics.com

Page 16: R reproducibility

16

Possible Solution

• Bundle all packages with scripts• Packrat solves this very well– Project + package dependencies stored in Github

• But:– Contributes to package fragmentation– Adds friction to the sharing process– Doesn’t address the problem for R generally

Page 17: R reproducibility

17

CRAN vs GithubCRAN• “Repository of Record”

– Default for R users

• Strict quality checking• Handles dependencies• Binaries built

– But only current versions saved

• Manual update process• Dependent on volunteer

support

Github• Frictionless publishing /

updates– RStudio integration

• Social development– Pull requests FTW

• Ease of updates

• Fragmented – no unified directory of packages

• Permanence – accounts closed / repos deleted

Page 18: R reproducibility

18

A downstream CRAN solution?

“I don't see why CRAN needs to be involved in this effort at all. A third party could take snapshots of CRAN at R release dates, and make those available to package users in a separate repository. It is not hard to set a different repository than CRAN as the default location from which to obtain packages.”-- R-core member, r-devel, March 2014

Page 19: R reproducibility

19

Snapshot CRAN repository : requirements

• Availability• Latency• Bandwidth• Storage• Binary package archives

• Other enhancements?

Page 20: R reproducibility

Defaults are important!!20

Proposal“Development Branch” “Stable Branch”

MRANCRAN Downstram

Reproducible