reconhub / incidence

☣:chart_with_upwards_trend::chart_with_downwards_trend:☣ Compute and visualise incidence
https://reconhub.github.io/incidence
Other
58 stars 13 forks source link

give a better error when subsetting groups that don't exist #82

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

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)