convert_med: Adds boolean columns corresponding to a group of medications...

View source: R/convert_med.R

convert_medR Documentation

Adds boolean columns corresponding to a group of medications whether it is present in the given row.

Description

Analyzes medication data loaded using load_med. By default, the data.table is returned with new columns corresponding to boolean values, whether given group of medications are present. If collapse is given, then the information is aggregated based-on the collapse column and the earliest of latest time of the given medication is provided.

Usage

convert_med(
  d,
  code = "med",
  codes_to_find = NULL,
  collapse = NULL,
  code_time = "time_med",
  aggr_type = "earliest",
  nThread = parallel::detectCores() - 1
)

Arguments

d

data.table, database containing medication data loaded using the load_med function.

code

string, column name of the medication column. Defaults to med.

codes_to_find

list, a list of arrays corresponding to sets of medication names. New boolean columns with the name of each list element will be created. These columns are indicators whether the given medication is present in the set of medication names or not.

collapse

string, a column name on which to collapse the data.table. Used in case we wish to assess whether given medications are present within all the same instances of collapse. See vignette for details.

code_time

string, column name of the time column. Defaults to time_med. Used in case collapse is present to provide the earliest or latest instance of diagnosing the given disease.

aggr_type

string, if multiple occurences of the medications are present within the same case of collapse, which timepoint to return. Supported are: "earliest" or "latest". Defaults to earliest.

nThread

integer, number of threads to use for parallelization. If it is set to 1, then no parallel backends are created and the function is executed sequentially.

Value

data.table, with indicator columns whether given group of codes_to_find is present or not. If collapse is present, then only unique ID and the summary columns are returned.

Examples

## Not run: 
#Define medication group and add an indicator column whether
#the given medication group was administered
meds <- list(statin = c("Simvastatin", "Atorvastatin"),
             NSAID  = c("Acetaminophen", "Paracetamol"))

data_med_indic <- convert_med(d = data_med, codes_to_find = meds, nThread = 1)

#Summarize per patient if they ever had the given medication groups registered
data_med_indic_any <- convert_med(d = data_med,
codes_to_find = meds, collapse = "ID_MERGE", nThread = 2)

## End(Not run)

parseRPDR documentation built on March 31, 2023, 11:36 p.m.