Use this function on e.g. clinical texts from health care records. It returns a vector of antimicrobial drugs found in the texts.

ab_from_text(text, collapse = NULL, translate_ab = "name", ...)

Arguments

text

text to analyse

collapse

character to pass on to paste(..., collapse = ...) to only return one character per element of text, see Examples

translate_ab

a column name of the antibiotics data set to translate the antibiotic abbreviations to, using ab_property(). Defaults to "name", which is equal to using TRUE. Use a value FALSE, NULL or NA to prevent translation of the <ab> code.

...

parameters passed on to as.ab()

Details

To use this for creating a new variable in a data set (e.g. with mutate()), it could be convenient to paste the outcome together with the collapse parameter so every value in your new variable will be a character of length 1:
df %>% mutate(abx = ab_from_text(clinical_text, collapse = "|"))

This function is also internally used by as.ab(), although it then only returns the first hit.

Examples

# mind the bad spelling of amoxicillin in this line, 
# straight from a true health care record:
ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds")

ab_from_text("administered amoxi/clav and cipro")
ab_from_text("administered amoxi/clav and cipro", collapse = ", ")

# if you want to know which antibiotic groups were administered, check it:
abx <- ab_from_text("administered amoxi/clav and cipro")
ab_group(abx)