【问题标题】:Find value of all functions with trace active查找所有具有跟踪活动的函数的值
【发布时间】:2016-01-20 06:49:11
【问题描述】:

如何找到我已激活trace 的所有功能的值?我知道我可以打开全局tracingState,但我发现我忘记了正在跟踪哪些函数,并且想知道是否有办法检索这些信息?简单的例子,

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')

【问题讨论】:

    标签: r debugging trace


    【解决方案1】:

    我没有意识到这一点,但是trace 在修改后的函数中添加了一个类“functionWithTrace”。所以,很容易找回那些,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 2018-06-24
      相关资源
      最近更新 更多