Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R data.table segfault when trying to update one column and create another

Tags:

r

data.table

Is it possible to create a new column in a data.table and update an existing column at the same time? The following didn't work. Thanks.

library(data.table)
dt <- data.table(x=runif(4), y=runif(4), z=c("x","x","y","y"))
dt[, c("x", "y") := list(x[1], y[1]), by=z]     # works
dt[, c("x", "newx") := list(x[1], y[1]), by=z]

Caught Segfault:

address 0x20000010, cause 'memory not mapped'

Traceback:

 1: [.data.table(dt, , :=(c("x", "newx"), list(x[1], y[1])), by = z)
 2: dt[, :=(c("x", "newx"), list(x[1], y[1])), by = z]
like image 313
chriss Avatar asked Aug 29 '13 22:08

chriss


1 Answers

Yes. But you need v1.8.9 from R-Forge to get the following fix :

o Mixing adding and updating into one DT[, :=(existingCol=...,newCol=...), by=...] now works without error or segfault, #2778 and #2528. Many thanks to Arunkumar Srinivasan for reporting and for the nice reproducible examples. Tests added.

See latest NEWS (updated live) for other changes in v1.8.9.

like image 82
Matt Dowle Avatar answered Sep 28 '22 17:09

Matt Dowle