合并并不是非常大的data.tables会立即导致R被终止

合并并不是非常大的data.tables会立即导致R被终止,r,memory,data.table,R,Memory,Data.table,我在这台机器上有32GB的ram,但我可以比任何人更快地杀死R;) 例子 这里的目标是使用利用data.table效率的函数实现两个data.table的rbind() 输入: rm(list=ls()) gc() tmp.table <- data.table(X1=sample(1:7,4096000,replace=TRUE), X2=as.factor(sample(1:2,4096000,replace=TRUE)),

我在这台机器上有32GB的ram,但我可以比任何人更快地杀死R;)

例子 这里的目标是使用利用data.table效率的函数实现两个data.table的
rbind()

输入:

rm(list=ls())
gc()
tmp.table <- data.table(X1=sample(1:7,4096000,replace=TRUE),
                           X2=as.factor(sample(1:2,4096000,replace=TRUE)),
                           X3=sample(1:1000,4096000,replace=TRUE),
                           X4=sample(1:256,4096000,replace=TRUE),
                           X5=sample(1:16,4096000,replace=TRUE),
                           X6=rnorm(4096000))

setkey(tmp.table,X1,X2,X3,X4,X5,X6)

join.table <- data.table(X1 = integer(), X2 = factor(), 
                         X3 = integer(), X4=integer(),
                         X5 = integer(), X6 = numeric())

setkey(join.table,X1,X2,X3,X4,X5,X6)

tables()
join.table <- merge(join.table,tmp.table,all.y=TRUE)
输出:

          used (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells 1604987 85.8    2403845  128.4   2251281  120.3
Vcells 3019405 23.1  537019062 4097.2 468553954 3574.8
     NAME            NROW  MB COLS              KEY              
[1,] join.table         0   1 X1,X2,X3,X4,X5,X6 X1,X2,X3,X4,X5,X6
[2,] tmp.table  4,096,000 110 X1,X2,X3,X4,X5,X6 X1,X2,X3,X4,X5,X6
Total: 111MB
输入:

rm(list=ls())
gc()
tmp.table <- data.table(X1=sample(1:7,4096000,replace=TRUE),
                           X2=as.factor(sample(1:2,4096000,replace=TRUE)),
                           X3=sample(1:1000,4096000,replace=TRUE),
                           X4=sample(1:256,4096000,replace=TRUE),
                           X5=sample(1:16,4096000,replace=TRUE),
                           X6=rnorm(4096000))

setkey(tmp.table,X1,X2,X3,X4,X5,X6)

join.table <- data.table(X1 = integer(), X2 = factor(), 
                         X3 = integer(), X4=integer(),
                         X5 = integer(), X6 = numeric())

setkey(join.table,X1,X2,X3,X4,X5,X6)

tables()
join.table <- merge(join.table,tmp.table,all.y=TRUE)
输入:

rm(list=ls())
gc()
tmp.table <- data.table(X1=sample(1:7,4096000,replace=TRUE),
                           X2=as.factor(sample(1:2,4096000,replace=TRUE)),
                           X3=sample(1:1000,4096000,replace=TRUE),
                           X4=sample(1:256,4096000,replace=TRUE),
                           X5=sample(1:16,4096000,replace=TRUE),
                           X6=rnorm(4096000))

setkey(tmp.table,X1,X2,X3,X4,X5,X6)

join.table <- data.table(X1 = integer(), X2 = factor(), 
                         X3 = integer(), X4=integer(),
                         X5 = integer(), X6 = numeric())

setkey(join.table,X1,X2,X3,X4,X5,X6)

tables()
join.table <- merge(join.table,tmp.table,all.y=TRUE)
Data.table是1.8.11版。

更新:这已在的commit 1123中修复。发件人: o
rbindlist
至少有一个因子列,并且至少有一个空的
数据。表
导致SEGFULT(或在linux/mac中报告了与哈希表相关的错误)。这个问题现在已经解决了#5355。感谢Trevor Alexander报告SO(以及mnel提交错误报告):


这可以通过一行
数据表
和一列
因子
以及一列零行数据表和一列因子来重现

library(data.table)
A <- data.table(x=factor(1), key='x')
B <- data.table(x=factor(), key='x')
merge(B, A, all.y=TRUE)

# Rstudio -> R encountered fatal error
#  R Gui -> R for windoze GUI has stopped working
如果您运行它,将产生相同的错误


这已作为问题报告给包作者

当您将空的
连接表
tmp.表
合并时,您预计会发生什么情况?如果R崩溃,您似乎应该向包维护人员报告此错误(特别是因为他们响应速度非常快),对于我来说,rstudio_0.97.551工作得很好,R版本3.0.2 x86_64-w64-mingw32/x64(64位)和data.table_1.8.10。此问题与一个错误有关,已报告。感谢you@JoshuaUlrich当然可以,但一般来说,究竟是什么和哪里出了问题(RStudio或data.table),是否有解决办法(同时使用不同的命令/语法)?我知道答案是肯定的,但如果过于逐字逐句地理解它并结束问题,那么危险在于它可能会阻止用户询问问题。我无法在Mac 10.9上的1.8.10或1.8.11中重现这一点。无论是在RGui还是TerminalI中,都不会添加操作系统信息。+1非常感谢您提交报告并链接到这里。我提高了它的优先级。