reconverse / incidence2

Compute and visualise incidence (reworking of the original incidence package)
https://www.reconverse.org/incidence2
Other
17 stars 2 forks source link

using `select()` in an `<incidence2>` object drops the `<tibble>` class #120

Closed avallecam closed 1 month ago

avallecam commented 1 month ago

Is this behaviour expected? If it is, interested to read the rationale behind it. I found it while writing an assessment to connect incidence2 outputs with epinow2. I tested this with a class object only, and the class was kept.

One implication of this is that I add one step to convert the incidence2 output to tibble before epinow2 to conserve the display features as written in https://github.com/avallecam/epicatador/blob/main/68-emcr-summative-06.R#L53-L56

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


Please include a brief description of the problem with a code example:

library(dplyr)
library(incidence2)

ebola <- subset(outbreaks::ebola_sim_clean$linelist ,!is.na(hospital))
daily_incidence <- incidence(ebola, date_index = "date_of_onset")

# {incidence2} coerse output to <tibble> class (which I like)
daily_incidence %>% class()
#> [1] "incidence2" "tbl_df"     "tbl"        "data.frame"

# mutate() keep the <tibble> class (which I like)
daily_incidence %>% dplyr::mutate(col = "all") %>% class()
#> [1] "incidence2" "tbl_df"     "tbl"        "data.frame"

# BUT select() drop the <tibble> class (which I do not like)
daily_incidence %>% dplyr::select(date_index, count) %>% class()
#> [1] "data.frame"

daily_incidence %>% incidence2::select(date_index, count) %>% class()
#> [1] "data.frame"

# test with a tibble ------------------------------------------------------

# mutate() keep the <tibble> class
ebola %>% as_tibble() %>% dplyr::mutate(col = "all") %>% class()
#> [1] "tbl_df"     "tbl"        "data.frame"

# select() keep the <tibble> class
ebola %>% as_tibble() %>% dplyr::select(-gender) %>% class()
#> [1] "tbl_df"     "tbl"        "data.frame"

Created on 2024-10-06 with reprex v2.1.1


TimTaylor commented 1 month ago

Cheers for the report @avallecam. This should now be fixed on the main branch. I'll try and get it on CRAN this evening/tomorrow. It should have been updated with the 2.3.0 release but was an oversight.

avallecam commented 1 month ago

it worked, thanks!

library(dplyr)
library(incidence2)

ebola <- subset(outbreaks::ebola_sim_clean$linelist ,!is.na(hospital))
daily_incidence <- incidence(ebola, date_index = "date_of_onset")

# {incidence2} coerse output to <tibble> class (which I like)
daily_incidence %>% class()
#> [1] "incidence2" "tbl_df"     "tbl"        "data.frame"

# mutate() keep the <tibble> class (which I like)
daily_incidence %>% dplyr::mutate(col = "all") %>% class()
#> [1] "incidence2" "tbl_df"     "tbl"        "data.frame"

# [now solved] BUT select() drop the <tibble> class (which I do not like)
daily_incidence %>% dplyr::select(date_index, count) %>% class()
#> [1] "tbl_df"     "tbl"        "data.frame"

daily_incidence %>% incidence2::select(date_index, count) %>% class()
#> [1] "tbl_df"     "tbl"        "data.frame"

#

Created on 2024-10-07 with reprex v2.1.1