collectArgInfo: Trace a function and collect information about each argument

Description Usage Arguments Value Author(s) See Also Examples

View source: R/argInfo.R

Description

This function is used to trace calls to a function and collect information such as the class, typeof, length and dim of each argument in the call. The results are collected in a list that can then be queried using gatherArgInfo.

Usage

1
2
3
collectArgInfo(fn, op = getParamInfo, print = FALSE, envir = globalenv(),
               col = genInfoCollectorFun(op, names(formals(fn, envir))),
               ...)

Arguments

fn

the name of the function to be trace, or the function itself

op

the function to be called for each argument in the call to get the information of interest.

print

a logical value passed to trace to control whether it emits a message each time the traced function is called.

envir

the environment in which to find the function to be traced

col

a list of functions used in the trace action. This is a parameter so that callers can create it before calling this function and manipulate the functions and their enviroment to customize the trace actions. For example, we use this in collectCallResults to put the results in the same environment as the arguments in all calls.

...

passed directly to trace allowing the caller to, for example, add an exit or at argument.

Value

This returns a function which can be called to access the results. One can pass it the name of a variable which will call gatherArgInfo for you.

Author(s)

Duncan Temple Lang

See Also

trace

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
g = function(a, b = 2){ invisible(list(length(a), class(b))) }
i = collectArgInfo(g)

g(mtcars, 1:10)
g(3, TRUE)
g(lm, matrix(0, 2, 3))
g("xyz", matrix(letters[1:6], 2, 3))

i()
i("class")

duncantl/CallCounter documentation built on Jan. 20, 2020, 5:16 a.m.