Calculate and assign flags based on infection history
cg_annotate_episodes_count.Rd
Count the total number of infections for each individual at the end
of the study (or at that data freeze), and make it available as a
fresh column. cg_annotate_episodes_count()
should be run after
cg_annotate_episodes_find()
. For the cumulative number of
infections use cg_annotate_episodes_find()
only.
Examples
library(dplyr)
data("built_smallstudy")
cg <- built_smallstudy$chronogram
## add infections to chronogram
cg <- cg_add_experiment(
cg,
built_smallstudy$infections_to_add
)
## annotate infections
cg <- cg_annotate_episodes_find(
cg,
infection_cols = c("LFT", "PCR", "symptoms"),
infection_present = c("pos", "Post", "^severe")
)
#> Parsed: infection_cols and infection_present
#>
#> Searching in the [[column]], for the "text":
#>
#> stringr::str_detect(.data[["LFT"]], "pos") ~ "yes"
#>
#> stringr::str_detect(.data[["PCR"]], "Post") ~ "yes"
#>
#> stringr::str_detect(.data[["symptoms"]], "^severe") ~ "yes"
#>
#>
#> ...detecting will be exact.
#> Capitals, spelling etc must be precise
#>
#> Joining with `by = join_by(calendar_date, elig_study_id)`
## count infections
cg <- cg_annotate_episodes_count(
cg)
## pull number of infections each individual has during study ##
cg %>%
dplyr::group_by(elig_study_id) %>%
dplyr::slice_head() %>%
dplyr::select(elig_study_id, count_col)
#> # A tibble: 3 × 2
#> # Groups: elig_study_id [3]
#> elig_study_id count_col
#> <fct> <dbl>
#> 1 1 1
#> 2 2 2
#> 3 3 0