Why does trace(…, edit=TRUE) not work when … = [.data.table

时光怂恿深爱的人放手 提交于 2019-12-05 02:49:22

This is apparently being caused by the recent addition of curly braces (i.e. {}) at one place in data.table's formal argument list.

First, a MRE to show that braces really do cause trace(..., edit=TRUE) to choke:

## Without braces, no problem
func <- function(inColor=FALSE, col = if(inColor) "red" else "grey") { 
    plot(rnorm(99), col=col)}

trace(func, edit=TRUE)
# [1] "func"


## With braces, tracing fails
funcB <- function(inColor=FALSE, col = if(inColor) "red" else {"grey"}) { 
    plot(rnorm(99), col=col)}

trace(funcB, edit=TRUE)
# Error in .makeTracedFunction(def, tracer, exit, at, print, doEdit) : 
#   the editing in trace() can only change the body of the function, not 
#   the arguments or defaults

Then, for the record, here are the formals for [.data.table in versions 1.8.6 (for which tracing works) and version 1.8.8 (for which it doesn't):

## Version 1.8.6 -- Tracing worked
function (x, i, j, by, keyby, with=TRUE, nomatch=getOption("datatable.nomatch"), 
    mult="all", roll=FALSE, rolltolast=FALSE, 
    which=FALSE, .SDcols, verbose=getOption("datatable.verbose"), drop=NULL)


## Version 1.8.8 -- Tracing doesn't (See {} in the 'rollends' argument)
function (x, i, j, by, keyby, with=TRUE, nomatch=getOption("datatable.nomatch"), 
    mult = "all", roll = FALSE, 
    rollends = if (roll == "nearest") c(TRUE, 
        TRUE) else {
        if (roll >= 0) 
            c(FALSE, TRUE)
        else c(TRUE, FALSE)
    }, 
    which = FALSE, .SDcols, verbose = getOption("datatable.verbose"), 
    allow.cartesian = getOption("datatable.allow.cartesian"), 
    drop = NULL, rolltolast = FALSE) 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!