1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 19:26:13 +01:00

(v1.2.0.9014) ab_from_text()

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-06-25 17:34:50 +02:00
parent 8a66e475d7
commit 344bbd57f4
32 changed files with 749 additions and 191 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.2.0.9013 Version: 1.2.0.9014
Date: 2020-06-22 Date: 2020-06-25
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(
person(role = c("aut", "cre"), person(role = c("aut", "cre"),

12
NEWS.md
View File

@ -1,7 +1,12 @@
# AMR 1.2.0.9013 # AMR 1.2.0.9014
## <small>Last updated: 22-Jun-2020</small> ## <small>Last updated: 25-Jun-2020</small>
### New ### New
* Function `ab_from_text()` to retrieve antimicrobial drugs from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally:
```r
ab_from_text("28/03/2020 regular amoxiciliin 500mg po tds")
#> [1] "Amoxicillin"
```
* [Tidyverse selections](https://tidyselect.r-lib.org/reference/language.html) for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like `dplyr::select()` and `tidyr::pivot_longer()`: * [Tidyverse selections](https://tidyselect.r-lib.org/reference/language.html) for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like `dplyr::select()` and `tidyr::pivot_longer()`:
```r ```r
library(dplyr) library(dplyr)
@ -26,6 +31,7 @@
* Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set * Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set
### Changed ### Changed
* Fixed a bug for using `susceptibility` or `resistance()` outside `summarise()`
* Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded * Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded
* All `*_join_microorganisms()` functions and `bug_drug_combinations()` now return the original data class (e.g. `tibble`s and `data.table`s) * All `*_join_microorganisms()` functions and `bug_drug_combinations()` now return the original data class (e.g. `tibble`s and `data.table`s)
* Fixed a bug where `as.ab()` would return an error on invalid input values * Fixed a bug where `as.ab()` would return an error on invalid input values
@ -34,6 +40,8 @@
* Fixed a bug in `bug_drug_combinations()` for when only one antibiotic was in the input data * Fixed a bug in `bug_drug_combinations()` for when only one antibiotic was in the input data
* Changed the summary for class `<mo>`, to highlight the %SI vs. %R * Changed the summary for class `<mo>`, to highlight the %SI vs. %R
* Improved error handling, giving more useful info when functions return an error * Improved error handling, giving more useful info when functions return an error
* Algorithm improvements to `as.ab()`
* Added Monuril as trade name for fosfomycin
# AMR 1.2.0 # AMR 1.2.0

286
R/ab.R
View File

@ -30,6 +30,7 @@
#' @details All entries in the [antibiotics] data set have three different identifiers: a human readable EARS-Net code (column `ab`, used by ECDC and WHONET), an ATC code (column `atc`, used by WHO), and a CID code (column `cid`, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. #' @details All entries in the [antibiotics] data set have three different identifiers: a human readable EARS-Net code (column `ab`, used by ECDC and WHONET), an ATC code (column `atc`, used by WHO), and a CID code (column `cid`, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem.
#' #'
#' Use the [ab_property()] functions to get properties based on the returned antibiotic ID, see Examples. #' Use the [ab_property()] functions to get properties based on the returned antibiotic ID, see Examples.
#'
#' @section Source: #' @section Source:
#' World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/} #' World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
#' #'
@ -38,7 +39,9 @@
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm} #' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
#' @aliases ab #' @aliases ab
#' @return Character (vector) with class [`ab`]. Unknown values will return `NA`. #' @return Character (vector) with class [`ab`]. Unknown values will return `NA`.
#' @seealso [antibiotics] for the dataframe that is being used to determine ATCs. #' @seealso
#' * [antibiotics] for the dataframe that is being used to determine ATCs
#' * [ab_from_text()] for a function to retrieve antimicrobial drugs from clinical text (from health care records)
#' @inheritSection AMR Read more on our website! #' @inheritSection AMR Read more on our website!
#' @export #' @export
#' @examples #' @examples
@ -72,6 +75,9 @@ as.ab <- function(x, ...) {
return(x) return(x)
} }
initial <- is.null(list(...)$initial)
already_regex <- isTRUE(list(...)$already_regex)
if (all(toupper(x) %in% antibiotics$ab)) { if (all(toupper(x) %in% antibiotics$ab)) {
# valid AB code, but not yet right class # valid AB code, but not yet right class
return(structure(.Data = toupper(x), return(structure(.Data = toupper(x),
@ -79,26 +85,30 @@ as.ab <- function(x, ...) {
} }
x_bak <- x x_bak <- x
x <- toupper(x)
# remove diacritics # remove diacritics
x <- iconv(x, from = "UTF-8", to = "ASCII//TRANSLIT") x <- iconv(x, from = "UTF-8", to = "ASCII//TRANSLIT")
x <- gsub('"', "", x, fixed = TRUE) x <- gsub('"', "", x, fixed = TRUE)
# remove suffices x_bak_clean <- x
x_bak_clean <- gsub("_(mic|rsi|dis[ck])$", "", x, ignore.case = TRUE) if (already_regex == FALSE) {
# remove disk concentrations, like LVX_NM -> LVX # remove suffices
x_bak_clean <- gsub("_[A-Z]{2}[0-9_.]{0,3}$", "", x_bak_clean, ignore.case = TRUE) x_bak_clean <- gsub("_(MIC|RSI|DIS[CK])$", "", x_bak_clean)
# remove part between brackets if that's followed by another string # remove disk concentrations, like LVX_NM -> LVX
x_bak_clean <- gsub("(.*)+ [(].*[)]", "\\1", x_bak_clean) x_bak_clean <- gsub("_[A-Z]{2}[0-9_.]{0,3}$", "", x_bak_clean)
# keep only max 1 space # remove part between brackets if that's followed by another string
x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean, ignore.case = TRUE)) x_bak_clean <- gsub("(.*)+ [(].*[)]", "\\1", x_bak_clean)
# non-character, space or number should be a slash # keep only max 1 space
x_bak_clean <- gsub("[^A-Za-z0-9 -]", "/", x_bak_clean) x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean))
# spaces around non-characters must be removed: amox + clav -> amox/clav # non-character, space or number should be a slash
x_bak_clean <- gsub("(.*[a-zA-Z0-9]) ([^a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) x_bak_clean <- gsub("[^A-Z0-9 -]", "/", x_bak_clean)
x_bak_clean <- gsub("(.*[^a-zA-Z0-9]) ([a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) # spaces around non-characters must be removed: amox + clav -> amox/clav
# remove hyphen after a starting "co" x_bak_clean <- gsub("(.*[A-Z0-9]) ([^A-Z0-9].*)", "\\1\\2", x_bak_clean)
x_bak_clean <- gsub("^co-", "co", x_bak_clean, ignore.case = TRUE) x_bak_clean <- gsub("(.*[^A-Z0-9]) ([A-Z0-9].*)", "\\1\\2", x_bak_clean)
# replace text 'and' with a slash # remove hyphen after a starting "co"
x_bak_clean <- gsub(" and ", "/", x_bak_clean, ignore.case = TRUE) x_bak_clean <- gsub("^CO-", "CO", x_bak_clean)
# replace text 'and' with a slash
x_bak_clean <- gsub(" AND ", "/", x_bak_clean)
}
x <- unique(x_bak_clean) x <- unique(x_bak_clean)
x_new <- rep(NA_character_, length(x)) x_new <- rep(NA_character_, length(x))
@ -118,14 +128,14 @@ as.ab <- function(x, ...) {
} }
# exact AB code # exact AB code
found <- antibiotics[which(antibiotics$ab == toupper(x[i])), ]$ab found <- antibiotics[which(antibiotics$ab == x[i]), ]$ab
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
} }
# exact ATC code # exact ATC code
found <- antibiotics[which(antibiotics$atc == toupper(x[i])), ]$ab found <- antibiotics[which(antibiotics$atc == x[i]), ]$ab
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
@ -139,7 +149,7 @@ as.ab <- function(x, ...) {
} }
# exact name # exact name
found <- antibiotics[which(toupper(antibiotics$name) == toupper(x[i])), ]$ab found <- antibiotics[which(toupper(antibiotics$name) == x[i]), ]$ab
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
@ -147,11 +157,7 @@ as.ab <- function(x, ...) {
# exact LOINC code # exact LOINC code
loinc_found <- unlist(lapply(antibiotics$loinc, loinc_found <- unlist(lapply(antibiotics$loinc,
function(s) if (x[i] %in% s) { function(s) x[i] %in% s))
TRUE
} else {
FALSE
}))
found <- antibiotics$ab[loinc_found == TRUE] found <- antibiotics$ab[loinc_found == TRUE]
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
@ -160,11 +166,7 @@ as.ab <- function(x, ...) {
# exact synonym # exact synonym
synonym_found <- unlist(lapply(antibiotics$synonyms, synonym_found <- unlist(lapply(antibiotics$synonyms,
function(s) if (toupper(x[i]) %in% toupper(s)) { function(s) x[i] %in% toupper(s)))
TRUE
} else {
FALSE
}))
found <- antibiotics$ab[synonym_found == TRUE] found <- antibiotics$ab[synonym_found == TRUE]
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
@ -173,90 +175,87 @@ as.ab <- function(x, ...) {
# exact abbreviation # exact abbreviation
abbr_found <- unlist(lapply(antibiotics$abbreviations, abbr_found <- unlist(lapply(antibiotics$abbreviations,
function(a) if (toupper(x[i]) %in% toupper(a)) { function(a) x[i] %in% toupper(a)))
TRUE
} else {
FALSE
}))
found <- antibiotics$ab[abbr_found == TRUE] found <- antibiotics$ab[abbr_found == TRUE]
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
} }
# first >=4 characters of name
if (nchar(x[i]) >= 4) {
found <- antibiotics[which(toupper(antibiotics$name) %like% paste0("^", x[i])), ]$ab
if (length(found) > 0) {
x_new[i] <- found[1L]
next
}
}
# allow characters that resemble others, but only continue when having more than 3 characters # allow characters that resemble others, but only continue when having more than 3 characters
if (nchar(x[i]) <= 3) { if (nchar(x[i]) <= 3) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1]) x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
next next
} }
x_spelling <- tolower(x[i]) x_spelling <- x[i]
x_spelling <- gsub("[iy]+", "[iy]+", x_spelling) if (already_regex == FALSE) {
x_spelling <- gsub("(c|k|q|qu|s|z|x|ks)+", "(c|k|q|qu|s|z|x|ks)+", x_spelling) x_spelling <- gsub("[IY]+", "[IY]+", x_spelling)
x_spelling <- gsub("(ph|f|v)+", "(ph|f|v)+", x_spelling) x_spelling <- gsub("(C|K|Q|QU|S|Z|X|KS)+", "(C|K|Q|QU|S|Z|X|KS)+", x_spelling)
x_spelling <- gsub("(th|t)+", "(th|t)+", x_spelling) x_spelling <- gsub("(PH|F|V)+", "(PH|F|V)+", x_spelling)
x_spelling <- gsub("a+", "a+", x_spelling) x_spelling <- gsub("(TH|T)+", "(TH|T)+", x_spelling)
x_spelling <- gsub("e+", "e+", x_spelling) x_spelling <- gsub("A+", "A+", x_spelling)
x_spelling <- gsub("o+", "o+", x_spelling) x_spelling <- gsub("E+", "E+", x_spelling)
# allow any ending of -in/-ine and -im/-ime x_spelling <- gsub("O+", "O+", x_spelling)
x_spelling <- gsub("(\\[iy\\]\\+(n|m)|\\[iy\\]\\+(n|m)e\\+)$", "[iy]+(n|m)e*", x_spelling) # allow any ending of -in/-ine and -im/-ime
# allow any ending of -ol/-ole x_spelling <- gsub("(\\[IY\\]\\+(N|M)|\\[IY\\]\\+(N|M)E\\+)$", "[IY]+(N|M)E*", x_spelling)
x_spelling <- gsub("(o\\+l|o\\+le\\+)$", "o+le*", x_spelling) # allow any ending of -ol/-ole
# allow any ending of -on/-one x_spelling <- gsub("(O\\+L|O\\+LE\\+)$", "O+LE*", x_spelling)
x_spelling <- gsub("(o\\+n|o\\+ne\\+)$", "o+ne*", x_spelling) # allow any ending of -on/-one
# replace multiple same characters to single one with '+', like "ll" -> "l+" x_spelling <- gsub("(O\\+N|O\\+NE\\+)$", "O+NE*", x_spelling)
x_spelling <- gsub("(.)\\1+", "\\1+", x_spelling) # replace multiple same characters to single one with '+', like "ll" -> "l+"
# replace spaces and slashes with a possibility on both x_spelling <- gsub("(.)\\1+", "\\1+", x_spelling)
x_spelling <- gsub("[ /]", "( .*|.*/)", x_spelling) # replace spaces and slashes with a possibility on both
x_spelling <- gsub("[ /]", "( .*|.*/)", x_spelling)
# correct for digital reading text (OCR)
x_spelling <- gsub("[NRD]", "[NRD]", x_spelling)
}
# try if name starts with it # try if name starts with it
found <- antibiotics[which(antibiotics$name %like% paste0("^", x_spelling)), ]$ab found <- antibiotics[which(antibiotics$name %like% paste0("^", x_spelling)), ]$ab
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
} }
# try if name ends with it
found <- antibiotics[which(antibiotics$name %like% paste0(x_spelling, "$")), ]$ab
if (nchar(x[i]) >= 4 & length(found) > 0) {
x_new[i] <- found[1L]
next
}
# and try if any synonym starts with it # and try if any synonym starts with it
synonym_found <- unlist(lapply(antibiotics$synonyms, synonym_found <- unlist(lapply(antibiotics$synonyms,
function(s) if (any(s %like% paste0("^", x_spelling))) { function(s) any(s %like% paste0("^", x_spelling))))
TRUE
} else {
FALSE
}))
found <- antibiotics$ab[synonym_found == TRUE] found <- antibiotics$ab[synonym_found == TRUE]
if (length(found) > 0) { if (length(found) > 0) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
} }
# try by removing all spaces # INITIAL - More uncertain results ----
if (x[i] %like% " ") {
found <- suppressWarnings(as.ab(gsub(" +", "", x[i]))) if (initial == TRUE) {
if (length(found) > 0 & !is.na(found)) { # only run on first try
x_new[i] <- found[1L]
next # try by removing all spaces
if (x[i] %like% " ") {
found <- suppressWarnings(as.ab(gsub(" +", "", x[i]), initial = FALSE))
if (length(found) > 0 & !is.na(found)) {
x_new[i] <- found[1L]
next
}
} }
}
# try by removing all spaces and numbers
# try by removing all spaces and numbers if (x[i] %like% " " | x[i] %like% "[0-9]") {
if (x[i] %like% " " | x[i] %like% "[0-9]") { found <- suppressWarnings(as.ab(gsub("[ 0-9]", "", x[i]), initial = FALSE))
found <- suppressWarnings(as.ab(gsub("[ 0-9]", "", x[i]))) if (length(found) > 0 & !is.na(found)) {
if (length(found) > 0 & !is.na(found)) { x_new[i] <- found[1L]
x_new[i] <- found[1L] next
next }
} }
}
if (!isFALSE(list(...)$initial_search)) {
# transform back from other languages and try again # transform back from other languages and try again
x_translated <- paste(lapply(strsplit(x[i], "[^a-zA-Z0-9 ]"), x_translated <- paste(lapply(strsplit(x[i], "[^A-Z0-9 ]"),
function(y) { function(y) {
for (i in seq_len(length(y))) { for (i in seq_len(length(y))) {
y[i] <- ifelse(tolower(y[i]) %in% tolower(translations_file$replacement), y[i] <- ifelse(tolower(y[i]) %in% tolower(translations_file$replacement),
@ -267,41 +266,102 @@ as.ab <- function(x, ...) {
y y
})[[1]], })[[1]],
collapse = "/") collapse = "/")
x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) x_translated_guess <- suppressWarnings(as.ab(x_translated, initial = FALSE))
if (!is.na(x_translated_guess)) { if (!is.na(x_translated_guess)) {
x_new[i] <- x_translated_guess x_new[i] <- x_translated_guess
next next
} }
if (!isFALSE(list(...)$initial_search2)) { # now also try to coerce brandname combinations like "Amoxy/clavulanic acid"
# now also try to coerce brandname combinations like "Amoxy/clavulanic acid" x_translated <- paste(lapply(strsplit(x_translated, "[^A-Z0-9 ]"),
x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"), function(y) {
function(y) { for (i in seq_len(length(y))) {
for (i in seq_len(length(y))) { y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial = FALSE))
y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE, initial_search2 = FALSE)) y[i] <- ifelse(!is.na(y_name),
y[i] <- ifelse(!is.na(y_name), y_name,
y_name, y[i])
y[i]) }
} y
y })[[1]],
})[[1]], collapse = "/")
collapse = "/") x_translated_guess <- suppressWarnings(as.ab(x_translated, initial = FALSE))
x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) if (!is.na(x_translated_guess)) {
if (!is.na(x_translated_guess)) { x_new[i] <- x_translated_guess
x_new[i] <- x_translated_guess next
}
# try by removing all trailing capitals
if (x[i] %like_case% "[a-z]+[A-Z]+$") {
found <- suppressWarnings(as.ab(gsub("[A-Z]+$", "", x[i]), initial = FALSE))
if (!is.na(found)) {
x_new[i] <- found[1L]
next next
} }
} }
}
# keep only letters
# try by removing all trailing capitals found <- suppressWarnings(as.ab(gsub("[^A-Z]", "", x[i]), initial = FALSE))
if (x[i] %like_case% "[a-z]+[A-Z]+$") { if (!is.na(found)) {
found <- suppressWarnings(as.ab(gsub("[A-Z]+$", "", x[i])))
if (length(found) > 0 & !is.na(found)) {
x_new[i] <- found[1L] x_new[i] <- found[1L]
next next
} }
}
# try from a bigger text, like from a health care record, see ?ab_from_text
found <- suppressWarnings(ab_from_text(x[i], initial = FALSE, translate_ab = FALSE)[1L])
if (!is.na(found)) {
x_new[i] <- found[1L]
next
}
# first 5 except for cephalosporins, then first 7 (those cephalosporins all start quite the same!)
found <- suppressWarnings(as.ab(substr(x[i], 1, 5), initial = FALSE))
if (!is.na(found) && !ab_group(found, initial = FALSE) %like% "cephalosporins") {
x_new[i] <- found[1L]
next
}
found <- suppressWarnings(as.ab(substr(x[i], 1, 7), initial = FALSE))
if (!is.na(found)) {
x_new[i] <- found[1L]
next
}
# make all consonants facultative
search_str <- gsub("([BCDFGHJKLMNPQRSTVWXZ])", "\\1*", x[i])
found <- suppressWarnings(as.ab(search_str, initial = FALSE, already_regex = TRUE))
# keep at least 4 normal characters
if (nchar(gsub(".\\*", "", search_str)) < 4) {
found <- NA
}
if (!is.na(found)) {
x_new[i] <- found[1L]
next
}
# make all vowels facultative
search_str <- gsub("([AEIOUY])", "\\1*", x[i])
found <- suppressWarnings(as.ab(search_str, initial = FALSE, already_regex = TRUE))
# keep at least 5 normal characters
if (nchar(gsub(".\\*", "", search_str)) < 5) {
found <- NA
}
if (!is.na(found)) {
x_new[i] <- found[1L]
next
}
# allow misspelling of vowels
x_spelling <- gsub("A+", "[AEIOU]+", x_spelling, fixed = TRUE)
x_spelling <- gsub("E+", "[AEIOU]+", x_spelling, fixed = TRUE)
x_spelling <- gsub("I+", "[AEIOU]+", x_spelling, fixed = TRUE)
x_spelling <- gsub("O+", "[AEIOU]+", x_spelling, fixed = TRUE)
x_spelling <- gsub("U+", "[AEIOU]+", x_spelling, fixed = TRUE)
found <- suppressWarnings(as.ab(x_spelling, initial = FALSE, already_regex = TRUE))
if (!is.na(found)) {
x_new[i] <- found[1L]
next
}
} # end of initial = TRUE
# not found # not found
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1]) x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
@ -316,7 +376,7 @@ as.ab <- function(x, ...) {
".", ".",
call. = FALSE) call. = FALSE)
} }
if (length(x_unknown) > 0) { if (length(x_unknown) > 0) {
warning("These values could not be coerced to a valid antimicrobial ID: ", warning("These values could not be coerced to a valid antimicrobial ID: ",
paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ", "), paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ", "),

74
R/ab_from_text.R Normal file
View File

@ -0,0 +1,74 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#' Retrieve antimicrobial drugs from text
#'
#' Use this function on e.g. clinical texts from health care records. It returns a vector of antimicrobial drugs found in the texts.
#' @param text text to analyse
#' @param collapse character to pass on to `paste(..., collapse = ...)` to only return one character per element of `text`, see Examples
#' @param 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.
#' @param ... 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:\cr
#' `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)
ab_from_text <- function(text, collapse = NULL, translate_ab = "name", ...) {
text <- tolower(text)
abbr <- unlist(antibiotics$abbreviations)
abbr <- abbr[nchar(abbr) >= 4]
names <- substr(antibiotics$name, 1, 5)
synonyms <- unlist(antibiotics$synonyms)
synonyms <- synonyms[nchar(synonyms) >= 4]
to_regex <- function(x) {
paste0("^(",
paste0(unique(gsub("[^a-z0-9]", ".*", sort(tolower(x)))), collapse = "|"),
").*")
}
text_split <- unlist(strsplit(text, "[ ;.,:/\\|-]"))
result <- as.ab(unique(c(text_split[grep(to_regex(abbr), text_split)],
text_split[grep(to_regex(names), text_split)],
# regular expression must not be too long, so split synonyms in two:
text_split[grep(to_regex(synonyms[c(1:0.5 * length(synonyms))]), text_split)],
text_split[grep(to_regex(synonyms[c(0.5 * length(synonyms):length(synonyms))]), text_split)])),
...)
translate_ab <- get_translate_ab(translate_ab)
if (!isFALSE(translate_ab)) {
result <- ab_property(result, property = translate_ab)
}
if (!is.null(collapse)) {
result <- paste0(result, collapse = collapse)
}
result
}

View File

@ -64,7 +64,7 @@
#' } #' }
like <- function(x, pattern, ignore.case = TRUE) { like <- function(x, pattern, ignore.case = TRUE) {
# set to fixed if no regex found # set to fixed if no regex found
fixed <- all(!grepl("[$.^*?+}{|)(]", pattern)) fixed <- all(!grepl("[\\[$.^*?+-}{|)(]", pattern))
if (ignore.case == TRUE) { if (ignore.case == TRUE) {
# set here, otherwise if fixed = TRUE, this warning will be thrown: argument 'ignore.case = TRUE' will be ignored # set here, otherwise if fixed = TRUE, this warning will be thrown: argument 'ignore.case = TRUE' will be ignored
x <- tolower(x) x <- tolower(x)

View File

@ -30,7 +30,7 @@
#' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of `0.123456` will then be returned as `"12.3%"`. #' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of `0.123456` will then be returned as `"12.3%"`.
#' @param only_all_tested (for combination therapies, i.e. using more than one variable for `...`): a logical to indicate that isolates must be tested for all antibiotics, see section *Combination therapy* below #' @param only_all_tested (for combination therapies, i.e. using more than one variable for `...`): a logical to indicate that isolates must be tested for all antibiotics, see section *Combination therapy* below
#' @param data a [`data.frame`] containing columns with class [`rsi`] (see [as.rsi()]) #' @param data a [`data.frame`] containing columns with class [`rsi`] (see [as.rsi()])
#' @param translate_ab a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()] #' @param translate_ab a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()]. Use a value
#' @inheritParams ab_property #' @inheritParams ab_property
#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter `combine_IR`, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is `TRUE`. #' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter `combine_IR`, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is `TRUE`.
#' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter `combine_SI`. #' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter `combine_SI`.

View File

@ -56,8 +56,10 @@ rsi_calc <- function(...,
# for complete data.frames, like example_isolates %>% select(AMC, GEN) %>% proportion_S() # for complete data.frames, like example_isolates %>% select(AMC, GEN) %>% proportion_S()
# and the old rsi function, which has "df" as name of the first parameter # and the old rsi function, which has "df" as name of the first parameter
x <- dots_df x <- dots_df
} else if (length(dots) == 1 | all(!dots %in% colnames(dots_df))) {
x <- dots_df
} else { } else {
x <- dots_df[, dots[dots %in% colnames(dots_df)]] x <- dots_df[, dots[dots %in% colnames(dots_df)], drop = FALSE]
} }
} else if (ndots == 1) { } else if (ndots == 1) {
# only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$AMC) and example_isolates$AMC %>% proportion_S() # only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$AMC) and example_isolates$AMC %>% proportion_S()
@ -111,7 +113,7 @@ rsi_calc <- function(...,
base::all(y %in% other_values) & base::any(is.na(y)) base::all(y %in% other_values) & base::any(is.na(y))
}) })
numerator <- sum(as.logical(by(x, seq_len(nrow(x)), function(row) any(unlist(row) %in% ab_result, na.rm = TRUE)))) numerator <- sum(as.logical(by(x, seq_len(nrow(x)), function(row) any(unlist(row) %in% ab_result, na.rm = TRUE))))
denominator <- nrow(x[!other_values_filter, ]) denominator <- nrow(x[!other_values_filter, , drop = FALSE])
} }
} else { } else {
# x is not a data.frame # x is not a data.frame
@ -168,9 +170,7 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
} }
stop_if(isTRUE(combine_SI) & isTRUE(combine_IR), "either `combine_SI` or `combine_IR` can be TRUE, not both", call = -2) stop_if(isTRUE(combine_SI) & isTRUE(combine_IR), "either `combine_SI` or `combine_IR` can be TRUE, not both", call = -2)
if (as.character(translate_ab) %in% c("TRUE", "official")) { translate_ab <- get_translate_ab(translate_ab)
translate_ab <- "name"
}
# select only groups and antibiotics # select only groups and antibiotics
if (has_groups(data)) { if (has_groups(data)) {
@ -292,3 +292,19 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
rownames(out) <- NULL rownames(out) <- NULL
out out
} }
get_translate_ab <- function(translate_ab) {
translate_ab <- as.character(translate_ab)[1L]
if (translate_ab %in% c("TRUE", "official")) {
return("name")
} else if (translate_ab %in% c(NA_character_, "FALSE")) {
return(FALSE)
} else {
translate_ab <- tolower(translate_ab)
stop_ifnot(translate_ab %in% colnames(AMR::antibiotics),
"invalid value for 'translate_ab', this must be a column name of the antibiotics data set\n",
"or TRUE (equals 'name') or FALSE to not translate at all.",
call = FALSE)
translate_ab
}
}

View File

@ -200,7 +200,7 @@
"FLM" "J01MB07" 3374 "Flumequine" "Quinolones" "Quinolone antibacterials" "Other quinolones" "" "c(\"apurone\", \"fantacin\", \"flumequine\", \"flumequino\", \"flumequinum\", \"flumigal\", \"flumiquil\", \"flumisol\", \"flumix\", \"imequyl\")" 1.2 "g" "character(0)" "FLM" "J01MB07" 3374 "Flumequine" "Quinolones" "Quinolone antibacterials" "Other quinolones" "" "c(\"apurone\", \"fantacin\", \"flumequine\", \"flumequino\", \"flumequinum\", \"flumigal\", \"flumiquil\", \"flumisol\", \"flumix\", \"imequyl\")" 1.2 "g" "character(0)"
"FLR1" "J01FA14" 71260 "Flurithromycin" "Macrolides/lincosamides" "Macrolides, lincosamides and streptogramins" "Macrolides" "" "c(\"flurithromicina\", \"flurithromycime\", \"flurithromycin\", \"flurithromycine\", \"flurithromycinum\", \"fluritromicina\", \"fluritromycinum\", \"flurizic\")" 0.75 "g" "character(0)" "FLR1" "J01FA14" 71260 "Flurithromycin" "Macrolides/lincosamides" "Macrolides, lincosamides and streptogramins" "Macrolides" "" "c(\"flurithromicina\", \"flurithromycime\", \"flurithromycin\", \"flurithromycine\", \"flurithromycinum\", \"fluritromicina\", \"fluritromycinum\", \"flurizic\")" 0.75 "g" "character(0)"
"FFL" 214356 "Fosfluconazole" "Antifungals/antimycotics" "" "c(\"fosfluconazole\", \"phosfluconazole\", \"procif\", \"prodif\")" "character(0)" "FFL" 214356 "Fosfluconazole" "Antifungals/antimycotics" "" "c(\"fosfluconazole\", \"phosfluconazole\", \"procif\", \"prodif\")" "character(0)"
"FOS" "J01XX01" 446987 "Fosfomycin" "Other antibacterials" "Other antibacterials" "Other antibacterials" "c(\"ff\", \"fm\", \"fo\", \"fos\", \"fosf\")" "c(\"fosfocina\", \"fosfomicina\", \"fosfomycin\", \"fosfomycin sodium\", \"fosfomycine\", \"fosfomycinum\", \"fosfonomycin\", \"phosphonemycin\", \"phosphonomycin\", \"veramina\")" 3 "g" 8 "g" "character(0)" "FOS" "J01XX01" 446987 "Fosfomycin" "Other antibacterials" "Other antibacterials" "Other antibacterials" "c(\"ff\", \"fm\", \"fo\", \"fos\", \"fosf\")" "c(\"fosfocina\", \"fosfomicina\", \"fosfomycin\", \"fosfomycin sodium\", \"fosfomycine\", \"fosfomycinum\", \"fosfonomycin\", \"monuril\", \"monurol\", \"phosphonemycin\", \"phosphonomycin\", \"veramina\")" 3 "g" 8 "g" "character(0)"
"FMD" 572 "Fosmidomycin" "Other antibacterials" "" "c(\"fosmidomycin\", \"fosmidomycina\", \"fosmidomycine\", \"fosmidomycinum\")" "character(0)" "FMD" 572 "Fosmidomycin" "Other antibacterials" "" "c(\"fosmidomycin\", \"fosmidomycina\", \"fosmidomycine\", \"fosmidomycinum\")" "character(0)"
"FRM" 8378 "Framycetin" "Aminoglycosides" "c(\"\", \"fram\")" "c(\"actilin\", \"actiline\", \"antibiotique\", \"bycomycin\", \"endomixin\", \"enterfram\", \"fradiomycin\", \"fradiomycin b\", \"fradiomycinum\", \"framicetina\", \"framycetin\", \"framycetin sulfate\", \"framycetine\", \"framycetinum\", \"framygen\", \"fraquinol\", \"jernadex\", \"myacine\", \"myacyne\", \"mycerin\", \"mycifradin\", \"neobrettin\", \"neolate\", \"neomas\", \"neomcin\", \"neomicina\", \"neomin\", \"neomycin\", \"neomycin b\", \"neomycin b sulfate\", \"neomycin solution\", \"neomycin sulfate\", \"neomycin sulphate\", \"neomycinb\", \"neomycine\", \"neomycinum\", "FRM" 8378 "Framycetin" "Aminoglycosides" "c(\"\", \"fram\")" "c(\"actilin\", \"actiline\", \"antibiotique\", \"bycomycin\", \"endomixin\", \"enterfram\", \"fradiomycin\", \"fradiomycin b\", \"fradiomycinum\", \"framicetina\", \"framycetin\", \"framycetin sulfate\", \"framycetine\", \"framycetinum\", \"framygen\", \"fraquinol\", \"jernadex\", \"myacine\", \"myacyne\", \"mycerin\", \"mycifradin\", \"neobrettin\", \"neolate\", \"neomas\", \"neomcin\", \"neomicina\", \"neomin\", \"neomycin\", \"neomycin b\", \"neomycin b sulfate\", \"neomycin solution\", \"neomycin sulfate\", \"neomycin sulphate\", \"neomycinb\", \"neomycine\", \"neomycinum\",
\"nivemycin\", \"pimavecort\", \"soframycin\", \"soframycine\", \"tuttomycin\", \"vonamycin\", \"vonamycin powder v\")" "character(0)" \"nivemycin\", \"pimavecort\", \"soframycin\", \"soframycine\", \"tuttomycin\", \"vonamycin\", \"vonamycin powder v\")" "character(0)"

View File

@ -488,6 +488,10 @@ antibiotics[which(antibiotics$ab == "SLT4"), "abbreviations"][[1]] <- list(c(ant
antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]], "trsx")) antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]], "trsx"))
antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]], "vanc")) antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]], "vanc"))
antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]], "vori")) antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]], "vori"))
antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]], "Monuril")))
antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]], "Monurol")))
antibiotics <- antibiotics %>% antibiotics <- antibiotics %>%
mutate(ab = as.character(ab)) %>% mutate(ab = as.character(ab)) %>%
rbind(antibiotics %>% rbind(antibiotics %>%

Binary file not shown.

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -43,7 +43,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>
@ -229,21 +229,26 @@
<small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small> <small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div> </div>
<div id="amr-1209013" class="section level1"> <div id="amr-1209014" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9013"> <h1 class="page-header" data-toc-text="1.2.0.9014">
<a href="#amr-1209013" class="anchor"></a>AMR 1.2.0.9013<small> Unreleased </small> <a href="#amr-1209014" class="anchor"></a>AMR 1.2.0.9014<small> Unreleased </small>
</h1> </h1>
<div id="last-updated-22-jun-2020" class="section level2"> <div id="last-updated-25-jun-2020" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-22-jun-2020" class="anchor"></a><small>Last updated: 22-Jun-2020</small> <a href="#last-updated-25-jun-2020" class="anchor"></a><small>Last updated: 25-Jun-2020</small>
</h2> </h2>
<div id="new" class="section level3"> <div id="new" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
<a href="#new" class="anchor"></a>New</h3> <a href="#new" class="anchor"></a>New</h3>
<ul> <ul>
<li> <li>
<p>Function <code><a href="../reference/ab_from_text.html">ab_from_text()</a></code> to retrieve antimicrobial drugs from clinical texts in e.g. health care records, which also corrects for misspelling since it uses <code><a href="../reference/as.ab.html">as.ab()</a></code> internally:</p>
<div class="sourceCode" id="cb1"><pre class="r"><span class="fu"><a href="../reference/ab_from_text.html">ab_from_text</a></span>(<span class="st">"28/03/2020 regular amoxiciliin 500mg po tds"</span>)
<span class="co">#&gt; [1] "Amoxicillin"</span></pre></div>
</li>
<li>
<p><a href="https://tidyselect.r-lib.org/reference/language.html">Tidyverse selections</a> for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like <code><a href="https://dplyr.tidyverse.org/reference/select.html">dplyr::select()</a></code> and <code><a href="https://tidyr.tidyverse.org/reference/pivot_longer.html">tidyr::pivot_longer()</a></code>:</p> <p><a href="https://tidyselect.r-lib.org/reference/language.html">Tidyverse selections</a> for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like <code><a href="https://dplyr.tidyverse.org/reference/select.html">dplyr::select()</a></code> and <code><a href="https://tidyr.tidyverse.org/reference/pivot_longer.html">tidyr::pivot_longer()</a></code>:</p>
<div class="sourceCode" id="cb1"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>) <div class="sourceCode" id="cb2"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>)
<span class="co"># Columns 'IPM' and 'MEM' are in the example_isolates data set</span> <span class="co"># Columns 'IPM' and 'MEM' are in the example_isolates data set</span>
<span class="no">example_isolates</span> <span class="kw">%&gt;%</span> <span class="no">example_isolates</span> <span class="kw">%&gt;%</span>
@ -269,6 +274,8 @@
<h3 class="hasAnchor"> <h3 class="hasAnchor">
<a href="#changed" class="anchor"></a>Changed</h3> <a href="#changed" class="anchor"></a>Changed</h3>
<ul> <ul>
<li>Fixed a bug for using <code>susceptibility</code> or <code><a href="../reference/proportion.html">resistance()</a></code> outside <code><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise()</a></code>
</li>
<li>Fixed a bug where <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> would not work on a tibble when the <code>tibble</code> or <code>dplyr</code> package was loaded</li> <li>Fixed a bug where <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> would not work on a tibble when the <code>tibble</code> or <code>dplyr</code> package was loaded</li>
<li>All <code>*_join_microorganisms()</code> functions and <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> now return the original data class (e.g. <code>tibble</code>s and <code>data.table</code>s)</li> <li>All <code>*_join_microorganisms()</code> functions and <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> now return the original data class (e.g. <code>tibble</code>s and <code>data.table</code>s)</li>
<li>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li> <li>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li>
@ -278,6 +285,9 @@
<li>Fixed a bug in <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> for when only one antibiotic was in the input data</li> <li>Fixed a bug in <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> for when only one antibiotic was in the input data</li>
<li>Changed the summary for class <code>&lt;mo&gt;</code>, to highlight the %SI vs. %R</li> <li>Changed the summary for class <code>&lt;mo&gt;</code>, to highlight the %SI vs. %R</li>
<li>Improved error handling, giving more useful info when functions return an error</li> <li>Improved error handling, giving more useful info when functions return an error</li>
<li>Algorithm improvements to <code><a href="../reference/as.ab.html">as.ab()</a></code>
</li>
<li>Added Monuril as trade name for fosfomycin</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -399,7 +409,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline</p></li> <li><p>Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline</p></li>
<li> <li>
<p>Interpretation from MIC values (and disk zones) to R/SI can now be used with <code><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at()</a></code> of the <code>dplyr</code> package:</p> <p>Interpretation from MIC values (and disk zones) to R/SI can now be used with <code><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at()</a></code> of the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb2"><pre class="r"><span class="no">yourdata</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb3"><pre class="r"><span class="no">yourdata</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span>(<span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(<span class="no">antibiotic1</span>:<span class="no">antibiotic25</span>), <span class="no">as.rsi</span>, <span class="kw">mo</span> <span class="kw">=</span> <span class="st">"E. coli"</span>) <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span>(<span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(<span class="no">antibiotic1</span>:<span class="no">antibiotic25</span>), <span class="no">as.rsi</span>, <span class="kw">mo</span> <span class="kw">=</span> <span class="st">"E. coli"</span>)
<span class="no">yourdata</span> <span class="kw">%&gt;%</span> <span class="no">yourdata</span> <span class="kw">%&gt;%</span>
@ -426,7 +436,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Support for LOINC codes in the <code>antibiotics</code> data set. Use <code><a href="../reference/ab_property.html">ab_loinc()</a></code> to retrieve LOINC codes, or use a LOINC code for input in any <code>ab_*</code> function:</p> <p>Support for LOINC codes in the <code>antibiotics</code> data set. Use <code><a href="../reference/ab_property.html">ab_loinc()</a></code> to retrieve LOINC codes, or use a LOINC code for input in any <code>ab_*</code> function:</p>
<div class="sourceCode" id="cb3"><pre class="r"><span class="fu"><a href="../reference/ab_property.html">ab_loinc</a></span>(<span class="st">"ampicillin"</span>) <div class="sourceCode" id="cb4"><pre class="r"><span class="fu"><a href="../reference/ab_property.html">ab_loinc</a></span>(<span class="st">"ampicillin"</span>)
<span class="co">#&gt; [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5"</span> <span class="co">#&gt; [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5"</span>
<span class="fu"><a href="../reference/ab_property.html">ab_name</a></span>(<span class="st">"21066-6"</span>) <span class="fu"><a href="../reference/ab_property.html">ab_name</a></span>(<span class="st">"21066-6"</span>)
<span class="co">#&gt; [1] "Ampicillin"</span> <span class="co">#&gt; [1] "Ampicillin"</span>
@ -435,7 +445,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li> </li>
<li> <li>
<p>Support for SNOMED CT codes in the <code>microorganisms</code> data set. Use <code><a href="../reference/mo_property.html">mo_snomed()</a></code> to retrieve SNOMED codes, or use a SNOMED code for input in any <code>mo_*</code> function:</p> <p>Support for SNOMED CT codes in the <code>microorganisms</code> data set. Use <code><a href="../reference/mo_property.html">mo_snomed()</a></code> to retrieve SNOMED codes, or use a SNOMED code for input in any <code>mo_*</code> function:</p>
<div class="sourceCode" id="cb4"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_snomed</a></span>(<span class="st">"S. aureus"</span>) <div class="sourceCode" id="cb5"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_snomed</a></span>(<span class="st">"S. aureus"</span>)
<span class="co">#&gt; [1] 115329001 3092008 113961008</span> <span class="co">#&gt; [1] 115329001 3092008 113961008</span>
<span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="fl">115329001</span>) <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="fl">115329001</span>)
<span class="co">#&gt; [1] "Staphylococcus aureus"</span> <span class="co">#&gt; [1] "Staphylococcus aureus"</span>
@ -498,9 +508,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:</p> <p>If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:</p>
<div class="sourceCode" id="cb5"><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="no">somebugs</span>) <span class="kw">==</span> <span class="st">"Enterobacteriaceae"</span>) <span class="no">...</span></pre></div> <div class="sourceCode" id="cb6"><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="no">somebugs</span>) <span class="kw">==</span> <span class="st">"Enterobacteriaceae"</span>) <span class="no">...</span></pre></div>
<p>then please adjust this to:</p> <p>then please adjust this to:</p>
<div class="sourceCode" id="cb6"><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="no">somebugs</span>) <span class="kw">==</span> <span class="st">"Enterobacterales"</span>) <span class="no">...</span></pre></div> <div class="sourceCode" id="cb7"><pre class="r"><span class="kw">if</span> (<span class="fu"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="no">somebugs</span>) <span class="kw">==</span> <span class="st">"Enterobacterales"</span>) <span class="no">...</span></pre></div>
</li> </li>
</ul> </ul>
</li> </li>
@ -512,7 +522,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Functions <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> as aliases of <code><a href="../reference/proportion.html">proportion_SI()</a></code> and <code><a href="../reference/proportion.html">proportion_R()</a></code>, respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.</p> <p>Functions <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> as aliases of <code><a href="../reference/proportion.html">proportion_SI()</a></code> and <code><a href="../reference/proportion.html">proportion_R()</a></code>, respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.</p>
<div class="sourceCode" id="cb7"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>) <div class="sourceCode" id="cb8"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>)
<span class="no">example_isolates</span> <span class="kw">%&gt;%</span> <span class="no">example_isolates</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">bug</span> <span class="kw">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="no">mo</span>)) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">bug</span> <span class="kw">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="no">mo</span>)) <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(<span class="kw">amoxicillin</span> <span class="kw">=</span> <span class="fu"><a href="../reference/proportion.html">resistance</a></span>(<span class="no">AMX</span>), <span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(<span class="kw">amoxicillin</span> <span class="kw">=</span> <span class="fu"><a href="../reference/proportion.html">resistance</a></span>(<span class="no">AMX</span>),
@ -539,7 +549,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>More intelligent way of coping with some consonants like “l” and “r”</p></li> <li><p>More intelligent way of coping with some consonants like “l” and “r”</p></li>
<li> <li>
<p>Added a score (a certainty percentage) to <code><a href="../reference/as.mo.html">mo_uncertainties()</a></code>, that is calculated using the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a>:</p> <p>Added a score (a certainty percentage) to <code><a href="../reference/as.mo.html">mo_uncertainties()</a></code>, that is calculated using the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a>:</p>
<div class="sourceCode" id="cb8"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Stafylococcus aureus"</span>, <div class="sourceCode" id="cb9"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Stafylococcus aureus"</span>,
<span class="st">"staphylokok aureuz"</span>)) <span class="st">"staphylokok aureuz"</span>))
<span class="co">#&gt; Warning: </span> <span class="co">#&gt; Warning: </span>
<span class="co">#&gt; Results of two values were guessed with uncertainty. Use mo_uncertainties() to review them.</span> <span class="co">#&gt; Results of two values were guessed with uncertainty. Use mo_uncertainties() to review them.</span>
@ -596,12 +606,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Determination of first isolates now <strong>excludes</strong> all unknown microorganisms at default, i.e. microbial code <code>"UNKNOWN"</code>. They can be included with the new parameter <code>include_unknown</code>:</p> <p>Determination of first isolates now <strong>excludes</strong> all unknown microorganisms at default, i.e. microbial code <code>"UNKNOWN"</code>. They can be included with the new parameter <code>include_unknown</code>:</p>
<div class="sourceCode" id="cb9"><pre class="r"><span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="no">...</span>, <span class="kw">include_unknown</span> <span class="kw">=</span> <span class="fl">TRUE</span>)</pre></div> <div class="sourceCode" id="cb10"><pre class="r"><span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="no">...</span>, <span class="kw">include_unknown</span> <span class="kw">=</span> <span class="fl">TRUE</span>)</pre></div>
<p>For WHONET users, this means that all records/isolates with organism code <code>"con"</code> (<em>contamination</em>) will be excluded at default, since <code>as.mo("con") = "UNKNOWN"</code>. The function always shows a note with the number of unknown microorganisms that were included or excluded.</p> <p>For WHONET users, this means that all records/isolates with organism code <code>"con"</code> (<em>contamination</em>) will be excluded at default, since <code>as.mo("con") = "UNKNOWN"</code>. The function always shows a note with the number of unknown microorganisms that were included or excluded.</p>
</li> </li>
<li> <li>
<p>For code consistency, classes <code>ab</code> and <code>mo</code> will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in <code>NA</code>:</p> <p>For code consistency, classes <code>ab</code> and <code>mo</code> will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in <code>NA</code>:</p>
<div class="sourceCode" id="cb10"><pre class="r"><span class="co"># how it works in base R:</span> <div class="sourceCode" id="cb11"><pre class="r"><span class="co"># how it works in base R:</span>
<span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html">factor</a></span>(<span class="st">"A"</span>) <span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html">factor</a></span>(<span class="st">"A"</span>)
<span class="no">x</span>[<span class="fl">1</span>] <span class="kw">&lt;-</span> <span class="st">"B"</span> <span class="no">x</span>[<span class="fl">1</span>] <span class="kw">&lt;-</span> <span class="st">"B"</span>
<span class="co">#&gt; Warning message:</span> <span class="co">#&gt; Warning message:</span>
@ -624,7 +634,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Function <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> to quickly get a <code>data.frame</code> with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed with <code><a href="../reference/mo_property.html">mo_shortname()</a></code> at default:</p> <p>Function <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> to quickly get a <code>data.frame</code> with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed with <code><a href="../reference/mo_property.html">mo_shortname()</a></code> at default:</p>
<div class="sourceCode" id="cb11"><pre class="r"><span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="../reference/bug_drug_combinations.html">bug_drug_combinations</a></span>(<span class="no">example_isolates</span>) <div class="sourceCode" id="cb12"><pre class="r"><span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="../reference/bug_drug_combinations.html">bug_drug_combinations</a></span>(<span class="no">example_isolates</span>)
<span class="co">#&gt; NOTE: Using column `mo` as input for `col_mo`.</span> <span class="co">#&gt; NOTE: Using column `mo` as input for `col_mo`.</span>
<span class="no">x</span>[<span class="fl">1</span>:<span class="fl">4</span>, ] <span class="no">x</span>[<span class="fl">1</span>:<span class="fl">4</span>, ]
<span class="co">#&gt; mo ab S I R total</span> <span class="co">#&gt; mo ab S I R total</span>
@ -645,11 +655,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="co">#&gt; 4 Gram-negative AMX 227 0 405 632</span> <span class="co">#&gt; 4 Gram-negative AMX 227 0 405 632</span>
<span class="co">#&gt; NOTE: Use 'format()' on this result to get a publicable/printable format.</span></pre></div> <span class="co">#&gt; NOTE: Use 'format()' on this result to get a publicable/printable format.</span></pre></div>
<p>You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R <code><a href="https://rdrr.io/r/base/format.html">format()</a></code> function:</p> <p>You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R <code><a href="https://rdrr.io/r/base/format.html">format()</a></code> function:</p>
<div class="sourceCode" id="cb12"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span>(<span class="no">x</span>, <span class="kw">combine_IR</span> <span class="kw">=</span> <span class="fl">FALSE</span>)</pre></div> <div class="sourceCode" id="cb13"><pre class="r"><span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span>(<span class="no">x</span>, <span class="kw">combine_IR</span> <span class="kw">=</span> <span class="fl">FALSE</span>)</pre></div>
</li> </li>
<li> <li>
<p>Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for <code>portion_*</code> functions or <code>count_*</code> functions. This can be used to determine the empiric susceptibility of a combination therapy. A new parameter <code>only_all_tested</code> (<strong>which defaults to <code>FALSE</code></strong>) replaces the old <code>also_single_tested</code> and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the <code>portion</code> and <code>count</code> help pages), where the %SI is being determined:</p> <p>Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for <code>portion_*</code> functions or <code>count_*</code> functions. This can be used to determine the empiric susceptibility of a combination therapy. A new parameter <code>only_all_tested</code> (<strong>which defaults to <code>FALSE</code></strong>) replaces the old <code>also_single_tested</code> and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the <code>portion</code> and <code>count</code> help pages), where the %SI is being determined:</p>
<div class="sourceCode" id="cb13"><pre class="r"># -------------------------------------------------------------------- <div class="sourceCode" id="cb14"><pre class="r"># --------------------------------------------------------------------
# only_all_tested = FALSE only_all_tested = TRUE # only_all_tested = FALSE only_all_tested = TRUE
# ----------------------- ----------------------- # ----------------------- -----------------------
# Drug A Drug B include as include as include as include as # Drug A Drug B include as include as include as include as
@ -669,7 +679,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li> </li>
<li> <li>
<p><code>tibble</code> printing support for classes <code>rsi</code>, <code>mic</code>, <code>disk</code>, <code>ab</code> <code>mo</code>. When using <code>tibble</code>s containing antimicrobial columns, values <code>S</code> will print in green, values <code>I</code> will print in yellow and values <code>R</code> will print in red. Microbial IDs (class <code>mo</code>) will emphasise on the genus and species, not on the kingdom.</p> <p><code>tibble</code> printing support for classes <code>rsi</code>, <code>mic</code>, <code>disk</code>, <code>ab</code> <code>mo</code>. When using <code>tibble</code>s containing antimicrobial columns, values <code>S</code> will print in green, values <code>I</code> will print in yellow and values <code>R</code> will print in red. Microbial IDs (class <code>mo</code>) will emphasise on the genus and species, not on the kingdom.</p>
<div class="sourceCode" id="cb14"><pre class="r"><span class="co"># (run this on your own console, as this page does not support colour printing)</span> <div class="sourceCode" id="cb15"><pre class="r"><span class="co"># (run this on your own console, as this page does not support colour printing)</span>
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>) <span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="no">dplyr</span>)
<span class="no">example_isolates</span> <span class="kw">%&gt;%</span> <span class="no">example_isolates</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">mo</span>:<span class="no">AMC</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">mo</span>:<span class="no">AMC</span>) <span class="kw">%&gt;%</span>
@ -750,7 +760,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Function <code><a href="../reference/proportion.html">rsi_df()</a></code> to transform a <code>data.frame</code> to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions <code><a href="../reference/count.html">count_df()</a></code> and <code><a href="../reference/AMR-deprecated.html">portion_df()</a></code> to immediately show resistance percentages and number of available isolates:</p> <p>Function <code><a href="../reference/proportion.html">rsi_df()</a></code> to transform a <code>data.frame</code> to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions <code><a href="../reference/count.html">count_df()</a></code> and <code><a href="../reference/AMR-deprecated.html">portion_df()</a></code> to immediately show resistance percentages and number of available isolates:</p>
<div class="sourceCode" id="cb15"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb16"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">AMX</span>, <span class="no">CIP</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">AMX</span>, <span class="no">CIP</span>) <span class="kw">%&gt;%</span>
<span class="fu"><a href="../reference/proportion.html">rsi_df</a></span>() <span class="fu"><a href="../reference/proportion.html">rsi_df</a></span>()
<span class="co"># antibiotic interpretation value isolates</span> <span class="co"># antibiotic interpretation value isolates</span>
@ -775,7 +785,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>UPEC (Uropathogenic <em>E. coli</em>)</li> <li>UPEC (Uropathogenic <em>E. coli</em>)</li>
</ul> </ul>
<p>All these lead to the microbial ID of <em>E. coli</em>:</p> <p>All these lead to the microbial ID of <em>E. coli</em>:</p>
<div class="sourceCode" id="cb16"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"UPEC"</span>) <div class="sourceCode" id="cb17"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"UPEC"</span>)
<span class="co"># B_ESCHR_COL</span> <span class="co"># B_ESCHR_COL</span>
<span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"UPEC"</span>) <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="st">"UPEC"</span>)
<span class="co"># "Escherichia coli"</span> <span class="co"># "Escherichia coli"</span>
@ -882,7 +892,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>when all values are unique it now shows a message instead of a warning</p></li> <li><p>when all values are unique it now shows a message instead of a warning</p></li>
<li> <li>
<p>support for boxplots:</p> <p>support for boxplots:</p>
<div class="sourceCode" id="cb17"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb18"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu">freq</span>(<span class="no">age</span>) <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">age</span>) <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://rdrr.io/r/graphics/boxplot.html">boxplot</a></span>() <span class="fu"><a href="https://rdrr.io/r/graphics/boxplot.html">boxplot</a></span>()
<span class="co"># grouped boxplots:</span> <span class="co"># grouped boxplots:</span>
@ -973,7 +983,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li> </li>
<li> <li>
<p>New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:</p> <p>New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:</p>
<div class="sourceCode" id="cb18"><pre class="r"><span class="fu"><a href="../reference/filter_ab_class.html">filter_aminoglycosides</a></span>() <div class="sourceCode" id="cb19"><pre class="r"><span class="fu"><a href="../reference/filter_ab_class.html">filter_aminoglycosides</a></span>()
<span class="fu"><a href="../reference/filter_ab_class.html">filter_carbapenems</a></span>() <span class="fu"><a href="../reference/filter_ab_class.html">filter_carbapenems</a></span>()
<span class="fu"><a href="../reference/filter_ab_class.html">filter_cephalosporins</a></span>() <span class="fu"><a href="../reference/filter_ab_class.html">filter_cephalosporins</a></span>()
<span class="fu"><a href="../reference/filter_ab_class.html">filter_1st_cephalosporins</a></span>() <span class="fu"><a href="../reference/filter_ab_class.html">filter_1st_cephalosporins</a></span>()
@ -985,14 +995,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="fu"><a href="../reference/filter_ab_class.html">filter_macrolides</a></span>() <span class="fu"><a href="../reference/filter_ab_class.html">filter_macrolides</a></span>()
<span class="fu"><a href="../reference/filter_ab_class.html">filter_tetracyclines</a></span>()</pre></div> <span class="fu"><a href="../reference/filter_ab_class.html">filter_tetracyclines</a></span>()</pre></div>
<p>The <code>antibiotics</code> data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the <code>antibiotics</code> data set. For example:</p> <p>The <code>antibiotics</code> data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the <code>antibiotics</code> data set. For example:</p>
<div class="sourceCode" id="cb19"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/filter_ab_class.html">filter_glycopeptides</a></span>(<span class="kw">result</span> <span class="kw">=</span> <span class="st">"R"</span>) <div class="sourceCode" id="cb20"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/filter_ab_class.html">filter_glycopeptides</a></span>(<span class="kw">result</span> <span class="kw">=</span> <span class="st">"R"</span>)
<span class="co"># Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R</span> <span class="co"># Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R</span>
<span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/filter_ab_class.html">filter_glycopeptides</a></span>(<span class="kw">result</span> <span class="kw">=</span> <span class="st">"R"</span>, <span class="kw">scope</span> <span class="kw">=</span> <span class="st">"all"</span>) <span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/filter_ab_class.html">filter_glycopeptides</a></span>(<span class="kw">result</span> <span class="kw">=</span> <span class="st">"R"</span>, <span class="kw">scope</span> <span class="kw">=</span> <span class="st">"all"</span>)
<span class="co"># Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is R</span></pre></div> <span class="co"># Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is R</span></pre></div>
</li> </li>
<li> <li>
<p>All <code>ab_*</code> functions are deprecated and replaced by <code>atc_*</code> functions:</p> <p>All <code>ab_*</code> functions are deprecated and replaced by <code>atc_*</code> functions:</p>
<div class="sourceCode" id="cb20"><pre class="r"><span class="no">ab_property</span> <span class="kw">-&gt;</span> <span class="fu">atc_property</span>() <div class="sourceCode" id="cb21"><pre class="r"><span class="no">ab_property</span> <span class="kw">-&gt;</span> <span class="fu">atc_property</span>()
<span class="no">ab_name</span> <span class="kw">-&gt;</span> <span class="fu">atc_name</span>() <span class="no">ab_name</span> <span class="kw">-&gt;</span> <span class="fu">atc_name</span>()
<span class="no">ab_official</span> <span class="kw">-&gt;</span> <span class="fu">atc_official</span>() <span class="no">ab_official</span> <span class="kw">-&gt;</span> <span class="fu">atc_official</span>()
<span class="no">ab_trivial_nl</span> <span class="kw">-&gt;</span> <span class="fu">atc_trivial_nl</span>() <span class="no">ab_trivial_nl</span> <span class="kw">-&gt;</span> <span class="fu">atc_trivial_nl</span>()
@ -1011,17 +1021,17 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>New function <code><a href="../reference/age_groups.html">age_groups()</a></code> to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.</p></li> <li><p>New function <code><a href="../reference/age_groups.html">age_groups()</a></code> to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.</p></li>
<li> <li>
<p>New function <code><a href="../reference/resistance_predict.html">ggplot_rsi_predict()</a></code> as well as the base R <code><a href="https://rdrr.io/r/base/plot.html">plot()</a></code> function can now be used for resistance prediction calculated with <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code>:</p> <p>New function <code><a href="../reference/resistance_predict.html">ggplot_rsi_predict()</a></code> as well as the base R <code><a href="https://rdrr.io/r/base/plot.html">plot()</a></code> function can now be used for resistance prediction calculated with <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code>:</p>
<div class="sourceCode" id="cb21"><pre class="r"><span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span>(<span class="no">septic_patients</span>, <span class="kw">col_ab</span> <span class="kw">=</span> <span class="st">"amox"</span>) <div class="sourceCode" id="cb22"><pre class="r"><span class="no">x</span> <span class="kw">&lt;-</span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span>(<span class="no">septic_patients</span>, <span class="kw">col_ab</span> <span class="kw">=</span> <span class="st">"amox"</span>)
<span class="fu"><a href="https://rdrr.io/r/base/plot.html">plot</a></span>(<span class="no">x</span>) <span class="fu"><a href="https://rdrr.io/r/base/plot.html">plot</a></span>(<span class="no">x</span>)
<span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span>(<span class="no">x</span>)</pre></div> <span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span>(<span class="no">x</span>)</pre></div>
</li> </li>
<li> <li>
<p>Functions <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> and <code><a href="../reference/first_isolate.html">filter_first_weighted_isolate()</a></code> to shorten and fasten filtering on data sets with antimicrobial results, e.g.:</p> <p>Functions <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> and <code><a href="../reference/first_isolate.html">filter_first_weighted_isolate()</a></code> to shorten and fasten filtering on data sets with antimicrobial results, e.g.:</p>
<div class="sourceCode" id="cb22"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>(<span class="no">...</span>) <div class="sourceCode" id="cb23"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>(<span class="no">...</span>)
<span class="co"># or</span> <span class="co"># or</span>
<span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>(<span class="no">septic_patients</span>, <span class="no">...</span>)</pre></div> <span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>(<span class="no">septic_patients</span>, <span class="no">...</span>)</pre></div>
<p>is equal to:</p> <p>is equal to:</p>
<div class="sourceCode" id="cb23"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb24"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="kw">only_firsts</span> <span class="kw">=</span> <span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="no">septic_patients</span>, <span class="no">...</span>)) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="kw">only_firsts</span> <span class="kw">=</span> <span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="no">septic_patients</span>, <span class="no">...</span>)) <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="no">only_firsts</span> <span class="kw">==</span> <span class="fl">TRUE</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="no">only_firsts</span> <span class="kw">==</span> <span class="fl">TRUE</span>) <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(-<span class="no">only_firsts</span>)</pre></div> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(-<span class="no">only_firsts</span>)</pre></div>
@ -1052,7 +1062,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Now handles incorrect spelling, like <code>i</code> instead of <code>y</code> and <code>f</code> instead of <code>ph</code>:</p> <p>Now handles incorrect spelling, like <code>i</code> instead of <code>y</code> and <code>f</code> instead of <code>ph</code>:</p>
<div class="sourceCode" id="cb24"><pre class="r"><span class="co"># mo_fullname() uses as.mo() internally</span> <div class="sourceCode" id="cb25"><pre class="r"><span class="co"># mo_fullname() uses as.mo() internally</span>
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Sthafilokockus aaureuz"</span>) <span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Sthafilokockus aaureuz"</span>)
<span class="co">#&gt; [1] "Staphylococcus aureus"</span> <span class="co">#&gt; [1] "Staphylococcus aureus"</span>
@ -1062,7 +1072,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li> </li>
<li> <li>
<p>Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default <code>allow_uncertain = TRUE</code> is equal to uncertainty level 2. Run <code><a href="../reference/as.mo.html">?as.mo</a></code> for more info about these levels.</p> <p>Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default <code>allow_uncertain = TRUE</code> is equal to uncertainty level 2. Run <code><a href="../reference/as.mo.html">?as.mo</a></code> for more info about these levels.</p>
<div class="sourceCode" id="cb25"><pre class="r"><span class="co"># equal:</span> <div class="sourceCode" id="cb26"><pre class="r"><span class="co"># equal:</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">...</span>, <span class="kw">allow_uncertain</span> <span class="kw">=</span> <span class="fl">TRUE</span>) <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">...</span>, <span class="kw">allow_uncertain</span> <span class="kw">=</span> <span class="fl">TRUE</span>)
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">...</span>, <span class="kw">allow_uncertain</span> <span class="kw">=</span> <span class="fl">2</span>) <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">...</span>, <span class="kw">allow_uncertain</span> <span class="kw">=</span> <span class="fl">2</span>)
@ -1075,7 +1085,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>All microbial IDs that found are now saved to a local file <code>~/.Rhistory_mo</code>. Use the new function <code>clean_mo_history()</code> to delete this file, which resets the algorithms.</p></li> <li><p>All microbial IDs that found are now saved to a local file <code>~/.Rhistory_mo</code>. Use the new function <code>clean_mo_history()</code> to delete this file, which resets the algorithms.</p></li>
<li> <li>
<p>Incoercible results will now be considered unknown, MO code <code>UNKNOWN</code>. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:</p> <p>Incoercible results will now be considered unknown, MO code <code>UNKNOWN</code>. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:</p>
<div class="sourceCode" id="cb26"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"qwerty"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"es"</span>) <div class="sourceCode" id="cb27"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"qwerty"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"es"</span>)
<span class="co"># Warning: </span> <span class="co"># Warning: </span>
<span class="co"># one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it.</span> <span class="co"># one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it.</span>
<span class="co">#&gt; [1] "(género desconocido)"</span></pre></div> <span class="co">#&gt; [1] "(género desconocido)"</span></pre></div>
@ -1123,7 +1133,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:</p> <p>Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:</p>
<div class="sourceCode" id="cb27"><pre class="r"><span class="co"># Determine genus of microorganisms (mo) in `septic_patients` data set:</span> <div class="sourceCode" id="cb28"><pre class="r"><span class="co"># Determine genus of microorganisms (mo) in `septic_patients` data set:</span>
<span class="co"># OLD WAY</span> <span class="co"># OLD WAY</span>
<span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="kw">genus</span> <span class="kw">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="no">mo</span>)) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="kw">genus</span> <span class="kw">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="no">mo</span>)) <span class="kw">%&gt;%</span>
@ -1206,7 +1216,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Fewer than 3 characters as input for <code>as.mo</code> will return NA</p></li> <li><p>Fewer than 3 characters as input for <code>as.mo</code> will return NA</p></li>
<li> <li>
<p>Function <code>as.mo</code> (and all <code>mo_*</code> wrappers) now supports genus abbreviations with “species” attached</p> <p>Function <code>as.mo</code> (and all <code>mo_*</code> wrappers) now supports genus abbreviations with “species” attached</p>
<div class="sourceCode" id="cb28"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"E. species"</span>) <span class="co"># B_ESCHR</span> <div class="sourceCode" id="cb29"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"E. species"</span>) <span class="co"># B_ESCHR</span>
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"E. spp."</span>) <span class="co"># "Escherichia species"</span> <span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"E. spp."</span>) <span class="co"># "Escherichia species"</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. spp"</span>) <span class="co"># B_STPHY</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. spp"</span>) <span class="co"># B_STPHY</span>
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. species"</span>) <span class="co"># "Staphylococcus species"</span></pre></div> <span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. species"</span>) <span class="co"># "Staphylococcus species"</span></pre></div>
@ -1221,13 +1231,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul> <ul>
<li> <li>
<p>Support for grouping variables, test with:</p> <p>Support for grouping variables, test with:</p>
<div class="sourceCode" id="cb29"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb30"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="no">hospital_id</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="no">hospital_id</span>) <span class="kw">%&gt;%</span>
<span class="fu">freq</span>(<span class="no">gender</span>)</pre></div> <span class="fu">freq</span>(<span class="no">gender</span>)</pre></div>
</li> </li>
<li> <li>
<p>Support for (un)selecting columns:</p> <p>Support for (un)selecting columns:</p>
<div class="sourceCode" id="cb30"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <div class="sourceCode" id="cb31"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span>
<span class="fu">freq</span>(<span class="no">hospital_id</span>) <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">hospital_id</span>) <span class="kw">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(-<span class="no">count</span>, -<span class="no">cum_count</span>) <span class="co"># only get item, percent, cum_percent</span></pre></div> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(-<span class="no">count</span>, -<span class="no">cum_count</span>) <span class="co"># only get item, percent, cum_percent</span></pre></div>
</li> </li>
@ -1305,7 +1315,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li> </li>
</ul> </ul>
<p>They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:</p> <p>They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:</p>
<div class="sourceCode" id="cb31"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"E. coli"</span>) <div class="sourceCode" id="cb32"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] "Gram negative"</span> <span class="co"># [1] "Gram negative"</span>
<span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"E. coli"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"de"</span>) <span class="co"># German</span> <span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"E. coli"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"de"</span>) <span class="co"># German</span>
<span class="co"># [1] "Gramnegativ"</span> <span class="co"># [1] "Gramnegativ"</span>
@ -1314,7 +1324,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. group A"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"pt"</span>) <span class="co"># Portuguese</span> <span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. group A"</span>, <span class="kw">language</span> <span class="kw">=</span> <span class="st">"pt"</span>) <span class="co"># Portuguese</span>
<span class="co"># [1] "Streptococcus grupo A"</span></pre></div> <span class="co"># [1] "Streptococcus grupo A"</span></pre></div>
<p>Furthermore, former taxonomic names will give a note about the current taxonomic name:</p> <p>Furthermore, former taxonomic names will give a note about the current taxonomic name:</p>
<div class="sourceCode" id="cb32"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"Esc blattae"</span>) <div class="sourceCode" id="cb33"><pre class="r"><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"Esc blattae"</span>)
<span class="co"># Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)</span> <span class="co"># Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)</span>
<span class="co"># [1] "Gram negative"</span></pre></div> <span class="co"># [1] "Gram negative"</span></pre></div>
</li> </li>
@ -1327,14 +1337,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Function <code>is.rsi.eligible</code> to check for columns that have valid antimicrobial results, but do not have the <code>rsi</code> class yet. Transform the columns of your raw data with: <code>data %&gt;% mutate_if(is.rsi.eligible, as.rsi)</code></p></li> <li><p>Function <code>is.rsi.eligible</code> to check for columns that have valid antimicrobial results, but do not have the <code>rsi</code> class yet. Transform the columns of your raw data with: <code>data %&gt;% mutate_if(is.rsi.eligible, as.rsi)</code></p></li>
<li> <li>
<p>Functions <code>as.mo</code> and <code>is.mo</code> as replacements for <code>as.bactid</code> and <code>is.bactid</code> (since the <code>microoganisms</code> data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The <code>as.mo</code> function determines microbial IDs using intelligent rules:</p> <p>Functions <code>as.mo</code> and <code>is.mo</code> as replacements for <code>as.bactid</code> and <code>is.bactid</code> (since the <code>microoganisms</code> data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The <code>as.mo</code> function determines microbial IDs using intelligent rules:</p>
<div class="sourceCode" id="cb33"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"E. coli"</span>) <div class="sourceCode" id="cb34"><pre class="r"><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] B_ESCHR_COL</span> <span class="co"># [1] B_ESCHR_COL</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"MRSA"</span>) <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"MRSA"</span>)
<span class="co"># [1] B_STPHY_AUR</span> <span class="co"># [1] B_STPHY_AUR</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S group A"</span>) <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S group A"</span>)
<span class="co"># [1] B_STRPTC_GRA</span></pre></div> <span class="co"># [1] B_STRPTC_GRA</span></pre></div>
<p>And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:</p> <p>And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:</p>
<div class="sourceCode" id="cb34"><pre class="r"><span class="no">thousands_of_E_colis</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span>(<span class="st">"E. coli"</span>, <span class="fl">25000</span>) <div class="sourceCode" id="cb35"><pre class="r"><span class="no">thousands_of_E_colis</span> <span class="kw">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span>(<span class="st">"E. coli"</span>, <span class="fl">25000</span>)
<span class="kw pkg">microbenchmark</span><span class="kw ns">::</span><span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html">microbenchmark</a></span>(<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">thousands_of_E_colis</span>), <span class="kw">unit</span> <span class="kw">=</span> <span class="st">"s"</span>) <span class="kw pkg">microbenchmark</span><span class="kw ns">::</span><span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html">microbenchmark</a></span>(<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="no">thousands_of_E_colis</span>), <span class="kw">unit</span> <span class="kw">=</span> <span class="st">"s"</span>)
<span class="co"># Unit: seconds</span> <span class="co"># Unit: seconds</span>
<span class="co"># min median max neval</span> <span class="co"># min median max neval</span>
@ -1366,7 +1376,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added three antimicrobial agents to the <code>antibiotics</code> data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)</p></li> <li><p>Added three antimicrobial agents to the <code>antibiotics</code> data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)</p></li>
<li> <li>
<p>Added 163 trade names to the <code>antibiotics</code> data set, it now contains 298 different trade names in total, e.g.:</p> <p>Added 163 trade names to the <code>antibiotics</code> data set, it now contains 298 different trade names in total, e.g.:</p>
<div class="sourceCode" id="cb35"><pre class="r"><span class="fu">ab_official</span>(<span class="st">"Bactroban"</span>) <div class="sourceCode" id="cb36"><pre class="r"><span class="fu">ab_official</span>(<span class="st">"Bactroban"</span>)
<span class="co"># [1] "Mupirocin"</span> <span class="co"># [1] "Mupirocin"</span>
<span class="fu"><a href="../reference/ab_property.html">ab_name</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Bactroban"</span>, <span class="st">"Amoxil"</span>, <span class="st">"Zithromax"</span>, <span class="st">"Floxapen"</span>)) <span class="fu"><a href="../reference/ab_property.html">ab_name</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Bactroban"</span>, <span class="st">"Amoxil"</span>, <span class="st">"Zithromax"</span>, <span class="st">"Floxapen"</span>))
<span class="co"># [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin"</span> <span class="co"># [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin"</span>
@ -1381,7 +1391,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added parameters <code>minimum</code> and <code>as_percent</code> to <code>portion_df</code></p></li> <li><p>Added parameters <code>minimum</code> and <code>as_percent</code> to <code>portion_df</code></p></li>
<li> <li>
<p>Support for quasiquotation in the functions series <code>count_*</code> and <code>portions_*</code>, and <code>n_rsi</code>. This allows to check for more than 2 vectors or columns.</p> <p>Support for quasiquotation in the functions series <code>count_*</code> and <code>portions_*</code>, and <code>n_rsi</code>. This allows to check for more than 2 vectors or columns.</p>
<div class="sourceCode" id="cb36"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">amox</span>, <span class="no">cipr</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/count.html">count_IR</a></span>() <div class="sourceCode" id="cb37"><pre class="r"><span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="no">amox</span>, <span class="no">cipr</span>) <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/count.html">count_IR</a></span>()
<span class="co"># which is the same as:</span> <span class="co"># which is the same as:</span>
<span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/count.html">count_IR</a></span>(<span class="no">amox</span>, <span class="no">cipr</span>) <span class="no">septic_patients</span> <span class="kw">%&gt;%</span> <span class="fu"><a href="../reference/count.html">count_IR</a></span>(<span class="no">amox</span>, <span class="no">cipr</span>)
@ -1399,10 +1409,10 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added longest en shortest character length in the frequency table (<code>freq</code>) header of class <code>character</code></p></li> <li><p>Added longest en shortest character length in the frequency table (<code>freq</code>) header of class <code>character</code></p></li>
<li> <li>
<p>Support for types (classes) list and matrix for <code>freq</code></p> <p>Support for types (classes) list and matrix for <code>freq</code></p>
<div class="sourceCode" id="cb37"><pre class="r"><span class="no">my_matrix</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/with.html">with</a></span>(<span class="no">septic_patients</span>, <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="no">age</span>, <span class="no">gender</span>), <span class="kw">ncol</span> <span class="kw">=</span> <span class="fl">2</span>)) <div class="sourceCode" id="cb38"><pre class="r"><span class="no">my_matrix</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/with.html">with</a></span>(<span class="no">septic_patients</span>, <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="no">age</span>, <span class="no">gender</span>), <span class="kw">ncol</span> <span class="kw">=</span> <span class="fl">2</span>))
<span class="fu">freq</span>(<span class="no">my_matrix</span>)</pre></div> <span class="fu">freq</span>(<span class="no">my_matrix</span>)</pre></div>
<p>For lists, subsetting is possible:</p> <p>For lists, subsetting is possible:</p>
<div class="sourceCode" id="cb38"><pre class="r"><span class="no">my_list</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span>(<span class="kw">age</span> <span class="kw">=</span> <span class="no">septic_patients</span>$<span class="no">age</span>, <span class="kw">gender</span> <span class="kw">=</span> <span class="no">septic_patients</span>$<span class="no">gender</span>) <div class="sourceCode" id="cb39"><pre class="r"><span class="no">my_list</span> <span class="kw">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span>(<span class="kw">age</span> <span class="kw">=</span> <span class="no">septic_patients</span>$<span class="no">age</span>, <span class="kw">gender</span> <span class="kw">=</span> <span class="no">septic_patients</span>$<span class="no">gender</span>)
<span class="no">my_list</span> <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">age</span>) <span class="no">my_list</span> <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">age</span>)
<span class="no">my_list</span> <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">gender</span>)</pre></div> <span class="no">my_list</span> <span class="kw">%&gt;%</span> <span class="fu">freq</span>(<span class="no">gender</span>)</pre></div>
</li> </li>

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html WHONET: WHONET.html
benchmarks: benchmarks.html benchmarks: benchmarks.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
last_built: 2020-06-22T11:18Z last_built: 2020-06-25T15:34Z
urls: urls:
reference: https://msberends.gitlab.io/AMR/reference reference: https://msberends.gitlab.io/AMR/reference
article: https://msberends.gitlab.io/AMR/articles article: https://msberends.gitlab.io/AMR/articles

View File

@ -0,0 +1,305 @@
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Retrieve antimicrobial drugs from text — ab_from_text • AMR (for R)</title>
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png" />
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png" />
<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>
<!-- bootstrap-toc -->
<link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script>
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous" />
<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script>
<!-- headroom.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>
<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>
<link href="../extra.css" rel="stylesheet">
<script src="../extra.js"></script>
<meta property="og:title" content="Retrieve antimicrobial drugs from text — ab_from_text" />
<meta property="og:description" content="Use this function on e.g. clinical texts from health care records. It returns a vector of antimicrobial drugs found in the texts." />
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" />
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
<div class="container template-reference-topic">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home"></span>
Home
</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<span class="fa fa-question-circle"></span>
How to
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/AMR.html">
<span class="fa fa-directions"></span>
Conduct AMR analysis
</a>
</li>
<li>
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
</a>
</li>
<li>
<a href="../articles/PCA.html">
<span class="fa fa-compress"></span>
Conduct principal component analysis for AMR
</a>
</li>
<li>
<a href="../articles/MDR.html">
<span class="fa fa-skull-crossbones"></span>
Determine multi-drug resistance (MDR)
</a>
</li>
<li>
<a href="../articles/WHONET.html">
<span class="fa fa-globe-americas"></span>
Work with WHONET data
</a>
</li>
<li>
<a href="../articles/SPSS.html">
<span class="fa fa-file-upload"></span>
Import data from SPSS/SAS/Stata
</a>
</li>
<li>
<a href="../articles/EUCAST.html">
<span class="fa fa-exchange-alt"></span>
Apply EUCAST rules
</a>
</li>
<li>
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../reference/ab_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
</a>
</li>
<li>
<a href="../articles/benchmarks.html">
<span class="fa fa-shipping-fast"></span>
Other: benchmarks
</a>
</li>
</ul>
</li>
<li>
<a href="../reference/">
<span class="fa fa-book-open"></span>
Manual
</a>
</li>
<li>
<a href="../authors.html">
<span class="fa fa-users"></span>
Authors
</a>
</li>
<li>
<a href="../news/">
<span class="far fa far fa-newspaper"></span>
Changelog
</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://gitlab.com/msberends/AMR">
<span class="fab fa fab fa-gitlab"></span>
Source Code
</a>
</li>
<li>
<a href="../LICENSE-text.html">
<span class="fa fa-book"></span>
Licence
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Retrieve antimicrobial drugs from text</h1>
<small class="dont-index">Source: <a href='https://gitlab.com/msberends/AMR/blob/master/R/ab_from_text.R'><code>R/ab_from_text.R</code></a></small>
<div class="hidden name"><code>ab_from_text.Rd</code></div>
</div>
<div class="ref-description">
<p>Use this function on e.g. clinical texts from health care records. It returns a vector of antimicrobial drugs found in the texts.</p>
</div>
<pre class="usage"><span class='fu'>ab_from_text</span>(<span class='no'>text</span>, <span class='kw'>collapse</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>text</th>
<td><p>text to analyse</p></td>
</tr>
<tr>
<th>collapse</th>
<td><p>character to pass on to <code><a href='https://rdrr.io/r/base/paste.html'>paste(..., collapse = ...)</a></code> to only return one character per element of <code>text</code>, see Examples</p></td>
</tr>
<tr>
<th>translate_ab</th>
<td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Defaults to "name", which is equal to using <code>TRUE</code>. Use a value <code>FALSE</code>, <code>NULL</code> or <code>NA</code> to prevent translation of the <code>&lt;ab&gt;</code> code.</p></td>
</tr>
<tr>
<th>...</th>
<td><p>parameters passed on to <code><a href='as.ab.html'>as.ab()</a></code></p></td>
</tr>
</table>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>To use this for creating a new variable in a data set (e.g. with <code>mutate()</code>), it could be convenient to paste the outcome together with the <code>collapse</code> parameter so every value in your new variable will be a character of length 1:<br />
<code>df %&gt;% mutate(abx = ab_from_text(clinical_text, collapse = "|"))</code></p>
<p>This function is also internally used by <code><a href='as.ab.html'>as.ab()</a></code>, although it then only returns the first hit.</p>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><span class='co'># mind the bad spelling of amoxicillin in this line, </span>
<span class='co'># straight from a true health care record:</span>
<span class='fu'>ab_from_text</span>(<span class='st'>"28/03/2020 regular amoxicilliin 500mg po tds"</span>)
<span class='fu'>ab_from_text</span>(<span class='st'>"administered amoxi/clav and cipro"</span>)
<span class='fu'>ab_from_text</span>(<span class='st'>"administered amoxi/clav and cipro"</span>, <span class='kw'>collapse</span> <span class='kw'>=</span> <span class='st'>", "</span>)
<span class='co'># if you want to know which antibiotic groups were administered, check it:</span>
<span class='no'>abx</span> <span class='kw'>&lt;-</span> <span class='fu'>ab_from_text</span>(<span class='st'>"administered amoxi/clav and cipro"</span>)
<span class='fu'><a href='ab_property.html'>ab_group</a></span>(<span class='no'>abx</span>)</pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top">
<h2 data-toc-skip>Contents</h2>
</nav>
</div>
</div>
<footer>
<div class="copyright">
<p>Developed by <a href='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <a href='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <a href='https://www.rug.nl/staff/a.w.friedrich/'>Alexander W. Friedrich</a>, <a href='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <a href='https://www.rug.nl/staff/c.j.albers/'>Casper J. Albers</a>, <a href='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.</p>
</div>
</footer>
</div>
</body>
</html>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>
@ -288,7 +288,12 @@ This package contains <strong>all ~550 antibiotic, antimycotic and antiviral dru
<p>On our website <a href='https://msberends.gitlab.io/AMR'>https://msberends.gitlab.io/AMR</a> you can find <a href='https://msberends.gitlab.io/AMR/articles/AMR.html'>a comprehensive tutorial</a> about how to conduct AMR analysis, the <a href='https://msberends.gitlab.io/AMR/reference'>complete documentation of all functions</a> (which reads a lot easier than here in R) and <a href='https://msberends.gitlab.io/AMR/articles/WHONET.html'>an example analysis using WHONET data</a>.</p> <p>On our website <a href='https://msberends.gitlab.io/AMR'>https://msberends.gitlab.io/AMR</a> you can find <a href='https://msberends.gitlab.io/AMR/articles/AMR.html'>a comprehensive tutorial</a> about how to conduct AMR analysis, the <a href='https://msberends.gitlab.io/AMR/reference'>complete documentation of all functions</a> (which reads a lot easier than here in R) and <a href='https://msberends.gitlab.io/AMR/articles/WHONET.html'>an example analysis using WHONET data</a>.</p>
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2> <h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><a href='antibiotics.html'>antibiotics</a> for the dataframe that is being used to determine ATCs.</p></div> <div class='dont-index'>
<ul>
<li><p><a href='antibiotics.html'>antibiotics</a> for the dataframe that is being used to determine ATCs</p></li>
<li><p><code><a href='ab_from_text.html'>ab_from_text()</a></code> for a function to retrieve antimicrobial drugs from clinical text (from health care records)</p></li>
</ul>
</div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2> <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><span class='co'># these examples all return "ERY", the ID of erythromycin:</span> <pre class="examples"><span class='co'># these examples all return "ERY", the ID of erythromycin:</span>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -83,7 +83,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>
@ -280,7 +280,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
</tr> </tr>
<tr> <tr>
<th>translate_ab</th> <th>translate_ab</th>
<td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code></p></td> <td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Use a value</p></td>
</tr> </tr>
<tr> <tr>
<th>language</th> <th>language</th>
@ -400,7 +400,7 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='kw'>S</span> <span class='kw'>=</span> <span class='fu'>count_S</span>(<span class='no'>CIP</span>), <span class='kw'>S</span> <span class='kw'>=</span> <span class='fu'>count_S</span>(<span class='no'>CIP</span>),
<span class='kw'>n1</span> <span class='kw'>=</span> <span class='fu'>count_all</span>(<span class='no'>CIP</span>), <span class='co'># the actual total; sum of all three</span> <span class='kw'>n1</span> <span class='kw'>=</span> <span class='fu'>count_all</span>(<span class='no'>CIP</span>), <span class='co'># the actual total; sum of all three</span>
<span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'>n_rsi</span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span> <span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'>n_rsi</span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span>
<span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/n.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span> <span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/context.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span>
<span class='co'># Count co-resistance between amoxicillin/clav acid and gentamicin,</span> <span class='co'># Count co-resistance between amoxicillin/clav acid and gentamicin,</span>
<span class='co'># so we can see that combination therapy does a lot more than mono therapy.</span> <span class='co'># so we can see that combination therapy does a lot more than mono therapy.</span>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>
@ -326,7 +326,7 @@
</tr> </tr>
<tr> <tr>
<th>translate_ab</th> <th>translate_ab</th>
<td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code></p></td> <td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Use a value</p></td>
</tr> </tr>
<tr> <tr>
<th>combine_SI</th> <th>combine_SI</th>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9013</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9011</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>

View File

@ -83,7 +83,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9011</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9014</span>
</span> </span>
</div> </div>
@ -296,7 +296,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
</tr> </tr>
<tr> <tr>
<th>translate_ab</th> <th>translate_ab</th>
<td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code></p></td> <td><p>a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Use a value</p></td>
</tr> </tr>
<tr> <tr>
<th>language</th> <th>language</th>

View File

@ -15,6 +15,9 @@
<url> <url>
<loc>https://msberends.gitlab.io/AMR/reference/WHONET.html</loc> <loc>https://msberends.gitlab.io/AMR/reference/WHONET.html</loc>
</url> </url>
<url>
<loc>https://msberends.gitlab.io/AMR/reference/ab_from_text.html</loc>
</url>
<url> <url>
<loc>https://msberends.gitlab.io/AMR/reference/ab_property.html</loc> <loc>https://msberends.gitlab.io/AMR/reference/ab_property.html</loc>
</url> </url>

38
man/ab_from_text.Rd Normal file
View File

@ -0,0 +1,38 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ab_from_text.R
\name{ab_from_text}
\alias{ab_from_text}
\title{Retrieve antimicrobial drugs from text}
\usage{
ab_from_text(text, collapse = NULL, translate_ab = "name", ...)
}
\arguments{
\item{text}{text to analyse}
\item{collapse}{character to pass on to \code{paste(..., collapse = ...)} to only return one character per element of \code{text}, see Examples}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Defaults to "name", which is equal to using \code{TRUE}. Use a value \code{FALSE}, \code{NULL} or \code{NA} to prevent translation of the \verb{<ab>} code.}
\item{...}{parameters passed on to \code{\link[=as.ab]{as.ab()}}}
}
\description{
Use this function on e.g. clinical texts from health care records. It returns a vector of antimicrobial drugs found in the texts.
}
\details{
To use this for creating a new variable in a data set (e.g. with \code{mutate()}), it could be convenient to paste the outcome together with the \code{collapse} parameter so every value in your new variable will be a character of length 1:\cr
\code{df \%>\% mutate(abx = ab_from_text(clinical_text, collapse = "|"))}
This function is also internally used by \code{\link[=as.ab]{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)
}

View File

@ -83,5 +83,8 @@ ab_name("J01FA01") # "Erythromycin"
ab_name("eryt") # "Erythromycin" ab_name("eryt") # "Erythromycin"
} }
\seealso{ \seealso{
\link{antibiotics} for the dataframe that is being used to determine ATCs. \itemize{
\item \link{antibiotics} for the dataframe that is being used to determine ATCs
\item \code{\link[=ab_from_text]{ab_from_text()}} for a function to retrieve antimicrobial drugs from clinical text (from health care records)
}
} }

View File

@ -47,7 +47,7 @@ count_df(
\item{data}{a \code{\link{data.frame}} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})} \item{data}{a \code{\link{data.frame}} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}} \item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Use a value}
\item{language}{language of the returned text, defaults to system language (see \code{\link[=get_locale]{get_locale()}}) and can also be set with \code{getOption("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.} \item{language}{language of the returned text, defaults to system language (see \code{\link[=get_locale]{get_locale()}}) and can also be set with \code{getOption("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}

View File

@ -83,7 +83,7 @@ labels_rsi_count(
\item{limits}{numeric vector of length two providing limits of the scale, use \code{NA} to refer to the existing minimum or maximum} \item{limits}{numeric vector of length two providing limits of the scale, use \code{NA} to refer to the existing minimum or maximum}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}} \item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Use a value}
\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.} \item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.}

View File

@ -62,7 +62,7 @@ rsi_df(
\item{data}{a \code{\link{data.frame}} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})} \item{data}{a \code{\link{data.frame}} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}} \item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Use a value}
\item{language}{language of the returned text, defaults to system language (see \code{\link[=get_locale]{get_locale()}}) and can also be set with \code{getOption("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.} \item{language}{language of the returned text, defaults to system language (see \code{\link[=get_locale]{get_locale()}}) and can also be set with \code{getOption("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}

View File

@ -0,0 +1,32 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
context("ab_from_text.R")
test_that("ab_from_text works", {
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds"),
"Amoxicillin")
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", translate_ab = FALSE),
as.ab("AMX"))
expect_identical(ab_from_text("administered amoxi/clav and cipro", collapse = ", "),
"Amoxicillin, Ciprofloxacin")
})