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
)A function.
An environment, parent.frame() by default. Ignored if FUN is not NULL.
Boolean. If TRUE, only functions that are direct descendants or antecedents of
FUN will be shown.
Boolean. If TRUE, rather than rendering the graph the intermediate graphviz
specification is returned.
If as.text is TRUE, a character vector. Otherwise, a foodweb object as described
above.
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.
# 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
#> # A `foodweb`: 5 vertices and 7 edges
#> digraph 'foodweb' {
#> f()
#> g() -> { f() }
#> h() -> { f(), g() }
#> i() -> { f(), g(), h() }
#> j() -> { j() }
#> }
# You can access the components directly or via getter functions
x$funmat
#> # A foodweb matrix: 5 functions and 7 links
#> CALLEE
#> CALLER f g h i j
#> f 0 0 0 0 0
#> g 1 0 0 0 0
#> h 1 1 0 0 0
#> i 1 1 1 0 0
#> j 0 0 0 0 1
get_graphviz_spec(x)
#> digraph 'foodweb' {
#> "f()"
#> "g()" -> { "f()" }
#> "h()" -> { "f()", "g()" }
#> "i()" -> { "f()", "g()", "h()" }
#> "j()" -> { "j()" }
#> }
# Calculate the foodweb of a function in another package
foodweb(glue::glue)
#> # A `foodweb`: 14 vertices and 13 edges
#> digraph 'foodweb' {
#> glue() -> { glue_data() }
#> color_transformer() -> { glue() }
#> glue_col() -> { glue() }
#> glue_safe() -> { glue() }
#> glue_sql() -> { glue() }
#> glue_data() -> { %||%(), as_glue(), bind_args(), drop_null(), has_names(), recycle_columns(), trim() }
#> %||%()
#> as_glue()
#> bind_args() -> { delayed_assign() }
#> drop_null()
#> has_names()
#> recycle_columns()
#> trim()
#> delayed_assign()
#> }