RobinHankin / disordR

https://robinhankin.github.io/disordR/
1 stars 0 forks source link

empty disord objects #51

Closed RobinHankin closed 1 year ago

RobinHankin commented 1 year ago

Extracting zero elements from a disord gives an empty object. But the resulting object "forgets" its class:

library("disordR")
#> Loading required package: Matrix

o <-  disord(c("a","b","a","z","c"))
o %in% "a"
#> A disord object with hash cfa45e2d02a803b2bfa4e2157e5a6e1da7d71321 and elements
#> [1]  TRUE FALSE  TRUE FALSE FALSE
#> (in some order)
o %in% "y"
#> [1] FALSE FALSE FALSE FALSE FALSE

o[o %in% "a"]
#> [1] "a" "a"
o[o %in% "y"]
#> integer(0)

Created on 2023-07-10 with reprex v2.0.2

Above, we see that both o %in% "a" and o %in% "y" correctly return a logical disord object. But while o[o %in% "a"] correctly returns a character vector [here dropped], o[o %in% "y"] returns integer(0) and it should return character(0)