label_cpt_nonanginal <- c("nonanginal", "unspecified")
label_cpt_atypical <- c("atypical", "Atypical")
label_cpt_typical <- c("typical", "angina")
label_cpt_unknown <- c(NA, NaN)
# Gives harmonise_label_one if there is valid input of chest_pain_type
chest_pain_type <- "unspecified"
harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
)
# Gives harmonise_label_two if there is valid input of chest_pain_type
chest_pain_type <- "Atypical"
harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
)
# Gives harmonise_label_three if there is valid input of chest_pain_type
chest_pain_type <- "angina"
harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
)
# Gives harmonise_label_unknown if there is valid missing input of chest_pain_type
chest_pain_type <- NaN
harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
)
# Gives harmonise_label_unknown if there is valid missing input of chest_pain_type
chest_pain_type <- "NIL"
label_cpt_unknown <- c("NIL")
harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
)
# Gives error of invalid typical chest pain input with partial match
chest_pain_type <- "Typical"
label_cpt_unknown <- c(NA, NaN)
try(harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
))
# Gives error of invalid typical chest pain input without partial match
chest_pain_type <- "Something"
label_cpt_unknown <- c(NA, NaN)
try(harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
))
# Gives error of invalid missing input of chest_pain_type
chest_pain_type <- NA
label_cpt_unknown <- c("NIL")
try(harmonise_three_labels(
arg = chest_pain_type,
label_one = label_cpt_nonanginal,
label_two = label_cpt_atypical,
label_three = label_cpt_typical,
label_unknown = label_cpt_unknown,
harmonise_label_one = "nonanginal",
harmonise_label_two = "atypical",
harmonise_label_three = "typical",
harmonise_label_unknown = NA
))
Run the code above in your browser using DataLab