I'm trying to understand the new env parameter in data.table.
This works (data.table version 1.14.3)
df1 = data.table(x=seq(1,10))
a="x"
df1[a<5, env=list(a=a)]
x
1: 1
2: 2
3: 3
4: 4
However, I can't get it to work in join conditions
df1 = data.table(x=seq(1,10), xz=rnorm(10))
df2 = data.table(y=seq(5,14), yz=rnorm(10))
a="x"
b="y"
# This fails
df1[df2, on=.(a<b), nomatch=0, env=list(a=a,b=b)]
Any thoughts on how to pass variables a and b to the on clause of data.table? I understand how to do it via function. However, I'm struggling to find best way to pass a and b as characters, and still use in the on clause
# This works
func <- function(d1,d2,a,b) {
eval(substitute(d1[d2, on=.(a<b), nomatch=0]))
}
func(df1,df2,x,y)