Here is a reprex illustrating the problem. Basically the problem is that when fit_curve() issues warnings, some functions like growth_rate() down the line can ignore warnings as an option, but plot() cannot. In terms of design, I am wondering if it would be useful to have a user-facing function to ignore warnings e.g.
x %>%
fit_curve() %>%
ignore_warnings() %>%
plot()
Or is it okay to have this as internal and add an option to plot()? Would be useful to discuss before making changes (also, happy to do them).
@TimTaylor tagging you for awareness and future discussions :)
library(tidyverse)
library(incidence2)
library(i2extras)
## set the random seed so we all get the same result
set.seed(1)
days <- 0:30
cases <- rpois(n = length(days), lambda = 3)
## step 3: create dates of infection for these cases
date_infection <- rep(days, cases)
data <- tibble(date_infection)
data
#> # A tibble: 96 × 1
#> date_infection
#> <int>
#> 1 0
#> 2 0
#> 3 1
#> 4 1
#> 5 2
#> 6 2
#> 7 2
#> 8 3
#> 9 3
#> 10 3
#> # … with 86 more rows
## build epicurve and fitting
res <- data %>%
incidence(date_infection) %>%
fit_curve(model = "negbin",
control = glm.control(maxit = 1e3))
res
#> # A tibble: 1 × 8
#> count_variable data model estimates fitting_warning fitting_error
#> <chr> <list<tibble[> <list> <list> <list> <list>
#> 1 count [30 × 2] <negb… <df [30 × … <chr [2]> <NULL>
#> # … with 2 more variables: prediction_warning <list>, prediction_error <list>
## Note: there seems to be a 'safe' warning, which I would like to be able to
## ignore in further analyses
res %>%
pull(fitting_warning)
#> [[1]]
#> [1] "NaNs produced" "NaNs produced"
## get growth rates: this behaves as expected
res %>%
growth_rate() # empty result coz of warnings - fine
#> # A tibble: 0 × 9
#> # … with 9 variables: count_variable <chr>, model <list>, r <dbl>,
#> # r_lower <dbl>, r_upper <dbl>, growth_or_decay <lgl>, time <lgl>,
#> # time_lower <lgl>, time_upper <lgl>
res %>%
growth_rate(include_warnings = TRUE) # results as expected - fine
#> # A tibble: 1 × 9
#> count_variable model r r_lower r_upper growth_or_decay time time_lower
#> <chr> <lis> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>
#> 1 count <neg… -0.00276 -0.0256 0.0200 halving 251. 27.1
#> # … with 1 more variable: time_upper <dbl>
## but plotting won't go through
res %>%
plot()
#> Error: Can't subset columns that don't exist.
#> x Column `count` doesn't exist.
Created on 2021-10-21 by the reprex package (v2.0.1)
Here is a reprex illustrating the problem. Basically the problem is that when
fit_curve()issues warnings, some functions likegrowth_rate()down the line can ignore warnings as an option, butplot()cannot. In terms of design, I am wondering if it would be useful to have a user-facing function to ignore warnings e.g.Or is it okay to have this as internal and add an option to
plot()? Would be useful to discuss before making changes (also, happy to do them).@TimTaylor tagging you for awareness and future discussions :)
Created on 2021-10-21 by the reprex package (v2.0.1)