pkggraph

April 19, 2026 · View on GitHub

Explore various dependencies of a package(s) (on the Comprehensive R Archive Network Like repositories).

Utilities

Start with init() which gets metadata from a CRAN like repository.

The package offers four functions:

  1. get_dependencies(): Get direct or indirect dependencies of a set of packages at desired depth (as a dataframe).
  2. get_neighborhood(): Get both direct and indirect of a set of packages at desired depth (as a dataframe).
  3. as_graph(): Get metadata embedded igraph equivalent of a dependency dataframe.
  4. plot(): Static plot of dependency graph.

Example

suppressPackageStartupMessages(library("dplyr"))
#> Warning: package 'dplyr' was built under R version 4.4.3
init()
#> ℹ Fetching package metadata from repositories ...
#> ℹ Computing package dependencies ...
#> ✔ Done!

# what does `mboost` package do
packmeta |> filter(Package == "mboost") |> pull(Description) |> cat()
#> Functional gradient descent algorithm
#>   (boosting) for optimizing general risk functions utilizing
#>   component-wise (penalised) least squares estimates or regression
#>   trees as base-learners for fitting generalized linear, additive
#>   and interaction models to potentially high-dimensional data.
#>   Models and algorithms are described in <doi:10.1214/07-STS242>,
#>   a hands-on tutorial is available from <doi:10.1007/s00180-012-0382-5>.
#>   The package allows user-specified loss functions and base-learners.

# Get direct 'import' dependencies of `mboost$ \text{two} \text{levels} \text{deeper}
\text{get\_dependencies}("\text{mboost}", \text{level} = 2, \text{relation} = "\text{Imports}")
#> # \text{A} \text{tibble}: 58  \times  3
#>    \text{pkg\_1}  \text{relation} \text{pkg\_2}     
#>    <\text{chr}>  <\text{fct}>    <\text{chr}>     
#>  1 \text{BayesX} \text{Imports}  \text{coda}      
#>  2 \text{BayesX} \text{Imports}  \text{colorspace}
#>  3 \text{BayesX} \text{Imports}  \text{interp}    
#>  4 \text{BayesX} \text{Imports}  \text{sf}        
#>  5 \text{BayesX} \text{Imports}  \text{sp}        
#>  6 \text{BayesX} \text{Imports}  \text{splines}   
#>  7 \text{Matrix} \text{Imports}  \text{grid}      
#>  8 \text{Matrix} \text{Imports}  \text{grid}      
#>  9 \text{Matrix} \text{Imports}  \text{grid}      
#> 10 \text{Matrix} \text{Imports}  \text{lattice}   
#> # ℹ 48 \text{more} \text{rows}

# \text{Get} \text{neighborhood} (\text{direct} \text{and} \text{indirect}) \text{dependencies} (\text{of} \text{all} \text{types}) \text{of} $mboost` one level deeper
get_neighborhood("mboost", level = 1)
#> # A tibble: 222 × 3
#>    pkg_1                     relation pkg_2   
#>    <chr>                     <fct>    <chr>   
#>  1 FDboost                   Depends  mboost  
#>  2 InvariantCausalPrediction Depends  mboost  
#>  3 TH.data                   Depends  MASS    
#>  4 TH.data                   Depends  survival
#>  5 boostrq                   Depends  mboost  
#>  6 boostrq                   Depends  parallel
#>  7 boostrq                   Depends  stabs   
#>  8 catdata                   Depends  MASS    
#>  9 censored                  Depends  survival
#> 10 expectreg                 Depends  BayesX  
#> # ℹ 212 more rows

# convert a dependency dataframe to a graph
get_neighborhood("mboost", level = 1) |> as_graph()
#> IGRAPH 146a4f2 DN-- 56 222 -- 
#> + attr: name (v/c), title (v/c), relation (e/c)
#> + edges from 146a4f2 (vertex names):
#>  [1] FDboost                  ->mboost      
#>  [2] InvariantCausalPrediction->mboost      
#>  [3] TH.data                  ->MASS        
#>  [4] TH.data                  ->survival    
#>  [5] boostrq                  ->mboost      
#>  [6] boostrq                  ->parallel    
#>  [7] boostrq                  ->stabs       
#>  [8] catdata                  ->MASS        
#> + ... omitted several edges

# plot a dependency graph
get_neighborhood("mboost", level = 1, relation = "Imports") |> as_graph() |> plot()

Installation

From CRAN:

pak::pkg_install("pkggraph")

You can install the development version of pkggraph from GitHub with:

# install.packages("pak")
pak::pak("talegari/pkggraph")