If in uniqueN a zero-length vector is passed to by, the function throws an error. I would expect it to return 0.
library(data.table)
DT <- data.table(idx=1:4, value="val")
uniqueN(DT, character(0))
# Error in forderv(x, by = by, retGrp = TRUE, na.last = if (!na.rm) FALSE else NA) :
# Internal error: DT has 2 columns but 'by' is either not integer or is length 0
This was unexpected, as instead the following works:
uniqueN(DT[, .SD, .SDcols=character(0)])
# [1] 0
Output of sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.8
loaded via a namespace (and not attached):
[1] compiler_3.6.3
If in
uniqueNa zero-length vector is passed toby, the function throws an error. I would expect it to return 0.This was unexpected, as instead the following works:
Output of
sessionInfo()