Skip to contents

requireMinCohortCount() filters an existing cohort table, keeping only records from cohorts with a minimum number of individuals

Usage

requireMinCohortCount(
  cohort,
  cohortId = NULL,
  minCohortCount = 5,
  name = tableName(cohort)
)

Arguments

cohort

A cohort table in a cdm reference.

cohortId

Vector identifying which cohorts to modify (cohort_definition_id or cohort_name). If NULL, all cohorts will be used; otherwise, only the specified cohorts will be modified, and the rest will remain unchanged.

minCohortCount

The minimum count of sbjects for a cohort to be included.

name

Name of the new cohort table created in the cdm object.

Value

Cohort table

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(nPerson = 100)

cdm$cohort1 |>
requireMinCohortCount(minCohortCount = 5)
#> # Source:   table<main.cohort1> [?? x 4]
#> # Database: DuckDB v1.0.0 [unknown@Linux 6.5.0-1025-azure:R 4.4.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          1 2001-02-15        2001-10-28     
#>  2                    1          1 2001-10-29        2003-03-15     
#>  3                    1          1 2003-03-16        2005-02-08     
#>  4                    1          2 1999-11-11        2002-04-09     
#>  5                    1          6 2011-03-07        2014-01-24     
#>  6                    1          7 2014-03-08        2014-03-19     
#>  7                    1         10 2019-12-04        2019-12-14     
#>  8                    1         13 2014-06-24        2014-06-29     
#>  9                    1         13 2014-06-30        2014-08-07     
#> 10                    1         14 1986-11-29        1987-12-14     
#> # ℹ more rows
# }