Build the call tree of a function
call_stack.Rdcall_stack() takes the name of a function, optionally namespaced
(e.g. "dplyr::select"), statically parses its body, and recursively
resolves every function it calls, building a tree of those calls, the
calls those functions make, and so on.
Resolution is static (read from the function's source code), not a
runtime trace: the function is never called. UseMethod() dispatch is
resolved by looking up the generic's registered S3 methods and
following each one. Other dynamic calls (NextMethod(), S4 and R6
dispatch, non-standard evaluation) show as leaves rather than being
followed further.
Value
An object of class call_stack: a named list with name (the
function name) and calls (a list of child nodes with the same shape).
See also
print.call_stack() for how the tree is drawn.
Examples
call_stack("mean.default", max_depth = 1)
#> █─mean.default
#> ├─.Internal
#> ├─anyNA
#> ├─c
#> ├─floor
#> ├─is.complex
#> ├─is.logical
#> ├─is.na
#> ├─is.numeric
#> ├─isTRUE
#> ├─length
#> ├─return
#> ├─sort.int
#> ├─stop
#> ├─unique
#> └─warning
# a generic: UseMethod() is replaced by the methods it dispatches to
call_stack("mean", max_depth = 1)
#> █─mean
#> ├─mean.Date
#> ├─mean.POSIXct
#> ├─mean.POSIXlt
#> ├─mean.default
#> ├─mean.difftime
#> ├─mean.quosure
#> └─mean.vctrs_vctr