Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R data.table 1.9.2 issue on setkey

Tags:

r

data.table

It seems to be a bug introduced post 1.8.10 related to setkey with DT which contains lists. Run two below codes to see the issue:

library(data.table)
dtl <- list()
dtl[[1]] <- data.table(scenario = 1,
                       processing = c(function(x) x))
dtl[[2]] <- data.table(scenario = 2,
                       processing = c(function(x) x))
dt <- rbindlist(dtl)
setkeyv(dt, c("scenario"))

and second below, currently produce error:

dtl <- list()
dtl[[1]] <- data.table(scenario = 2, # <- note we change order
                       processing = c(function(x) x))
dtl[[2]] <- data.table(scenario = 1,
                       processing = c(function(x) x))
dt <- rbindlist(dtl)
setkeyv(dt, c("scenario")) #setkey cannot sort?

It was working well in 1.8.10. I'm not able to setkey on my DT, seems to be related to DT which contains list of functions. Any easy workaround? I track the error msg to C code but have no idea how to fix it.

R 3.0.2 + data.table 1.9.2 on windows 64bit Thanks

like image 784
jangorecki Avatar asked Mar 05 '14 01:03

jangorecki


1 Answers

This is now fixed in commit #1216 of v1.9.3 (the current development version). From NEWS:

setkey doesn't allow list columns as keys. However, a bug in setkey did not allow setting key on data.table just containing list columns. This is now fixed. Closes #5366. Thanks to James Sams for reporting and to Michael Nelson for pinpointing the issue with a minimal reproducible example. Also thanks to MusX for reporting on SO.

We should be pushing 1.9.4 (next stable release) to CRAN sometime soon.

like image 114
Arun Avatar answered Oct 17 '22 01:10

Arun