Search code examples
rdebuggingtrace

Find value of all functions with trace active


How can I find the value of all the functions for which I have activated trace? I know I can turn of the global tracingState, but I find that I forget which functions are being traced and was wondering if there is a way to retrieve this information? Simple example,

tst <- function(cond) { if (cond) 'yay' else 'neigh' }
tst1 <- function(x) { x*x }
trace('tst', tracer=browser)
trace('tst1', tracer=browser)

## Can I retrieve a vector of functions being traced?
## would like a result here to be:
## [1] "tst"  "tst1"

## Cleaning
untrace('tst')
untrace('tst1')

Solution

  • I didn't realize this, but trace adds a class, "functionWithTrace" to the modified functions. So, it is easy enough to retrieve those,

    res <- eapply(.GlobalEnv, function(x) if (inherits(x, 'functionWithTrace')) TRUE)
    names(unlist(res))
    # [1] "tst"  "tst1"