give a better error when subsetting groups that don't exist
zkamvar opened this issue · comments
Zhian N. Kamvar commented
When subsetting with a group that didn't exist, an "index out of bounds" error was thrown. This should be replaced by a more sensible error.
library(incidence)
i <- incidence(sample(1:10, 100, replace = TRUE), groups = rep(c("a", "b"), length.out = 100))
i[, "a"]
#> <incidence object>
#> [50 cases from days 1 to 10]
#>
#> $counts: matrix with 10 rows and 1 columns
#> $n: 50 cases in total
#> $dates: 10 dates marking the left-side of bins
#> $interval: 1 day
#> $timespan: 10 days
#> $cumulative: FALSE
i[, "c"]
#> Error in out$counts[i, j, drop = FALSE]: subscript out of bounds
Created on 2018-11-26 by the reprex package (v0.2.1)