These functions create networks of the dependencies between or within R packages:
collect_cran() creates a network of the dependencies among the packages
available on CRAN.
It reads the Depends, Imports, LinkingTo, Suggests,
and Enhances fields of each package's DESCRIPTION file,
and creates a network in which the nodes are packages
and the ties are dependencies of a given type.
collect_pkg() creates a network of the dependencies among the functions
defined in a directory of R scripts.
It uses R's own parser to establish where each function is defined
and which functions it calls,
and creates a network in which the nodes are functions
and the ties are calls.
https://www.r-bloggers.com/2016/01/r-graph-objects-igraph-vs-network/
Inspired by Jakob Gepp's helfRlein::get_network(),
https://github.com/STATWORX/helfRlein/blob/master/R/get_network.R
A character vector of one or more package names, from which dependencies are collected. By default "all", which collects the dependencies among all the packages currently available on CRAN.
A character vector naming the dependency fields to
collect, from "Depends", "Imports", "LinkingTo", "Suggests",
and "Enhances".
By default c("Depends", "Imports", "LinkingTo"),
the dependencies that must be installed alongside a package.
The maximum number of steps from pkg to collect.
By default infinite, i.e. the whole dependency closure.
Whether to collect the packages that pkg depends upon,
"out" by default, the packages that depend upon pkg, "in",
or both, "all".
Character string with the path of the directory in which to
look for R scripts.
By default the current working directory.
Where dir holds a DESCRIPTION file and an R folder, as a package does,
the R folder is searched.
Logical.
Where TRUE, calls to functions that are not defined in dir,
such as those from other packages, are included as nodes too.
By default FALSE, since these are numerous and rarely of interest.
A tidygraph object representing the network of package dependencies
or function dependencies in a package.
Dependency networks grow quickly, and are most useful once scoped.
collect_cran() therefore collects only the Depends, Imports,
and LinkingTo fields by default, since these are the dependencies that
must be installed alongside a package, as in utils::install.packages().
Adding Suggests grows the dependency closure of a package by
two orders of magnitude.
For the same reason, collect_pkg() collects only calls to the functions
defined in the directory by default.
Both return networks that can be scoped further using, for example,
to_ego(), to_uniplex(), to_giant(), to_no_isolates(),
to_blocks(), or to_subgraph().
collect_cran() relies on utils::available.packages(),
which caches the repository index for an hour by default.
Set options(max.repo.cache.age = ) for a fresher or staler snapshot.
Note that these functions are not as actively maintained as others in the package, so please let us know if any are not currently working for you or if there are missing import routines by raising an issue on Github.
to_ego(), to_uniplex(), to_no_isolates()
Other makes:
make_create,
make_ego,
make_explicit,
make_learning,
make_play,
make_random,
make_read,
make_stochastic,
make_write
if (FALSE) { # \dontrun{
# The packages {manynet} depends upon, directly and indirectly:
collect_cran("manynet")
# The packages that depend directly upon {manynet}:
collect_cran("manynet", direction = "in", max_dist = 1)
} # }
if (FALSE) { # \dontrun{
# The network of calls among the functions in the working directory:
collect_pkg()
# Collapsed onto generics, where the directory is a package:
# to_blocks(collect_pkg(), node_attribute(collect_pkg(), "generic"))
} # }