Skip to contents

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.

Usage

cg_annotate_episodes_count(
  cg,
  episode_number = episode_number,
  count_col = count_col
)

Arguments

cg

a chronogram

episode_number

a character vector to use to label the ID column. Default is "episode_number".

count_col

column with infection count

Value

A subsetted chronogram

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