pkg_graph: Render a package-level dependency graph

View source: R/pkg_graph.R

pkg_graphR Documentation

Render a package-level dependency graph

Description

Discovers R packages under scan_dir via projects, parses each one's Depends and Imports fields, and renders edges between packages that both live in scan_dir. External CRAN dependencies are dropped.

Usage

pkg_graph(
  scan_dir = path.expand("~"),
  packages = NULL,
  include_suggests = FALSE,
  ...
)

Arguments

scan_dir

Directory to scan for project directories.

packages

Optional character vector limiting the graph to these packages.

include_suggests

If TRUE, also include edges for packages in each project's Suggests field. Default FALSE (only Depends and Imports).

...

Passed through to graph_svg.

Value

Character vector of SVG lines. Write with writeLines().

Examples

d <- file.path(tempdir(), "pkgdemo")
dir.create(file.path(d, "parent"), recursive = TRUE, showWarnings = FALSE)
dir.create(file.path(d, "child"), showWarnings = FALSE)
writeLines(c("Package: parent", "Title: P", "Version: 0.1.0"),
           file.path(d, "parent", "DESCRIPTION"))
writeLines(c("Package: child", "Title: C", "Version: 0.1.0",
             "Imports: parent"),
           file.path(d, "child", "DESCRIPTION"))
svg <- pkg_graph(scan_dir = d)
writeLines(svg, tempfile(fileext = ".svg"))

saber documentation built on Nov. 10, 2026, 9:06 a.m.