Skip to contents

Pick a window of dates from a chronogram: with respect to episode start.

Usage

cg_window_by_episode(
  cg,
  episode_numbers_col = episode_number,
  episode_handling = c("first", "last", "all"),
  preceding_days,
  following_days
)

Arguments

cg

a chronogram

episode_numbers_col

The column name to use for episode numbers. Default is episode_number.

episode_handling

which episode to reference. Must be one of "first", "last", or "all".

preceding_days

used as filter( date > (date_col - preceding_days) )

following_days

used as filter( date < (date_col + following_days) )

Value

A windowed chronogram

Examples


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)`

SevenDaysAfterFirstEpisode <- cg_window_by_episode(
  cg,
  episode_numbers_col = episode_number, 
  preceding_days = 0, 
  following_days = 7,
  episode_handling = "first"
)