Skip to contents

Coerces a data frame of casualties into a cohort, a tibble::tibble() subclass carrying the column contract shared by sdt_patient_card() and sdt_scenario(). Validation is vectorised: every column is checked in one pass and all offending rows are reported, rather than aborting on the first bad one.

Usage

sdt_cohort(data, ...)

Arguments

data

A data frame with the columns produced by sdt_patient_card(): id, age, sex, life_points, ventilated, injury_region, triage, therapy, arrival_order. Extra columns are kept and carried through untouched.

...

These dots are for future extensions and must be empty.

Value

A cohort object: a tibble subclass with the contract columns first, ordered by arrival_order. A zero-row input yields a zero-row cohort with the correct column types.

See also

validate_cohort() to check an existing cohort, sdt_as_patient_cards() to explode one into cards.

Examples

co <- sdt_cohort(sdt_synthetic_cohort(n = 5, seed = 1))
co
#> # A cohort: 5 casualties
#> # Triage:   red: 3 yellow: 1 green: 1
#>   id      age sex   life_points ventilated injury_region triage therapy
#>   <chr> <int> <chr>       <int> <lgl>      <chr>         <chr>  <chr>  
#> 1 P001     42 m               1 TRUE       head          red    TASC   
#> 2 P002     78 m               1 TRUE       extremity     red    TASC   
#> 3 P003     53 m               5 FALSE      abdomen       green  none   
#> 4 P004     30 f               4 FALSE      thorax        yellow TASC   
#> 5 P005     25 m               2 FALSE      thorax        red    DCS    
#> # ℹ 1 more variable: arrival_order <int>

# Every bad row is named at once, not just the first.
bad <- sdt_synthetic_cohort(n = 4, seed = 1)
bad$triage[c(2, 4)] <- "purple"
try(sdt_cohort(bad))
#> Error in sdt_cohort(bad) : `x` is not a valid cohort.
#> ✖ triage: must be one of "red", "yellow", and "green" in row 2 and 4.