countCalls: Count the number of calls to one or more functions

Description Usage Arguments Value Author(s) See Also Examples

View source: R/countCalls.R

Description

These functions allow one to count the number of calls to one or more functions.

Usage

1
2
3
4
countCalls(obj, counter = genCounter(), env = globalenv(), print = FALSE)
countMCalls(..., counter = genMultiCounter(funNames), env = globalenv(), print = FALSE,
            funs = substitute(list(...))[-1],
            funNames = sapply(funs, as.character))

Arguments

obj,...

the functions either as quoted namesto be

counter

the counter object to use, typically created via genCounter

env

the environment in which to evaluate the call to trace

print

passed on to trace

funs

an alternative way to specify the functions whose calls are to be counted. This allows the functions to be specified collectively in a list or character vector rather than individually via the ... mechanism.

funNames

the names of the functions, typically computed from the call itself. These are used to make updating the counts more efficient by not having to check if there is already a named element for the function in the integer vector.

Value

These function return the counter. This is a list with 3 functions

value

function to query the current count(s)

reset

function to reset the count(s) to 0, or to create a new empty integer vector if its parameter full is TRUE when calling it.

inc

the function called to increment the counter

Author(s)

Duncan Temple Lang

See Also

trace

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
ctr = countMCalls(rnorm)
replicate(10, rnorm(0))
ctr$value()

ctr$reset()
replicate(5, rnorm(0))
ctr$value()


ctr = countMCalls(dnorm, rnorm)
replicate(10, dnorm(0))
replicate(7, rnorm(1))
dnorm(1)
ctr$value()

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