Learn R Programming

foodwebr (version 1.0.0)

foodweb: Create a foodweb

Description

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.

Usage

foodweb(
  FUN = NULL,
  env = parent.frame(),
  filter = !is.null(FUN),
  as.text = FALSE
)

Value

If as.text is TRUE, a character vector. Otherwise, a foodweb object as described above.

Arguments

FUN

A function.

env

An environment, parent.frame() by default. Ignored if FUN is not NULL.

filter

Boolean. If TRUE, only functions that are direct descendants or antecedents of FUN will be shown.

as.text

Boolean. If TRUE, rather than rendering the graph the intermediate graphviz specification is returned.

Details

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab