Learn R Programming

havel (version 0.1.2)

plot_deps_graph: Plot dependency graph

Description

Plot a package's dependency graph, coloring each node by the number of packages it depends on.

Usage

plot_deps_graph(
  pkg,
  dep_type = c("depends", "imports", "linkingto"),
  pak_res = NULL,
  info_method = "pak",
  n_iter = 100,
  init = "mds",
  gg = FALSE,
  lwd = 1,
  cex = 1,
  pad_h = 0.09,
  pad_w = 0.07,
  arw = 1,
  legend_loc = "topright",
  ...
)

Value

By default, no return value, called for side effect of producing a plot. If gg = TRUE, then a ggplot object.

Arguments

pkg

package string passed to pak::pkg_deps

dep_type

type(s) of dependencies to look up. Valid values are c("depends", "imports", "linkingto")

pak_res

a pre-computed result from pak::pkg_deps

info_method

either "pak" or "tools". The latter will use tools::package_dependencies to look up package info.

n_iter

number of iterations for stress graph layout computation

init

how to initialize layout, MDS (default) or randomly

gg

If true, use ggplot2 + ggraph to layout/draw the plot instead of base graphics. Other graphical arguments below will be ignored.

lwd

line width

cex

text size multiplication factor (see graphics::par)

pad_h

height padding

pad_w

width padding

arw

factor by which to lengthen/shorten arrowheads

legend_loc

one of "topright"/"topleft"/"bottomright"/"bottomleft" indicating where to draw the legend

...

other arguments passed to par()

Details

dep_type = "suggests" is currently not supported because Suggests can be cyclic.

Pre-computing the dependency lookup with pak::pkg_deps and passing it to the pak_res argument can be handy when fiddling with graphical parameters. Also handy to avoid hitting the bundled GitHub PAT limits used by pak::pkg_deps().

The arrows and padding will be off if you resize the graphics window with the base graphics version. Either set gg=TRUE or set your desired graphics device size, then re-run your command.

The layout in the base graphics version is initialized with a bit of random jitter. If you want to tweak it change the random seed and try again.

Random layout initialization only applies to base graphics when used, and typically looks worse than MDS initialization. Generally only useful if the MDS layout happens to overlap the legend or something.

See Also

uniq_pkg_deps

Examples

Run this code
plot_deps_graph("ggplot2", pak_res = pkg_deps_ex$ggplot2)
# ^ ggplot2 has a moderate number of dependencies

plot_deps_graph("data.table", pak_res = pkg_deps_ex$data.table)
# ^ data.table has only one

# The `pak_res` arguments here are pre-computed results to avoid internet
# access while running the examples on CRAN's servers. They aren't required.

Run the code above in your browser using DataLab