Skip to content

as.matrix() of empty data.table wrong type (causing min() to fail on empty dt) #4762

@mb706

Description

@mb706

This is maybe not that big of an issue by itself, but it makes min() for empty data.table fail:

dt <- data.table(x = 1)
dt0 <- dt[FALSE]
mode(as.matrix(dt))
#> [1] "numeric"
mode(as.matrix(dt0))
#> [1] "logical"

I would be expecting "numeric" for both of these.

data.frame behaves the same (imho wrong) way, so feel free to close with wontfix I guess.

This causes the following problem:

min(dt)
#> [1] 1
min(dt0)
#> Error in FUN(X[[i]], ...) : 
#>   only defined on a data frame with all numeric variables

Expected behaviour:

min(dt0)
#> [1] Inf
#> Warning message:
#> In min(dt0) : no non-missing arguments to min; returning Inf
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 32 (Thirty Two)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.10.so

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=en_US.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.13.1

loaded via a namespace (and not attached):
[1] compiler_4.0.2

using

data.table 1.13.1 IN DEVELOPMENT built 2020-10-16 09:03:50 UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions