The Data-table FAQ 1.11 states:<div><br></div><div>"<span class="Apple-style-span" style="font-family: Helvetica; ">When you write x[y,foo*boo], data.table automatically inspects the j expression to see which columns it uses. </span></div>
<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">It will only subset, or group, those columns only. Memory is only created for the columns the j uses. </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">Let’s say foo is in x, and boo is in y (along with 20 other columns in y). </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;">Isn’t x[y,foo*boo] quicker to program and quicker to run than a merge step followed by another subset step ?"</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">Contrary to what it says above, I get an error when I try to access a y-column in the "j" argument of x[y,j]. </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">See the sequence of code below. </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;">> x <- data.table( foo = c(1,1,1,2,2,3), a = 1:6, key = 'foo') </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;">> y <- data.table( foo = c(1,2), boo = 10:11, key = 'foo') </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"> </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"># the below works as expected</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;">> x[y]</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"> foo a</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">[1,] 1 1</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">[2,] 2 4</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">> with( merge(x,y), foo*boo) </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">[1] 10 10 10 22 22</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"><br>
</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"># I want to acheive the same result as the above using the </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;"># syntactically more compact (and faster?) code below:</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"><br>
</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">> x[y, foo * boo ] </span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;">Error in eval(expr, envir, enclos) : object 'boo' not found</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"><br>
</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">So is the FAQ just wrong, or am I misunderstanding something?</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica">
<span class="Apple-style-span" style="font-size: small;"><br></span></p><p></p></div>