Use this function on e.g. clinical texts from health care records. It returns a list with all antimicrobial drugs found in the texts.
ab_from_text(text, collapse = NULL, translate_ab = FALSE, ...)
| text | text to analyse |
|---|---|
| collapse | character to pass on to |
| translate_ab | a column name of the antibiotics data set to translate the antibiotic abbreviations to, using |
| ... | parameters passed on to |
A list, or a character if collapse is not NULL
Without using collapse, this function will return a list. This can be convenient to use e.g. inside a mutate()):
df %>% mutate(abx = ab_from_text(clinical_text))
The returned AB codes can be transformed to official names, groups, etc. with all ab_property() functions like ab_name() and ab_group(), or by using the translate_ab parameter.
With using collapse, this function will return a character:
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 and will throw a note if more results could have been returned.
# 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[[1]]) if (require(dplyr)) { tibble(clinical_text = c("given cipro and mero", "started on doxy today")) %>% mutate(abx = ab_from_text(clinical_text), abx2 = ab_from_text(clinical_text, collapse = "|"), abx3 = ab_from_text(clinical_text, collapse = "|", translate_ab = "name")) }