FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Using a function in env= fails · Issue #6026 · Rdatatable/data.table · GitHub

Using a function in env= fails #6026

Description

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'

This is not a general issue with [:

DT[, .Primitive("sum")(b), by=a]
#        a    V1
#    <int> <int>
# 1:     1     3
# 2:     2     4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugprogrammingparameterizing queries: get, mget, eval, env

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL