genStackCollector: Generate a closure to use with trace to collect information...

View source: R/getCallStack.R

genStackCollectorR Documentation

Generate a closure to use with trace to collect information about the call stack.

Description

This function creates two functions that we use to a) collect the call stack for calls to a function using trace and b) access the results.

callNames returns the names of the functions being called in a call stack.

Usage

genStackCollector(fun = NULL, num = 0, expansionFactor = 2)

Arguments

fun

the name of the function that we will trace to find the call stacks

num

a guess as to the number of calls to this function so that we can preallocate the list in which we store the call stack for each call to the function

expansionFactor

a number that indicates by what factor to grow the list for storing the results should we have to extend it.

Value

A list with 2 elements - an update function and a value function.

Author(s)

Duncan Temple Lang

See Also

trace

Examples

z = genStackCollector(`[`)
trace(`[`, z$update)
mtcars[1, 2]
a = 1:10
a[2:3]
f = function(x) x[x > 4]
f(a)

lm(mpg ~ ., mtcars)

untrace(`[`)

z$value()
sapply(z$value(), length)

callNames(z$value()[[1]])

callNames(z$value()[[3]])

callNames(z$value()[[4]])

duncantl/CallCounter documentation built on Nov. 23, 2023, 3:38 p.m.