R data.table segfault when trying to update one column and create another
data.table, r
Solution
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.
Problem
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] ```