Skip to contents

Same as addAge(), except query is not computed to a table.

Usage

addAgeQuery(
  x,
  indexDate = "cohort_start_date",
  ageName = "age",
  ageGroup = NULL,
  ageMissingMonth = 1,
  ageMissingDay = 1,
  ageImposeMonth = FALSE,
  ageImposeDay = FALSE,
  ageUnit = "years",
  missingAgeGroupValue = "None",
  type = "numeric"
)

Arguments

x

A table containing individuals in a CDM reference.

indexDate

Name of a date column in x, or a single date to use for all rows, used as the reference date.

ageName

Name of the age column to add.

ageGroup

If not NULL, a list of age-group vectors.

ageMissingMonth

Month of the year assigned when month of birth is missing.

ageMissingDay

Day of the month assigned when day of birth is missing.

ageImposeMonth

If TRUE, month of birth is treated as missing for all individuals.

ageImposeDay

If TRUE, day of birth is treated as missing for all individuals.

ageUnit

Unit in which to express age: "years", "months", or "days".

missingAgeGroupValue

Value to use when age is missing.

type

Type of the created column(s). Counts, days, age, and observation durations can be "numeric" or "integer". Flag columns can also be "logical". Field columns can use "auto" to preserve the source type, or can be converted to "numeric", "integer", "logical", or "character".

Value

tibble with the age column added.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addAgeQuery()
#> # A query:  ?? x 5
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date   age
#>                   <int>      <int> <date>            <date>          <dbl>
#>  1                    1          5 1968-09-17        1977-08-13         13
#>  2                    1          2 1981-06-05        1998-12-01         15
#>  3                    1          7 1939-07-04        1939-07-16         20
#>  4                    2          8 1958-09-30        1961-03-16         30
#>  5                    1          9 1948-03-06        1982-10-18          2
#>  6                    2          1 1948-06-29        1951-01-05          2
#>  7                    2          4 1983-01-13        1986-03-03         12
#>  8                    1          6 1949-09-11        1964-09-19          5
#>  9                    1          3 1948-07-14        1948-07-23         15
#> 10                    1         10 1957-09-01        1958-07-10         18

# }