subsetCohorts()
filters an existing cohort table, keeping only the records
from cohorts that are specified.
Usage
subsetCohorts(
cohort,
cohortId,
name = tableName(cohort),
.softValidation = TRUE
)
Arguments
- cohort
A cohort table in a cdm reference.
- cohortId
Vector identifying which cohorts to include (cohort_definition_id or cohort_name). Cohorts not included will be removed from the cohort set.
- name
Name of the new cohort table created in the cdm object.
- .softValidation
Whether to perform a soft validation of consistency. If set to FALSE four additional checks will be performed: 1) a check that cohort end date is not before cohort start date, 2) a check that there are no missing values in required columns, 3) a check that cohort duration is all within observation period, and 4) that there are no overlapping cohort entries
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor(nPerson = 100)
cdm$cohort1 |> subsetCohorts(cohortId = 1)
#> # Source: table<cohort1> [?? x 4]
#> # Database: DuckDB v1.3.1 [unknown@Linux 6.11.0-1015-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 4 2019-06-09 2019-08-31
#> 2 1 6 1983-03-10 1996-03-21
#> 3 1 7 2013-03-03 2014-09-18
#> 4 1 7 2014-09-19 2014-12-14
#> 5 1 7 2015-04-04 2018-01-18
#> 6 1 8 2013-12-19 2016-08-09
#> 7 1 9 2005-11-05 2005-11-06
#> 8 1 9 2005-11-07 2006-07-18
#> 9 1 9 2006-07-19 2010-07-28
#> 10 1 12 2003-02-09 2007-02-05
#> # ℹ more rows
# }