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
{{ message }}
Repository navigation
Eval of quote()-ed expression in wrong frame in := with join #2176
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
(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..)
Activity
franknarf1 commentedon May 23, 2017
If you're willing to embed the new column name as well, there's
Alternately, you can always use
DT[X, on=.(x), z := get("y")]arunsrinivasan commentedon Jun 29, 2017
(I think) the problem is
.SDdoesn't contain columns ofX. It'd be nice to have the internal environment to have all vars in case of join (i.e., both data.tables' columns..)jangorecki commentedon Mar 22, 2020
isn't this a duplicate of #1180?