Using miniCRAN to identify package dependencies

Introduction

In miniCRAN I expose two functions that provides information about dependencies:

Take a look at some examples. I illustrate with the the package chron, because chron neatly illustrates the different roles of Imports, Suggests and Enhances:

A worked example using the package chron

The function pkgDep() exposes not only these dependencies, but also also all recursive dependencies. In other words, it answers the question which packages need to be installed to satsify all dependencies of dependencies.

This means that the algorithm is as follows:

The resulting list of packages should then contain the complete list necessary to satisfy all dependencies. In code:

library(miniCRAN)
tags <- "chron"
pkgDep(tags, suggests=FALSE, enhances=FALSE, includeBasePkgs = TRUE)
## [1] "chron"    "graphics" "stats"
pkgDep(tags, suggests = TRUE, enhances=FALSE)
##  [1] "chron"        "RColorBrewer" "dichromat"    "munsell"     
##  [5] "plyr"         "labeling"     "colorspace"   "Rcpp"        
##  [9] "digest"       "gtable"       "reshape2"     "scales"      
## [13] "proto"        "MASS"         "stringr"      "ggplot2"
pkgDep(tags, suggests = TRUE, enhances=TRUE)
##  [1] "chron"        "RColorBrewer" "dichromat"    "munsell"     
##  [5] "plyr"         "labeling"     "colorspace"   "Rcpp"        
##  [9] "digest"       "gtable"       "reshape2"     "scales"      
## [13] "proto"        "MASS"         "stringr"      "lattice"     
## [17] "ggplot2"      "zoo"

To create an igraph plot of the dependencies, you can use the function makeDepGraph() and plot the results:

dg <- makeDepGraph(tags, includeBasePkgs=FALSE, suggests=TRUE, enhances=TRUE)
set.seed(1)
plot(dg, legendPosEdge = c(-1, 1), legendPosVertex = c(1, 1), vertex.size=20)

plot of chunk makeDepGraph

Note how the dependencies expand to zoo (enhanced), scales and ggplot (suggested) and then recursively from there to get all the Imports and LinkingTo dependencies.

An example with multiple input packages

A more complicated example:

tags <- c("ggplot2", "data.table", "plyr", "knitr", "shiny", "xts", "lattice")
pkgDep(tags, suggests = TRUE, enhances=FALSE)
##  [1] "ggplot2"      "data.table"   "plyr"         "knitr"       
##  [5] "shiny"        "xts"          "lattice"      "digest"      
##  [9] "gtable"       "reshape2"     "scales"       "proto"       
## [13] "MASS"         "Rcpp"         "stringr"      "RColorBrewer"
## [17] "dichromat"    "munsell"      "labeling"     "colorspace"  
## [21] "evaluate"     "formatR"      "highr"        "markdown"    
## [25] "mime"         "httpuv"       "caTools"      "RJSONIO"     
## [29] "xtable"       "htmltools"    "bitops"       "zoo"         
## [33] "SparseM"      "survival"     "Formula"      "latticeExtra"
## [37] "cluster"      "maps"         "sp"           "foreign"     
## [41] "mvtnorm"      "TH.data"      "sandwich"     "nlme"        
## [45] "Matrix"       "bit"          "codetools"    "iterators"   
## [49] "timeDate"     "quadprog"     "Hmisc"        "BH"          
## [53] "quantreg"     "mapproj"      "hexbin"       "maptools"    
## [57] "multcomp"     "testthat"     "mgcv"         "chron"       
## [61] "reshape"      "fastmatch"    "bit64"        "abind"       
## [65] "foreach"      "doMC"         "itertools"    "testit"      
## [69] "rgl"          "XML"          "RCurl"        "Cairo"       
## [73] "timeSeries"   "tseries"      "its"          "fts"         
## [77] "tis"          "KernSmooth"
dg <- makeDepGraph(tags, includeBasePkgs=FALSE, suggests=TRUE, enhances=TRUE)
plot(dg, legendPosEdge = c(-1, -1), legendPosVertex = c(1, -1), vertex.size=10, cex=1)

plot of chunk so-tags