<div>
Hi,
</div><div>I just discovered some weird R-session crash in data.table. Here's an example to reproduce the crash. I did not find any bug filed regarding this issue. Maybe others can verify this? Then I'll file it as a bug. </div><div><br></div><div>The issue is this. Suppose you've a data.table with two columns x and y as follows:</div><div><br></div><div>require(data.table)</div><div>DT <- data.table(x = rep(1:2, c(3,2)), y = 6:10)</div><div><div> x y</div><div>1: 1 6</div><div>2: 1 7</div><div>3: 1 8</div><div>4: 2 9</div><div>5: 2 10</div></div><div><br></div><div>Now you want to add a new column "z" by reference grouped by "x". So, you'd do:</div>
<div><div><br></div><div>DT[, `:=`(z = .GRP), by = x]</div><div><div> x y z</div><div>1: 1 6 1</div><div>2: 1 7 1</div><div>3: 1 8 1</div><div>4: 2 9 2</div><div>5: 2 10 2</div></div><div><br></div><div>Now, for the sake of producing this error, assume that you assigned "z" the wrong value and that you want to change it. But, also you realised that you want to add another column "w" as well. So, you go ahead and do (remember to do the previous step and then this one):</div><div><br></div><div>DT[, `:=`(z = .N, w = 2), by = x] # R session crashes</div><div><br></div><div>Here, both R and Rstudio session crashes with the traceback message:</div><div><br></div><div><div> *** caught segfault ***</div><div>address 0x0, cause 'memory not mapped'</div><div><br></div><div>Traceback:</div><div> 1: `[.data.table`(DT, , `:=`(z = .GRP, w = 2), by = x)</div><div> 2: DT[, `:=`(z = .GRP, w = 2), by = x]</div><div><br></div></div><div>This on the other hand works as expected if you assign both columns the first time.</div><div><div>require(data.table)</div><div>DT <- data.table(x = rep(1:2, c(3,2)), y = 6:10)</div><div></div></div><div>DT[, `:=`(z = .GRP, w = 2), by = x] # works fine</div><div></div><div><br></div><div>That is, if you assign by reference (:=) with "by" and re-assign a variable while also creating another variable, there seems to be a segfault. This error may not be limited to this case, but that I've just tested this.</div><div><br></div><div>Here's my sessionInfo() from before the crash:</div><div><br></div><div><div>R version 3.0.0 (2013-04-03)</div><div>Platform: x86_64-apple-darwin10.8.0 (64-bit)</div><div><br></div><div>locale:</div><div>[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8</div><div><br></div><div>attached base packages:</div><div>[1] stats graphics grDevices utils datasets methods base </div><div><br></div><div>other attached packages:</div><div>[1] data.table_1.8.8</div><div><br></div><div>loaded via a namespace (and not attached):</div><div>[1] tools_3.0.0</div></div><div><br></div><div>Best,</div><div>Arun</div><div><br></div></div>