Skip to contents

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

Usage

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

Arguments

cohort

A cohort table in a cdm reference.

minCohortCount

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

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.

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(5)
#> Warning: There was 1 warning in `dplyr::summarise()`.
#>  In argument: `reason_id = max(.data$reason_id)`.
#> Caused by warning in `max()`:
#> ! no non-missing arguments to max; returning -Inf
#> # Source:   table<main.cohort1> [?? x 4]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.8.0-1017-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          4 1998-12-14        2002-02-14     
#>  2                    1          6 2003-04-11        2004-02-23     
#>  3                    1          7 2004-07-31        2004-11-23     
#>  4                    1          7 2004-11-24        2005-11-05     
#>  5                    1          7 2005-11-06        2012-01-12     
#>  6                    1          8 2009-09-13        2012-04-22     
#>  7                    1          9 2011-12-20        2011-12-20     
#>  8                    1          9 2011-12-21        2011-12-29     
#>  9                    1          9 2011-12-30        2012-04-02     
#> 10                    1         12 2000-11-15        2013-03-04     
#> # ℹ more rows
# }