Skip to contents

Discovers package dependencies at two levels:

Usage

build_import_edges(r_files, root = NULL)

Arguments

r_files

Character vector of absolute paths to .R source files.

root

Optional character(1). Project root directory. When provided, a DESCRIPTION file is searched there.

Value

A data.frame with columns:

from

File stem (or project identifier) where the import appears.

to

Package name being imported.

weight

Numeric: edge weight (default 1).

source

Character: "library", "qualified", or "description".

Details

  1. Explicitlibrary(pkg) and require(pkg) calls in source files.

  2. Qualifiedpkg::fn and pkg:::fn patterns (the package name is extracted as an import).

  3. DESCRIPTION – if a DESCRIPTION file is found in the project root (or any ancestor up to two levels up), its Imports: and Depends: fields are parsed.

Each discovered dependency produces an edge from the file stem (or the project root stem) to the package name. Base-R packages (base, methods, utils, stats, datasets, graphics, grDevices) are included when explicitly referenced but are labelled with source = "qualified" or source = "description" for downstream filtering.

Examples

if (FALSE) { # \dontrun{
proj  <- detect_rproject("/path/to/mypkg")
edges <- build_import_edges(proj$r_files, root = proj$root)
} # }