You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DT=data.table(a=1:2, b=3:4)
DT[, f(b), by=a, env=list(f=sum)]
# Error in as.character(jsub[[1L]]) : # cannot coerce type 'builtin' to vector of type 'character'
The issue is that the resulting query, instead of being DT[, sum(b), by=a], becomes DT[, .Primitive("sum")(b), by=a].
The same will happen for any closure:
DT[, f(b), by=a, env=list(f=\(x) sum(x))]
# Error in as.character(jsub[[1L]]) : # cannot coerce type 'closure' to vector of type 'character'
Just adding that this is a general issue with [, but it's a bit hard to construct examples AFAICT, which is why it hasn't come up. E.g.
DT= data.table(a=1:3)
eval(substitute(DT[, foo(a)], list(foo=sum)))
# Error in as.character(jsub[[1L]]) : # cannot coerce type 'builtin' to vector of type 'character'
Directly writing .Primitive("sum")(b) as above is not quite the same -- AIUI it's confusing because .Primitive("sum") is just the deparse() output / print string representation of the LHS.
The issue is that the resulting query, instead of being
DT[, sum(b), by=a]
, becomesDT[, .Primitive("sum")(b), by=a]
.The same will happen for any closure:
This is not a general issue with
[
:The text was updated successfully, but these errors were encountered: