Managing R package dependencies
One of my take aways from last week’s EARL conference was that R is more and more growing out of its academic roots into the enterprise. And with that come some challenges, e.g. how do I ensure consistent and systematic access to a set of R packages in an organisation, in particular when one team is providing packages to others?
Two packages can help here: roxyPackage and miniCRAN.
I wrote about roxyPackage earlier on this blog. It allows me to create a local repository to distribute my package, while at the same time execute and control the build process from within R. But what about my package’s dependencies? Here miniCRAN helps. miniCRAN is a new package by Andrie de Vries that enables me to find and download all package dependencies and store them in a local repository, e.g. the one used by roxyPackage.
For more details about roxyPackage and miniCRAN read the respective package vignettes.Example
To create a local sub-CRAN repository for the two packages I maintain on CRAN and with all their dependencies I use:
library("miniCRAN")
my.pkgs <- c("googleVis", "ChainLadder")
pkgs <- pkgDep(my.pkgs, suggests = TRUE, enhances=FALSE)
makeRepo(pkgs = pkgs, path="/Users/Shared/myCRANRepos")
And to visualise the dependencies:
dg <- makeDepGraph(my.pkgs, includeBasePkgs=FALSE,
suggests=TRUE, enhances=TRUE)
set.seed(1)
plot(dg, legendPosEdge = c(-1, 1),
legendPosVertex = c(1, 1), vertex.size=20)
What a surprise! In total I end up with 42 packages from CRAN and I didn’t expect any connection between the ChainLadder and googleVis package.Bonus tip
Don’t miss out on Pat Burns’s insightful talk about effective risk management from EARL. His thoughts reminded me of the great Karl Popper: Good tests kill flawed theories; we remain alive to guess again.Session Info
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] miniCRAN_0.1-0
loaded via a namespace (and not attached):
[1] httr_0.5 igraph_0.7.1 stringr_0.6.2 tools_3.1.1
[5] XML_3.98-1.1
Citation
For attribution, please cite this work as:Markus Gesmann (Sep 23, 2014) Managing R package dependencies. Retrieved from https://magesblog.com/post/2014-09-23-managing-r-package-dependencies/
@misc{ 2014-managing-r-package-dependencies,
author = { Markus Gesmann },
title = { Managing R package dependencies },
url = { https://magesblog.com/post/2014-09-23-managing-r-package-dependencies/ },
year = { 2014 }
updated = { Sep 23, 2014 }
}