<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p> </p>
<p>Hi,</p>
<p>Now fixed in v1.8.9 :</p>
<pre>o  Mixing adding and updating into one DT[, `:=`(existingCol=...,newCol=...), by=...] now works<br />     without error or segfault, #2778 and #2528. Many thanks to Arunkumar Srinivasan for reporting<br />     both with reproducible examples. Tests added.</pre>
<p>Matthew</p>
<p> </p>
<p>On 12.05.2013 11:44, Matthew Dowle wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<p> </p>
<p>Hi,</p>
<p>Yes I get that in latest dev too.  Thanks for the nice example,  please file. </p>
<p>Matthew</p>
<p> </p>
<p>On 12.05.2013 08:53, Arunkumar Srinivasan wrote:</p>
<blockquote style="padding-left: 5px; border-left: #1010ff  2px  solid; margin-left: 5px; width: 100%;">
<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>The issue is this. Suppose you've a data.table with two columns x and y as follows:</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>Now you want to add a new column "z" by reference grouped by "x". So, you'd do:</div>
<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>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>DT[, `:=`(z = .N, w = 2), by = x] # R session crashes</div>
<div>Here, both R and Rstudio session crashes with the traceback message:</div>
<div>
<div> *** caught segfault ***</div>
<div>address 0x0, cause 'memory not mapped'</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>
<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>DT[, `:=`(z = .GRP, w = 2), by = x]  # works fine</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>Here's my sessionInfo() from before the crash:</div>
<div>
<div>R version 3.0.0 (2013-04-03)</div>
<div>Platform: x86_64-apple-darwin10.8.0 (64-bit)</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>attached base packages:</div>
<div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div>
<div>other attached packages:</div>
<div>[1] data.table_1.8.8</div>
<div>loaded via a namespace (and not attached):</div>
<div>[1] tools_3.0.0</div>
</div>
<div>Best,</div>
<div>Arun</div>
</div>
</blockquote>
<p> </p>
<div> </div>
</blockquote>
<p> </p>
<div> </div>
</body></html>