library(dplyr)
# Derive a flag indicating anti-cancer treatment based on CM and PR
adsl <- tribble(
~USUBJID,
"1",
"2",
"3",
"4"
)
cm <- tribble(
~USUBJID, ~CMCAT, ~CMSEQ,
"1", "ANTI-CANCER", 1,
"1", "GENERAL", 2,
"2", "GENERAL", 1,
"3", "ANTI-CANCER", 1
)
# Assuming all records in PR indicate cancer treatment
pr <- tibble::tribble(
~USUBJID, ~PRSEQ,
"2", 1,
"3", 1
)
derive_var_merged_ef_msrc(
adsl,
by_vars = exprs(USUBJID),
flag_events = list(
flag_event(
dataset_name = "cm",
condition = CMCAT == "ANTI-CANCER"
),
flag_event(
dataset_name = "pr"
)
),
source_datasets = list(cm = cm, pr = pr),
new_var = CANCTRFL
)
# Using different by variables depending on the source
# Add a dose adjustment flag to ADEX based on ADEX, EC, and FA
adex <- tribble(
~USUBJID, ~EXLNKID, ~EXADJ,
"1", "1", "AE",
"1", "2", NA_character_,
"1", "3", NA_character_,
"2", "1", NA_character_,
"3", "1", NA_character_
)
ec <- tribble(
~USUBJID, ~ECLNKID, ~ECADJ,
"1", "3", "AE",
"3", "1", NA_character_
)
fa <- tribble(
~USUBJID, ~FALNKID, ~FATESTCD, ~FAOBJ, ~FASTRESC,
"3", "1", "OCCUR", "DOSE ADJUSTMENT", "Y"
)
derive_var_merged_ef_msrc(
adex,
by_vars = exprs(USUBJID, EXLNKID),
flag_events = list(
flag_event(
dataset_name = "ex",
condition = !is.na(EXADJ)
),
flag_event(
dataset_name = "ec",
condition = !is.na(ECADJ),
by_vars = exprs(USUBJID, EXLNKID = ECLNKID)
),
flag_event(
dataset_name = "fa",
condition = FATESTCD == "OCCUR" & FAOBJ == "DOSE ADJUSTMENT" & FASTRESC == "Y",
by_vars = exprs(USUBJID, EXLNKID = FALNKID)
)
),
source_datasets = list(ex = adex, ec = ec, fa = fa),
new_var = DOSADJFL
)
Run the code above in your browser using DataLab