list_len 从 rlang 0.2.0 开始被软弃用

list_len is soft-deprecated as of rlang 0.2.0

我是 运行 一些 R 代码,我收到以下警告消息

Warning message:
`list_len()` is soft-deprecated as of rlang 0.2.0.
Please use `new_list()` instead
This warning is displayed once per session. 

就其价值而言,调用代码如下所示

  df = convertCallCountsToHashTable(call_counts_hash_table )

  df %>%
    filter(needs_review) %>%
    filter( package != "R_GlobalEnv") %>%
    top_n( num_functions, desc(review_timer ))

我知道convertCallCountsToHashTable中的代码永远不会直接调用list_len;但是它确实调用了 dplyrtidyrlubridate 中的一些方法。

我怎样才能像 traceback 那样找出这条警告消息的来源?

如何让警告在每个会话中显示多次,以便我可以尝试调试它?

可以debuglist_len,然后用sys.calls看函数栈。请注意,由于 list_len 未导出,因此您必须引用命名空间。

my_fun <- function() rlang::list_len(3)
debug(rlang::list_len)
my_fun()
debugging in: rlang::list_len(3)
debug: {
    signal_soft_deprecated(paste_line("`list_len()` is soft-deprecated as of rlang 0.2.0.", 
        "Please use `new_list()` instead"))
    new_list(.n)
}
Browse[2]> sys.calls()
[[1]]
my_fun()

[[2]]
rlang::list_len(3)