Listing R Package Dependencies Without Installing Packages Listing R Package Dependencies Without Installing Packages r r

Listing R Package Dependencies Without Installing Packages


You can use the result of the available.packages function. For example, to see what ggplot2 depends on :

pack <- available.packages()pack["ggplot2","Depends"]

Which gives :

[1] "R (>= 2.14), stats, methods"

Note that depending on what you want to achieve, you may need to check the Imports field, too.


Another neat and simple solution is the internal function recursivePackageDependencies from the library packrat. However, the package must be installed in some library on your machine. The advantage is that it works with selfmade non-CRAN packages as well. Example:

packrat:::recursivePackageDependencies("ggplot2",lib.loc = .libPaths()[1])

giving:

 [1] "R6"           "RColorBrewer" "Rcpp"         "colorspace"   "dichromat"    "digest"       "gtable"       [8] "labeling"     "lazyeval"     "magrittr"     "munsell"      "plyr"         "reshape2"     "rlang"        [15] "scales"       "stringi"      "stringr"      "tibble"       "viridisLite" 


I am surprised no one mentioned tools::package_dependencies() , which is the simplest solution, and has a recursive argument (which the accepted solution does not offer).

Simple example looking at the recursive dependencies for the first 200 packages on CRAN:

library(tidyverse)avail_pks <- available.packages()deps <- tools::package_dependencies(packages = avail_pks[1:200, "Package"],                                    recursive = TRUE)tibble(Package=names(deps),       data=map(deps, as_tibble)) %>%   unnest(data)#> # A tibble: 7,125 x 2#>    Package value         #>    <chr>   <chr>         #>  1 A3      xtable        #>  2 A3      pbapply       #>  3 A3      parallel      #>  4 A3      stats         #>  5 A3      utils         #>  6 aaSEA   DT            #>  7 aaSEA   networkD3     #>  8 aaSEA   shiny         #>  9 aaSEA   shinydashboard#> 10 aaSEA   magrittr      #> # … with 7,115 more rows

Created on 2020-12-04 by the reprex package (v0.3.0)