Using by = NULL gives an error when used on a zero-row data.table, but I don't think it's the right error message.
Example
library(data.table)
dt <- data.table(x = c("a","b","a","b"), y = c(1,2,3,4))
dt[0, .N, by = NULL ]
> Error in `[.data.table`(dt, 0, .N, by = NULL) :
column or expression 1 of 'by' or 'keyby' is type NULL. Do not quote column names. Usage: DT[,sum(colC),by=list(colA,month(colB))]
I don't think this message makes sense, especially given you are allowed to use by = NULL on a non-zero-row table
dt[ x == "a", .N, by = NULL ]
# N
# 1: 2
Can the dt[0, .N, by = NULL ] example be allowed to pass and not throw an error, so it performs similarly to
dt[0, .N, by = x]
Empty data.table (0 rows and 2 cols): x,N
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.3
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 packrat_0.5.0
Using
by = NULLgives an error when used on a zero-row data.table, but I don't think it's the right error message.Example
I don't think this message makes sense, especially given you are allowed to use
by = NULLon a non-zero-row tableCan the
dt[0, .N, by = NULL ]example be allowed to pass and not throw an error, so it performs similarly to