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
dt1= data.table(a=1, key='a')
dt2= data.table(a=1, b=list(quote(5*a)), key='a')
#this works:dt1[dt2][, eval(b[[1]], .SD)]
#[1] 5# this doesn't (but should produce exact same result as above)dt1[dt2, eval(b[[1]], .SD)]
#Error in eval(b[[1]], .SD) : object 'b' not found
Actually thinking about this a bit - this is probably due to .SD only having LHS data.table columns, which is not that unreasonable, except that it's unclear how else one could do this kind of universal evaluation if using .SD is not an option.
I can't remember if this was ever discussed - what should.SD be inside a join? My gut reaction is that it should be the same as what it is immediately after the join (basically same conversation we had about .EACHI a while back), i.e. should contain all of the columns and not just LHS.
If it's agreed that .SD should only be for the LHS, that's fine, but it would be nice (and arguably essential) to also have i.SD, so you could eval(b,c(.SD,i.SD)) or something similar.
The problem seems to go beyond eval, though:
dt1[dt2,{y = c(.SD); NULL}] # works
dt1[dt2,{y = c(b[[1]]); NULL}] # works
dt1[dt2,{y = c(b[[1]],.SD); NULL}] # Error in eval(expr, envir, enclos) : object 'b' not found
@MichaelChirico it is not a duplicate of #935.
AFAIU this issue occurs due to the fact that when j's root call is eval() call for which we are kicking in an optimization that is injecting quoted expression, which is evaluated in .SD already.
qc= quote(5*a)
dt1[dt2, eval(qc)]
#[1] 5
Following workaround will work.
myeval=evaldt1[dt2, myeval(b[[1]], .SD)]
#[1] 5
issue would go away if we would deprecate special eval() handling in j.
Activity
eantonya commentedon Jun 17, 2015
Actually thinking about this a bit - this is probably due to
.SDonly having LHSdata.tablecolumns, which is not that unreasonable, except that it's unclear how else one could do this kind of universal evaluation if using.SDis not an option.I can't remember if this was ever discussed - what should
.SDbe inside a join? My gut reaction is that it should be the same as what it is immediately after the join (basically same conversation we had about.EACHIa while back), i.e. should contain all of the columns and not just LHS.franknarf1 commentedon Jun 17, 2015
If it's agreed that
.SDshould only be for the LHS, that's fine, but it would be nice (and arguably essential) to also havei.SD, so you couldeval(b,c(.SD,i.SD))or something similar.The problem seems to go beyond
eval, though:arunsrinivasan commentedon Jun 17, 2015
Related to #935
This'd work:
MichaelChirico commentedon Apr 11, 2019
Is this a duplicate of #935?
jangorecki commentedon Mar 22, 2020
@MichaelChirico it is not a duplicate of #935.
AFAIU this issue occurs due to the fact that when
j's root call iseval()call for which we are kicking in an optimization that is injecting quoted expression, which is evaluated in .SD already.Following workaround will work.
issue would go away if we would deprecate special
eval()handling inj.