reconverse/incidence2

Error: object 'date_onset' not found

mllstrm opened this issue · 1 comments

Please place an "x" in all the boxes that apply

  • I have the most recent version of incidence2 and R
  • I have found a bug
  • I have a reproducible example
  • I want to request a new feature

Hi!

Can´t create an incidence objekt. Got this: "Error: object 'date_onset' not found"

I have tried to recreate the example from epirhandbook:
https://epirhandbook.com/en/epidemic-curves.html

I use R 4.2.2 (and got the same result on 4.3.0)

linelist <- import("linelist_cleaned.xlsx")

epi_day <- incidence(            
  x = linelist,                           
  date_index = date_onset,    
  interval = "day"                   
)

Hi @mllstrm. The 2.0 release of {incidence2} came with some breaking changes (see https://cran.r-project.org/web/packages/incidence2/news/news.html for details). It is probably worth raising an issue in the epirhandbook repository.

The two changes that have broken this are the fact that we no longer support non-standard evaluation (e.g. date_index must now be quoted) and for a day interval users should convert the date_index variable to date prior to calling (the day interval will be reinstated as an option in a coming release - apologies it should not have been removed).

The current implementation would be to first ensure that date_onset is a date variable and then call incidence, i.e.

# for character date_onset
epi_day <- linelist |>
    mutate(date_onset = as.Date(date_onset)) |>
    incidence(date_index = "date_onset")

# or something like for other types of date_onset
epi_day <- linelist |>
    mutate(date_onset = clock::as_date(date_onset)) |>
    incidence(date_index = "date_onset")