Count the number of rows in each ggconsort cohort

cohort_count(.data, ...)

cohort_count_int(.data, ...)

cohort_count_adorn(.data, ..., .label_fn = NULL)

Arguments

.data

A ggconsort_cohort object

...

Cohorts to include in the output, can be quoted or unquoted cohort names, or tidyselect helpers such as [tidyselect::starts_with()].

.label_fn

An optional custom function for formatting cohort counts

Value

A tibble with cohort name, row number total, and label.

Functions

  • cohort_count: Returns a tibble with cohort name, row number total and label.

  • cohort_count_int: Returns a named vector with cohort counts.

  • cohort_count_adorn: Returns a cohort count in "(n = )" or other custom format

Examples

cohorts <- trial_data %>% cohort_start("Assessed for eligibility") %>% cohort_define( consented = .full %>% dplyr::filter(declined != 1), consented_chemonaive = consented %>% dplyr::filter(prior_chemo != 1) ) %>% cohort_label( consented = "Consented", consented_chemonaive = "Chemotherapy naive" ) cohorts %>% cohort_count()
#> # A tibble: 3 × 3 #> cohort count label #> <chr> <int> <chr> #> 1 .full 1200 Assessed for eligibility #> 2 consented 1141 Consented #> 3 consented_chemonaive 1028 Chemotherapy naive
cohorts %>% cohort_count_adorn()
#> [1] "Assessed for eligibility (n = 1200)" "Consented (n = 1141)" #> [3] "Chemotherapy naive (n = 1028)"
cohorts %>% cohort_count_adorn( starts_with("consented"), .label_fn = function(cohort, label, count, ...) { glue::glue("{count} {label} ({cohort})") } )
#> [1] "1141 Consented (consented)" #> [2] "1028 Chemotherapy naive (consented_chemonaive)"