1/29/18:就此问题开了一个问题: https://github.com/Rdatatable/data.table/issues/2590
我试图了解这是一个错误还是一个功能。我的理解是,对数据表中的每一行计算j表达式。因此,我期望一个空的data.table不产生输出。在下面的3个案例中,我不明白为什么案例2会产生任何输出或为什么会产生警告。
a <- data.table(foo = 0, bar = 1)
b <- a[1==2] #empty table
print("Test 1")
b[, .(foo, bar)] # expected output
print("Test 2")
b[, .(foo, bar, baz = "Hello")] #Unexpected output
print("Test 3")
b[1==2, .(foo, bar, baz = "Hello")] #expected output
输出:
[1] "Test 1"
Empty data.table (0 rows) of 2 cols: foo,bar
[1] "Test 2"
baz
1: Hello
Warning messages:
1: In as.data.table.list(jval) :
Item 1 is of size 0 but maximum size is 1, therefore recycled with 'NA'
2: In as.data.table.list(jval) :
Item 2 is of size 0 but maximum size is 1, therefore recycled with 'NA'
[1] "Test 3"
Empty data.table (0 rows) of 3 cols: foo,bar,baz