UPDATE: Old question ... it was resolved by data.table v1.5.3 in Feb 2011.
I am trying to use the data.table
package, and really like the speedups I am getting, but I am stumped by this error when I do x[y, <expr>]
where x
and y
are "data-tables" with the same key, and <expr>
contains column names of both x
and y
:
require(data.table)
x <- data.table( foo = 1:5, a = 5:1 )
y <- data.table( foo = 1:5, boo = 10:14)
setkey(x, foo)
setkey(y, foo)
> x[y, foo*boo]
Error in eval(expr, envir, enclos) : object 'boo' not found
UPDATE... To clarify the functionality I am looking for in the above example: I need to do the equivalent of the following:
with(merge(x,y), foo*boo)
However according to the below extract from the data.table
FAQ, this should have worked:
Finally, although it appears as though x[y] does not return the columns in y, you can actually use the columns from y in the j expression. This is what we mean by join inherited scope. Why not just return the union of all the columns from x and y and then run expressions on that? It boils down to eciency of code and what is quicker to program. When you write x[y,fooboo], data.table automatically inspects the j expression to see which columns it uses. It will only subset, or group, those columns only. Memory is only created for the columns the j uses. Let's say foo is in x, and boo is in y (along with 20 other columns in y). Isn't x[y,fooboo] quicker to program and quicker to run than a merge step followed by another subset step ?
I am aware of this question that addressed a similar issue, but it did not seem to have been resolved satisfactorily. Anyone know what I am missing or misunderstanding? Thanks.
UPDATE: I asked on the data-table help mailing list and the package author (Matthew Dowle) replied that indeed the FAQ quoted above is wrong, so the syntax I am using will not work currently, i.e. I cannot refer to the y
columns in the j
(i.e. second) argument when I do x[y,...]
.