Skip to contents

Add experimental data to a chronogram

Usage

cg_add_experiment(cg, experiment)

Arguments

cg

a chronogram object (class cg_tbl)

experiment

a tibble::tibble() containing experimental data. The dates and IDs columns in cg must be present in experiment.

Value

A chronogram

Examples

## Example 1: A small study ##-------------------------------------
data(built_smallstudy)

## Setup ##
cg <- built_smallstudy$chronogram

infections_to_add <- tibble::tribble(
  ~calendar_date, ~elig_study_id, ~LFT, ~PCR, ~symptoms,
  "01102020", "1", "pos", NA, NA,
  "11102020", "1", "pos", NA, "severe"
)
## Make calendar_date a date ##
infections_to_add$calendar_date <- lubridate::dmy(
  infections_to_add$calendar_date
)
## Add this new experiment data ##
cg_added <- cg_add_experiment(cg, infections_to_add)

## Example 2: Incorrect column names ##----------------------------

## Setup as for Example 1 ##
infections_to_add_renamed <- infections_to_add %>%
dplyr::rename(ID = elig_study_id)

## this fails ##
try(
cg_added_2 <- cg_add_experiment(cg, 
infections_to_add_renamed)
)
#> Error in check_experiment(x = experiment, cg = cg) : 
#>   Invalid experiment: provided ids_column_name is not present

##------------------------------------------------------------------