这似乎是一个在 1.8.10 之后引入的与包含列表的带有 DT 的 setkey 相关的错误。
运行以下两个代码以查看问题:
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"))
下面的第二个,目前产生错误:
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?
它在 1.8.10 中运行良好。我无法在我的 DT 上设置键,似乎与包含函数列表的 DT 有关。有什么简单的解决方法吗?我将错误消息跟踪到 C 代码,但不知道如何修复它。
R 3.0.2 + data.table 1.9.2 在 Windows 64 位
谢谢
最佳答案
现在已在 v1.9.3(当前开发版本)的 commit #1216 中修复。来自 NEWS :
setkey
doesn't allow list columns as keys. However, a bug insetkey
did not allow setting key ondata.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.
我们应该很快将 1.9.4(下一个稳定版本)推送到 CRAN。
关于R data.table 1.9.2 关于 setkey 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22186798/