Require that an index date is within a date range
Source:R/requireDateRange.R
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.1.2 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 9 2011-12-20 2011-12-20
#> 2 1 9 2011-12-21 2011-12-29
#> 3 1 9 2011-12-30 2012-04-02
#> 4 1 15 2018-03-20 2018-04-01
#> 5 1 22 2013-01-01 2013-03-07
#> 6 1 25 2018-01-10 2018-03-13
#> 7 1 25 2018-03-14 2018-03-22
#> 8 1 25 2018-03-23 2018-06-26
#> 9 1 25 2018-06-27 2018-11-13
#> 10 1 31 2012-09-03 2013-02-18
#> # ℹ more rows
# }