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

Description Usage Arguments Value Author(s) See Also Examples

View source: R/getCallStack.R

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

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

Arguments

fun

the name of teh 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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 Jan. 20, 2020, 5:16 a.m.