Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow by = NULL on zero-row data.table #3530

Closed
SymbolixAU opened this issue May 1, 2019 · 0 comments · Fixed by #3561
Closed

allow by = NULL on zero-row data.table #3530

SymbolixAU opened this issue May 1, 2019 · 0 comments · Fixed by #3561
Assignees
Milestone

Comments

@SymbolixAU
Copy link

@SymbolixAU SymbolixAU commented May 1, 2019

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 
@jangorecki jangorecki self-assigned this May 14, 2019
@jangorecki jangorecki changed the title [feature request] allow by = NULL on zero-row data.table allow by = NULL on zero-row data.table May 14, 2019
@mattdowle mattdowle added this to the 1.12.4 milestone May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants