| Title: | Visualise Function Dependencies |
|---|---|
| Description: | Easily create graphs of the inter-relationships between functions in an environment. |
| Authors: | Lewin Appleton-Fox [aut, cre] |
| Maintainer: | Lewin Appleton-Fox <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-06-01 10:49:29 UTC |
| Source: | https://github.com/lewinfox/foodwebr |
A foodweb object describes the relationship of functions in an environment. It has two
components: funmat (function matrix) which encodes the caller/callee relationships (i.e. which
functions call which) and graphviz_spec which is a text representation of the graph and is used
for the default plotting behaviour.
foodweb( FUN = NULL, env = parent.frame(), filter = !is.null(FUN), as.text = FALSE )foodweb( FUN = NULL, env = parent.frame(), filter = !is.null(FUN), as.text = FALSE )
FUN |
A function. |
env |
An environment, |
filter |
Boolean. If |
as.text |
Boolean. If |
foodweb() looks at the global environment by default. If you want to look at another
environment you can either pass a function to the FUN argument of foodweb() or pass an
environment to the env argument. If FUN is provided then the value of env is ignored, and
the environment of FUN will be used.
If as.text is TRUE, a character vector. Otherwise, a foodweb object as described
above.
# Create some functions to look at f <- function() 1 g <- function() f() h <- function() { f() g() } i <- function() { f() g() h() } j <- function() j() x <- foodweb() x # You can access the components directly or via getter functions x$funmat get_graphviz_spec(x) # Calculate the foodweb of a function in another package foodweb(glue::glue)# Create some functions to look at f <- function() 1 g <- function() f() h <- function() { f() g() } i <- function() { f() g() h() } j <- function() j() x <- foodweb() x # You can access the components directly or via getter functions x$funmat get_graphviz_spec(x) # Calculate the foodweb of a function in another package foodweb(glue::glue)
Returns a matrix of 0s and 1s with a row and column for each function in an environment, such that if the function on the x-axis calls the function on the y-axis, the element is 1, otherwise 0.
foodweb_matrix(env = parent.frame())foodweb_matrix(env = parent.frame())
env |
Environment in which to search for functions. |
An n x n matrix where n is the number of functions in env.
foodweb object.Extract the function matrix from a foodweb object.
get_funmat(x)get_funmat(x)
x |
A |
x$funmat - a numeric matrix.
foodweb object.Extract the GraphViz specification from a foodweb object.
get_graphviz_spec(x)get_graphviz_spec(x)
x |
A |
x$graphviz_spec - a character scalar.
graphviz specification from a function matrixGiven a function matrix created by foodweb_matrix(), convert it into a text specification
that can be passed to DiagrammeR::grViz().
graphviz_spec_from_matrix(funmat)graphviz_spec_from_matrix(funmat)
funmat |
A function matrix generated by |
A text string.
fm <- matrix(c(0, 1, 1, 1, 0, 1, 0, 1, 0), nrow = 3) colnames(fm) <- rownames(fm) <- c("foo", "bar", "baz") graphviz_spec_from_matrix(fm)fm <- matrix(c(0, 1, 1, 1, 0, 1, 0, 1, 0), nrow = 3) colnames(fm) <- rownames(fm) <- c("foo", "bar", "baz") graphviz_spec_from_matrix(fm)
foodweb?Is an object a foodweb?
is.foodweb(x)is.foodweb(x)
x |
The object to test |
Boolean
foodweb_matrix
Print a foodweb_matrix
## S3 method for class 'foodweb_matrix' print(x, ...)## S3 method for class 'foodweb_matrix' print(x, ...)
x |
A |
... |
Unused |
x, invisibly