assign_no_ct()
maps a variable in a raw dataset to a target SDTM variable that has no terminology restrictions.assign_ct()
maps a variable in a raw dataset to a target SDTM variable following controlled terminology recoding.
Usage
assign_no_ct(
tgt_dat = NULL,
tgt_var,
raw_dat,
raw_var,
id_vars = oak_id_vars()
)
assign_ct(
tgt_dat = NULL,
tgt_var,
raw_dat,
raw_var,
ct_spec,
ct_clst,
id_vars = oak_id_vars()
)
Arguments
- tgt_dat
Target dataset: a data frame to be merged against
raw_dat
by the variables indicated inid_vars
. This parameter is optional, see section Value for how the output changes depending on this argument value.- tgt_var
The target SDTM variable: a single string indicating the name of variable to be derived.
- raw_dat
The raw dataset (dataframe); must include the variables passed in
id_vars
andraw_var
.- raw_var
The raw variable: a single string indicating the name of the raw variable in
raw_dat
.- id_vars
Key variables to be used in the join between the raw dataset (
raw_dat
) and the target data set (raw_dat
).- ct_spec
Study controlled terminology specification: a dataframe with a minimal set of columns, see
ct_spec_vars()
for details.- ct_clst
A codelist code indicating which subset of the controlled terminology to apply in the derivation.
Value
The returned data set depends on the value of tgt_dat
:
If no target dataset is supplied, meaning that
tgt_dat
defaults toNULL
, then the returned data set israw_dat
, selected for the variables indicated inid_vars
, and a new extra column: the derived variable, as indicated intgt_var
.If the target dataset is provided, then it is merged with the raw data set
raw_dat
by the variables indicated inid_vars
, with a new column: the derived variable, as indicated intgt_var
.
Examples
md1 <-
tibble::tibble(
oak_id = 1:14,
raw_source = "MD1",
patient_number = 101:114,
MDIND = c(
"NAUSEA", "NAUSEA", "ANEMIA", "NAUSEA", "PYREXIA",
"VOMITINGS", "DIARHHEA", "COLD",
"FEVER", "LEG PAIN", "FEVER", "COLD", "COLD", "PAIN"
)
)
assign_no_ct(
tgt_var = "CMINDC",
raw_dat = md1,
raw_var = "MDIND"
)
#> # A tibble: 14 × 4
#> oak_id raw_source patient_number CMINDC
#> <int> <chr> <int> <chr>
#> 1 1 MD1 101 NAUSEA
#> 2 2 MD1 102 NAUSEA
#> 3 3 MD1 103 ANEMIA
#> 4 4 MD1 104 NAUSEA
#> 5 5 MD1 105 PYREXIA
#> 6 6 MD1 106 VOMITINGS
#> 7 7 MD1 107 DIARHHEA
#> 8 8 MD1 108 COLD
#> 9 9 MD1 109 FEVER
#> 10 10 MD1 110 LEG PAIN
#> 11 11 MD1 111 FEVER
#> 12 12 MD1 112 COLD
#> 13 13 MD1 113 COLD
#> 14 14 MD1 114 PAIN
cm_inter <-
tibble::tibble(
oak_id = 1:14,
raw_source = "MD1",
patient_number = 101:114,
CMTRT = c(
"BABY ASPIRIN",
"CORTISPORIN",
"ASPIRIN",
"DIPHENHYDRAMINE HCL",
"PARCETEMOL",
"VOMIKIND",
"ZENFLOX OZ",
"AMITRYPTYLINE",
"BENADRYL",
"DIPHENHYDRAMINE HYDROCHLORIDE",
"TETRACYCLINE",
"BENADRYL",
"SOMINEX",
"ZQUILL"
),
CMROUTE = c(
"ORAL",
"ORAL",
NA,
"ORAL",
"ORAL",
"ORAL",
"INTRAMUSCULAR",
"INTRA-ARTERIAL",
NA,
"NON-STANDARD",
"RANDOM_VALUE",
"INTRA-ARTICULAR",
"TRANSDERMAL",
"OPHTHALMIC"
)
)
# Controlled terminology specification
(ct_spec <- read_ct_spec_example("ct-01-cm"))
#> # A tibble: 33 × 8
#> codelist_code term_code CodedData term_value collected_value
#> <chr> <chr> <chr> <chr> <chr>
#> 1 C71113 C25473 QD QD QD (Every Day)
#> 2 C71113 C64496 BID BID BID (Twice a Day)
#> 3 C71113 C64499 PRN PRN PRN (As Needed)
#> 4 C71113 C64516 Q2H Q2H Q2H (Every 2 Hours)
#> 5 C71113 C64530 QID QID QID (4 Times a Day)
#> 6 C66726 C25158 CAPSULE CAPSULE Capsule
#> 7 C66726 C25394 PILL PILL Pill
#> 8 C66726 C29167 LOTION LOTION Lotion
#> 9 C66726 C42887 AEROSOL AEROSOL Aerosol
#> 10 C66726 C42944 INHALANT INHALANT Inhalant
#> # ℹ 23 more rows
#> # ℹ 3 more variables: term_preferred_term <chr>, term_synonyms <chr>,
#> # raw_codelist <chr>
assign_ct(
tgt_dat = cm_inter,
tgt_var = "CMINDC",
raw_dat = md1,
raw_var = "MDIND",
ct_spec = ct_spec,
ct_clst = "C66729"
)
#> # A tibble: 14 × 6
#> oak_id raw_source patient_number CMTRT CMROUTE CMINDC
#> <int> <chr> <int> <chr> <chr> <chr>
#> 1 1 MD1 101 BABY ASPIRIN ORAL NAUSEA
#> 2 2 MD1 102 CORTISPORIN ORAL NAUSEA
#> 3 3 MD1 103 ASPIRIN NA ANEMIA
#> 4 4 MD1 104 DIPHENHYDRAMINE HCL ORAL NAUSEA
#> 5 5 MD1 105 PARCETEMOL ORAL PYREX…
#> 6 6 MD1 106 VOMIKIND ORAL VOMIT…
#> 7 7 MD1 107 ZENFLOX OZ INTRAM… DIARH…
#> 8 8 MD1 108 AMITRYPTYLINE INTRA-… COLD
#> 9 9 MD1 109 BENADRYL NA FEVER
#> 10 10 MD1 110 DIPHENHYDRAMINE HYDROCHLORIDE NON-ST… LEG P…
#> 11 11 MD1 111 TETRACYCLINE RANDOM… FEVER
#> 12 12 MD1 112 BENADRYL INTRA-… COLD
#> 13 13 MD1 113 SOMINEX TRANSD… COLD
#> 14 14 MD1 114 ZQUILL OPHTHA… PAIN