Require that an index date is within a date range
requireInDateRange.Rd
requireInDateRange()
filters cohort records, keeping only those for
which the index date is within the specified date range.
Usage
requireInDateRange(
cohort,
dateRange,
cohortId = NULL,
indexDate = "cohort_start_date",
name = tableName(cohort)
)
Arguments
- cohort
A cohort table in a cdm reference.
- dateRange
A date vector with the minimum and maximum dates between which the index date must have been observed.
- 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.
- indexDate
Name of the column in the cohort that contains the date of interest.
- name
Name of the new cohort table created in the cdm object.
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor(nPerson = 100)
cdm$cohort1 |>
requireInDateRange(indexDate = "cohort_start_date",
dateRange = as.Date(c("2010-01-01", "2019-01-01")))
#> # 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 6 2011-03-07 2014-01-24
#> 2 1 7 2014-03-08 2014-03-19
#> 3 1 13 2014-06-24 2014-06-29
#> 4 1 13 2014-06-30 2014-08-07
#> 5 1 17 2017-03-28 2017-04-05
#> 6 1 18 2012-01-30 2012-05-21
#> 7 1 24 2016-11-15 2016-11-22
#> 8 1 24 2016-11-23 2016-11-29
#> 9 1 24 2016-11-30 2017-01-25
#> 10 1 31 2013-03-29 2014-02-09
#> # ℹ more rows
# }