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

View source: R/countCalls.R

countCallsR Documentation

Count the number of calls to one or more functions

Description

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

Usage

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

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 Nov. 23, 2023, 3:38 p.m.