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

Can I create a new column in a data table and update an existing column at the same time? The following did not 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] 
+6
source share
1 answer

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

o Mixing add and update into one DT [, := (existingCol = ..., newCol = ...), by = ...] now works without errors or segfault, # 2778 and # 2528. Many thanks to Arunkumar Shrinivasan for message and for good reproducible examples. Added tests.

See the latest NEWS (updated live) for other changes in version 1.8.9.

+5
source

Source: https://habr.com/ru/post/952789/


All Articles