Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data.table bug, causing a segfault in R

Tags:

r

data.table

The following code segfaults my R 2.15.0, running data.table 1.8.9.

library(data.table)
d = data.table(date = c(1,2,3,4,5), value = c(1,2,3,4,5))

# works as expected
d[-5][, mean(value), by = list(I(as.integer((date+1)/2)))]

# crashes R
d[-5, mean(value), by = list(I(as.integer((date+1)/2)))]

And on a related note, the following two commands have very different outputs:

d[-5][, value, by = list(I(as.integer((date+1)/2)))]
#    I value
# 1: 1     1
# 2: 1     2
# 3: 2     3
# 4: 2     4

d[-5, value, by = list(I(as.integer((date+1)/2)))]
#    I         value
# 1: 1 2.121996e-314
# 2: 1 2.470328e-323
# 3: 2 3.920509e-316
# 4: 2 2.470328e-323

Simpler command crashing my R from the comments:

d[-5, value, by = date]

As Ricardo points out, it's the combination of negative indexing and by that creates the problem.

like image 735
eddi Avatar asked Apr 16 '13 20:04

eddi


1 Answers

UPDATE: This has been fixed in v1.8.11. From NEWS :

Crash or incorrect aggregate results with negative indexing in i is fixed, #2697. Thanks to Eduard Antonyan (eddi) for reporting. Tests added.

like image 181
Arun Avatar answered Oct 17 '22 23:10

Arun