Skip to content

Eval of quote()-ed expression in wrong frame in := with join #2176

Open

Description

@rballentine

R v3.4.0 and data.table v1.10.4.

library(data.table)
DT<-data.table(x=1:3)
X<-data.table(x=2, y=2)

DT[X, z:=eval(quote(y)), on='x']
# assignment succeeds

q<-quote(y)
DT[X, z:=eval(q), on='x']
# Error in eval(q) : object 'y' not found

Though there seems to be no difference between the two evals, the first one works as expected and the second throws an error. I'm guessing in the second example the evaluation of the expression is happening before the join. I think evaluation should happen after the join, as it does in all cases other than when := (and lapply) are nested within joins.

Both styles worked as expected in data.table v1.9.6 and broke my code when I updated to v1.10.4.

Same issue with evals in lapply in joins:

DT[X, lapply(eval(quote(y)), I), on='x']
# as expected

q<-quote(y)
DT[X, lapply(eval(q), I), on='x']
# Error in eval(q) : object 'y' not found

Activity

  1. franknarf1 commented on May 23, 2017

    @franknarf1
    Contributor

    If you're willing to embed the new column name as well, there's

    q = quote(z := y)
    DT[X, on=.(x), eval(q)]
    

    Alternately, you can always use DT[X, on=.(x), z := get("y")]

  2. arunsrinivasan commented on Jun 29, 2017

    @arunsrinivasan
    Member

    (I think) the problem is .SD doesn't contain columns of X. It'd be nice to have the internal environment to have all vars in case of join (i.e., both data.tables' columns..)

  3. jangorecki commented on Mar 22, 2020

    @jangorecki
    Member

    isn't this a duplicate of #1180?

  4. added
    programming
    on Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfeature requestprogramming

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions