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

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

Closed
mb706 opened this issue Oct 16, 2020 · 2 comments · Fixed by #4790
Closed

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

mb706 opened this issue Oct 16, 2020 · 2 comments · Fixed by #4790
Milestone

Comments

@mb706
Copy link

mb706 commented Oct 16, 2020

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
@mb706
Copy link
Author

mb706 commented Oct 21, 2020

min() etc. not working is now fixed in R-devel by accepting logical matrices. You could still fix the mode(as.matrix(dt0)) being logical problem, but that is more of an inconsistency that should have few real implications.

@jangorecki
Copy link
Member

jangorecki commented Oct 21, 2020

Aside: because of that fix in R-devel our recent release is now failing on R-devel, #4769

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants