
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",
atFirst = FALSE,
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.
- atFirst
If FALSE the requirement will be applied to all records, if TRUE, it will only be required for the first entry of each subject.
- name
Name of the new cohort table created in the cdm object.
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor()
cdm$cohort1 |>
requireInDateRange(indexDate = "cohort_start_date",
dateRange = as.Date(c("2010-01-01", "2019-01-01")))
#> # A tibble: 19 × 4
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> * <int> <int> <date> <date>
#> 1 1 2 2016-07-24 2017-09-16
#> 2 1 3 2013-04-07 2013-06-13
#> 3 1 6 2018-04-23 2018-05-05
#> 4 1 11 2012-08-08 2012-08-17
#> 5 1 17 2012-04-11 2012-08-22
#> 6 1 22 2015-12-07 2018-03-02
#> 7 1 24 2016-08-19 2017-03-28
#> 8 1 27 2017-07-11 2018-08-27
#> 9 1 42 2016-05-04 2016-08-11
#> 10 1 44 2010-08-10 2010-12-04
#> 11 1 46 2016-12-05 2016-12-21
#> 12 1 55 2010-09-28 2010-10-09
#> 13 1 56 2015-07-11 2016-04-17
#> 14 1 60 2016-10-08 2017-08-04
#> 15 1 61 2014-01-03 2014-06-09
#> 16 1 65 2013-07-06 2013-07-19
#> 17 1 75 2013-04-29 2013-10-20
#> 18 1 78 2014-04-07 2015-03-10
#> 19 1 81 2011-07-31 2015-07-17
# }