
Add the maximum number of ingredients to which an individual is simultaneously exposed within a specified window
Source:R/polypharmacy.R
addPolypharmacyCount.RdAdd the maximum number of ingredients to which an individual is simultaneously exposed within a specified window
Arguments
- x
A
cdm_tablecontaining a person identifier column namedperson_idorsubject_id.- indexDate
A character string naming the
Datecolumn inxthat defines the index date.- window
A numeric vector of length two,
c(min, max), defining the window forpolypharmacyin days relative toindexDate. Use-InforInffor an unbounded lower or upper limit.- overlap
Logical; if
TRUE, count drug eras that overlap in time. IfFALSE, count drug eras that occur within the window without requiring them to overlap one another.- nameStyle
A character string specifying the name of the new column.
- name
A character string specifying the name of the output table. If
NULL, a temporary table is created.
Value
The table x with a new column containing the maximum number of
simultaneous ingredients in the window of interest.
Examples
# \donttest{
library(omock)
library(duckdb)
library(OmopIndices)
library(dplyr)
library(CohortConstructor)
cdm <- mockCdmFromDataset(datasetName = "GiBleed", source = "duckdb")
#> ℹ Loading bundled GiBleed tables from package data.
#> ℹ Adding drug_strength table.
#> ℹ Creating local <cdm_reference> object.
#> ℹ Inserting <cdm_reference> into duckdb.
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmplwnqmn/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
cdm$cohort <- conceptCohort(
cdm = cdm,
conceptSet = list(sinusitis = c(257012L, 4283893L, 4294548L, 40481087L)),
name = "cohort"
)
#> ℹ Subsetting table condition_occurrence using 4 concepts with domain:
#> condition.
#> ℹ Combining tables.
#> ℹ Creating cohort attributes.
#> ℹ Applying cohort requirements.
#> ℹ Merging overlapping records.
#> ✔ Cohort cohort created.
cdm$cohort |>
addPolypharmacyCount(window = c(-30, 0)) |>
select(subject_id, cohort_start_date, polypharmacy_count) |>
glimpse()
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 102, 140, 539, 1516, 2191, 2450, 2917, 3010, 3250, …
#> $ cohort_start_date <date> 1989-07-03, 1994-05-10, 1976-11-12, 1948-10-05, 19…
#> $ polypharmacy_count <int> 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, …
# }