diff --git a/DESCRIPTION b/DESCRIPTION index 08eff9b3..2c44bec9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9058 -Date: 2019-08-20 +Version: 0.7.1.9059 +Date: 2019-08-25 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), @@ -30,7 +30,7 @@ Depends: R (>= 3.1.0) Imports: backports, - clean, + clean (>= 1.1.0), crayon (>= 1.3.0), data.table (>= 1.9.0), dplyr (>= 0.7.0), diff --git a/NAMESPACE b/NAMESPACE index 69aa40ef..ec5bab9e 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ S3method(c,ab) S3method(c,mo) S3method(droplevels,mic) S3method(droplevels,rsi) +S3method(format,bugdrug) S3method(freq,mo) S3method(freq,rsi) S3method(kurtosis,data.frame) @@ -37,6 +38,7 @@ S3method(plot,mic) S3method(plot,resistance_predict) S3method(plot,rsi) S3method(print,ab) +S3method(print,bugdrug) S3method(print,catalogue_of_life_version) S3method(print,disk) S3method(print,mic) @@ -81,6 +83,7 @@ export(atc_online_groups) export(atc_online_property) export(availability) export(brmo) +export(bug_drug_combinations) export(catalogue_of_life_version) export(count_I) export(count_IR) @@ -108,6 +111,7 @@ export(filter_glycopeptides) export(filter_macrolides) export(filter_tetracyclines) export(first_isolate) +export(freq) export(full_join_microorganisms) export(g.test) export(geom_rsi) @@ -197,6 +201,7 @@ exportMethods(c.ab) exportMethods(c.mo) exportMethods(droplevels.mic) exportMethods(droplevels.rsi) +exportMethods(format.bugdrug) exportMethods(freq.mo) exportMethods(freq.rsi) exportMethods(kurtosis) @@ -206,6 +211,7 @@ exportMethods(kurtosis.matrix) exportMethods(plot.mic) exportMethods(plot.rsi) exportMethods(print.ab) +exportMethods(print.bugdrug) exportMethods(print.catalogue_of_life_version) exportMethods(print.disk) exportMethods(print.mic) @@ -223,6 +229,7 @@ exportMethods(summary.mic) exportMethods(summary.mo) exportMethods(summary.rsi) importFrom(clean,freq) +importFrom(clean,freq.default) importFrom(clean,top_freq) importFrom(crayon,bgGreen) importFrom(crayon,bgRed) @@ -272,6 +279,7 @@ importFrom(dplyr,n_distinct) importFrom(dplyr,n_groups) importFrom(dplyr,progress_estimated) importFrom(dplyr,pull) +importFrom(dplyr,rename) importFrom(dplyr,row_number) importFrom(dplyr,select) importFrom(dplyr,select_if) @@ -300,6 +308,8 @@ importFrom(stats,glm) importFrom(stats,lm) importFrom(stats,pchisq) importFrom(stats,predict) +importFrom(tidyr,gather) +importFrom(tidyr,spread) importFrom(utils,browseURL) importFrom(utils,installed.packages) importFrom(utils,menu) diff --git a/NEWS.md b/NEWS.md index 7ffdb24a..37cb658c 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ -# AMR 0.7.1.9058 +# AMR 0.7.1.9059 ### Breaking -* Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too. +* Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). The `freq()` function still works, since it is re-exported from the `clean` package to this `AMR` package. Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too. * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: ```r first_isolate(..., include_unknown = TRUE) @@ -9,6 +9,21 @@ For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default, since `as.mo("con") = "UNKNOWN"`. The function always shows a note with the number of 'unknown' microorganisms that were included or excluded. ### New +* Function `bug_drug_combinations()` to quickly get a `data.frame` with the antimicrobial resistance of any bug-drug combination in a data set: + ```r + x <- bug_drug_combinations(septic_patients) + x + #> ab mo S I R total + #> 1 AMC B_ESCHR_COL 332 74 61 467 + #> 2 AMC B_KLBSL_PNE 49 3 6 58 + #> 3 AMC B_PROTS_MIR 28 7 1 36 + #> 4 AMC B_PSDMN_AER 0 0 30 30 + #> 5 AMC B_STPHY_AUR 234 0 1 235 + ``` + You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R `format()` function: + ```r + format(x) + ``` * Additional way to calculate co-resistance, i.e. when using multiple antibiotics as input for `portion_*` functions or `count_*` functions. This can be used to determine the empiric susceptibily of a combination therapy. A new parameter `only_all_tested` (**which defaults to `FALSE`**) replaces the old `also_single_tested` 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 `portion` and `count` help pages), where the %SI is being determined: ```r @@ -72,6 +87,7 @@ * Speed improvement for `guess_ab_col()` which is now 30 times faster for antibiotic abbreviations * Improved `filter_ab_class()` to be more reliable and to support 5th generation cephalosporins * Classes `ab` and `mo` will now be preserved in any subsetting +* Function `availability()` now uses `portion_R()` instead of `portion_IR()`, to comply with EUCAST insights #### Other * Added Prof Dr Casper Albers as doctoral advisor and Dr Bart Meijer, Dr Dennis Souverein and Annick Lenglet as contributors diff --git a/R/availability.R b/R/availability.R index cec00f1e..e6e1bf43 100644 --- a/R/availability.R +++ b/R/availability.R @@ -21,9 +21,10 @@ #' Check availability of columns #' -#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antibiotic combination can be used for calculation with e.g. \code{\link{portion_IR}}. +#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{portion_R}}. #' @param tbl a \code{data.frame} or \code{list} #' @param width number of characters to present the visual availability, defaults to filling the width of the console +#' @details The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{portion_R}}. #' @return \code{data.frame} with column names of \code{tbl} as row names #' @inheritSection AMR Read more on our website! #' @export @@ -44,10 +45,10 @@ availability <- function(tbl, width = NULL) { x <- base::sapply(tbl, function(x) { 1 - base::sum(base::is.na(x)) / base::length(x) }) n <- base::sapply(tbl, function(x) base::length(x[!base::is.na(x)])) - IR <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_IR(x, minimum = 0), NA)) - IR_print <- character(length(IR)) - IR_print[!is.na(IR)] <- percent(IR[!is.na(IR)], round = 1, force_zero = TRUE) - IR_print[is.na(IR)] <- "" + R <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_R(x, minimum = 0), NA)) + R_print <- character(length(R)) + R_print[!is.na(R)] <- percent(R[!is.na(R)], round = 1, force_zero = TRUE) + R_print[is.na(R)] <- "" if (is.null(width)) { width <- options()$width - @@ -63,14 +64,14 @@ availability <- function(tbl, width = NULL) { width <- width / 2 } - if (length(IR[is.na(IR)]) == ncol(tbl)) { + if (length(R[is.na(R)]) == ncol(tbl)) { width <- width * 2 + 10 } - x_chars_IR <- strrep("#", round(width * IR, digits = 2)) - x_chars_S <- strrep("-", width - nchar(x_chars_IR)) - vis_resistance <- paste0("|", x_chars_IR, x_chars_S, "|") - vis_resistance[is.na(IR)] <- "" + x_chars_R <- strrep("#", round(width * R, digits = 2)) + x_chars_SI <- strrep("-", width - nchar(x_chars_R)) + vis_resistance <- paste0("|", x_chars_R, x_chars_SI, "|") + vis_resistance[is.na(R)] <- "" x_chars <- strrep("#", round(x, digits = 2) / (1 / width)) x_chars_empty <- strrep("-", width - nchar(x_chars)) @@ -78,9 +79,9 @@ availability <- function(tbl, width = NULL) { df <- data.frame(count = n, available = percent(x, round = 1, force_zero = TRUE), visual_availabilty = paste0("|", x_chars, x_chars_empty, "|"), - resistant = IR_print, + resistant = R_print, visual_resistance = vis_resistance) - if (length(IR[is.na(IR)]) == ncol(tbl)) { + if (length(R[is.na(R)]) == ncol(tbl)) { df[,1:3] } else { df diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R new file mode 100644 index 00000000..8f418abf --- /dev/null +++ b/R/bug_drug_combinations.R @@ -0,0 +1,107 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # +# # +# 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. # +# # +# This R package was created for academic research and 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. # +# ==================================================================== # + +#' Determine bug-drug combinations +#' +#' Determine antimicrobial resistance (AMR) of all bug-drug combinations in your data set where at least 30 (default) isolates are available per species. Use \code{format} on the result to prettify it to a printable format, see Examples. +#' @inheritParams eucast_rules +#' @inheritParams rsi_df +#' @importFrom dplyr rename +#' @importFrom tidyr spread +#' @importFrom clean freq +#' @export +#' @source \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}. +#' @inheritSection AMR Read more on our website! +#' @examples +#' \donttest{ +#' x <- bug_drug_combinations(septic_patients) +#' x +#' format(x) +#' } +bug_drug_combinations <- function(x, col_mo = NULL, minimum = 30) { + if (!is.data.frame(x)) { + stop("`x` must be a data frame.", call. = FALSE) + } + + # try to find columns based on type + # -- mo + if (is.null(col_mo)) { + col_mo <- search_type_in_df(x = x, type = "mo") + } + if (is.null(col_mo)) { + stop("`col_mo` must be set.", call. = FALSE) + } + + x <- x %>% + mutate(col_mo = x %>% pull(col_mo)) %>% + filter(mo %in% (clean::freq(mo) %>% + filter(count >= minimum) %>% + pull(item))) %>% + group_by(mo) %>% + AMR::rsi_df(translate_ab = FALSE, combine_SI = FALSE) %>% + select(-value) %>% + spread(interpretation, isolates) %>% + mutate(total = S + I + R) %>% + filter(total >= minimum) %>% + rename(ab = antibiotic) + + structure(.Data = x, class = c("bugdrug", class(x))) +} + +#' @importFrom dplyr everything rename +#' @importFrom tidyr spread +#' @exportMethod format.bugdrug +#' @export +format.bugdrug <- function(x, combine_SI = TRUE, add_ab_group = TRUE, ...) { + if (combine_SI == TRUE) { + x$isolates <- x$R + } else { + x$isolates <- x$R + x$I + } + y <- x %>% + mutate(mo = mo_name(mo), + txt = paste0(AMR:::percent(isolates / total, force_zero = TRUE), + " (", trimws(format(isolates, big.mark = ",")), "/", + trimws(format(total, big.mark = ",")), ")")) %>% + select(ab, mo, txt) %>% + spread(mo, txt) %>% + mutate_all(~ifelse(is.na(.), "", .)) %>% + mutate(ab = paste0(ab_name(ab), " (", as.ab(ab), ", ", ab_atc(ab), ")"), + ab_group = ab_group(ab)) %>% + select(ab_group, ab, everything()) %>% + arrange(ab_group, ab) %>% + mutate(ab_group = ifelse(ab_group != lag(ab_group) | is.na(lag(ab_group)), ab_group, "")) + + if (add_ab_group == FALSE) { + y <- y %>% select(-ab_group) + } + y <- y %>% rename("Group" = ab_group, + "Antibiotic" = ab) + y +} + +#' @exportMethod print.bugdrug +#' @export +#' @importFrom crayon blue +print.bugdrug <- function(x, ...) { + print(as.data.frame(x, stringsAsFactors = FALSE)) + message(blue("NOTE: Use 'format()' on this result to get a format that is ready for export or printing.")) +} diff --git a/R/freq.R b/R/freq.R index 38ff3880..104dc639 100755 --- a/R/freq.R +++ b/R/freq.R @@ -19,23 +19,25 @@ # Visit our website for more info: https://msberends.gitlab.io/AMR. # # ==================================================================== # -freq_def <- clean:::freq.default +#' @importFrom clean freq +#' @export +clean::freq + #' @exportMethod freq.mo #' @importFrom dplyr n_distinct -#' @importFrom clean freq +#' @importFrom clean freq.default #' @export #' @noRd freq.mo <- function(x, ...) { - # replace with freq.default() if next `clean` version is published on CRAN - freq_def(x = x, ..., - .add_header = list(families = n_distinct(mo_family(x, language = NULL)), - genera = n_distinct(mo_genus(x, language = NULL)), - species = n_distinct(paste(mo_genus(x, language = NULL), - mo_species(x, language = NULL))))) + freq.default(x = x, ..., + .add_header = list(families = n_distinct(mo_family(x, language = NULL)), + genera = n_distinct(mo_genus(x, language = NULL)), + species = n_distinct(paste(mo_genus(x, language = NULL), + mo_species(x, language = NULL))))) } #' @exportMethod freq.rsi -#' @importFrom clean freq +#' @importFrom clean freq.default #' @export #' @noRd freq.rsi <- function(x, ...) { @@ -43,12 +45,12 @@ freq.rsi <- function(x, ...) { x_name <- gsub(".*[$]", "", x_name) ab <- suppressMessages(suppressWarnings(AMR::as.ab(x_name))) if (!is.na(ab)) { - freq_def(x = x, ..., - .add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"), - group = ab_group(ab), - `%SI` = portion_SI(x, minimum = 0, as_percent = TRUE))) + freq.default(x = x, ..., + .add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"), + group = ab_group(ab), + `%SI` = AMR::portion_SI(x, minimum = 0, as_percent = TRUE))) } else { - freq_def(x = x, ..., - .add_header = list(`%SI` = portion_SI(x, minimum = 0, as_percent = TRUE))) + freq.default(x = x, ..., + .add_header = list(`%SI` = AMR::portion_SI(x, minimum = 0, as_percent = TRUE))) } } diff --git a/R/rsi_calc.R b/R/rsi_calc.R index e1617fb0..fdc08965 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -169,6 +169,7 @@ rsi_calc <- function(..., } #' @importFrom dplyr %>% summarise_if mutate select everything bind_rows +#' @importFrom tidyr gather rsi_calc_df <- function(type, # "portion" or "count" data, translate_ab = "name", @@ -187,10 +188,10 @@ rsi_calc_df <- function(type, # "portion" or "count" combine_SI <- FALSE } if (isTRUE(combine_SI) & isTRUE(combine_IR)) { - stop("either `combine_SI` or `combine_IR` can be TRUE", call. = FALSE) + stop("either `combine_SI` or `combine_IR` can be TRUE, not both", call. = FALSE) } - if (data %>% select_if(is.rsi) %>% ncol() == 0) { + if (!any(sapply(data, is.rsi), na.rm = TRUE)) { stop("No columns with class 'rsi' found. See ?as.rsi.", call. = FALSE) } @@ -198,7 +199,7 @@ rsi_calc_df <- function(type, # "portion" or "count" translate_ab <- "name" } - get_summaryfunction <- function(int) { + get_summaryfunction <- function(int, type) { # look for portion_S, count_S, etc: int_fn <- get(paste0(type, "_", int), envir = asNamespace("AMR")) @@ -218,11 +219,11 @@ rsi_calc_df <- function(type, # "portion" or "count" select(interpretation, everything()) } - resS <- get_summaryfunction("S") - resI <- get_summaryfunction("I") - resR <- get_summaryfunction("R") - resSI <- get_summaryfunction("SI") - resIR <- get_summaryfunction("IR") + resS <- get_summaryfunction("S", type) + resI <- get_summaryfunction("I", type) + resR <- get_summaryfunction("R", type) + resSI <- get_summaryfunction("SI", type) + resIR <- get_summaryfunction("IR", type) data.groups <- group_vars(data) if (isFALSE(combine_SI) & isFALSE(combine_IR)) { @@ -245,11 +246,11 @@ rsi_calc_df <- function(type, # "portion" or "count" } res <- res %>% - tidyr::gather(antibiotic, value, -interpretation, -data.groups) %>% + gather(antibiotic, value, -interpretation, -data.groups) %>% select(antibiotic, everything()) if (!translate_ab == FALSE) { - res <- res %>% mutate(antibiotic = ab_property(antibiotic, property = translate_ab, language = language)) + res <- res %>% mutate(antibiotic = AMR::ab_property(antibiotic, property = translate_ab, language = language)) } res diff --git a/R/rsi_df.R b/R/rsi_df.R index 84cc46ff..11520b0f 100644 --- a/R/rsi_df.R +++ b/R/rsi_df.R @@ -21,7 +21,6 @@ #' @rdname portion #' @rdname count -#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything #' @export rsi_df <- function(data, translate_ab = "name", diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 2d2fe6c5..29e2d2e4 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/index.html b/docs/articles/index.html index 0ab00eda..e7e76955 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 1b328999..d9f466d5 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ diff --git a/docs/index.html b/docs/index.html index b3fd9b29..71ab45f1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ diff --git a/docs/news/index.html b/docs/news/index.html index 2cb5c0b6..8014e475 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ @@ -225,15 +225,15 @@ -freq()
has moved to a new package, clean
(CRAN link). Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the freq()
function. The clean
package is available on CRAN and will be installed automatically when updating the AMR
package, that now imports it. In a later stage, the skewness()
and kurtosis()
functions will be moved to the clean
package too.freq()
has moved to a new package, clean
(CRAN link). The freq()
function still works, since it is re-exported from the clean
package to this AMR
package. Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the freq()
function. The clean
package is available on CRAN and will be installed automatically when updating the AMR
package, that now imports it. In a later stage, the skewness()
and kurtosis()
functions will be moved to the clean
package too.Determination of first isolates now excludes all ‘unknown’ microorganisms at default, i.e. microbial code "UNKNOWN"
. They can be included with the new parameter include_unknown
:
Function bug_drug_combinations()
to quickly get a data.frame
with the antimicrobial resistance of any bug-drug combination in a data set:
x <- bug_drug_combinations(septic_patients)
+x
+#> ab mo S I R total
+#> 1 AMC B_ESCHR_COL 332 74 61 467
+#> 2 AMC B_KLBSL_PNE 49 3 6 58
+#> 3 AMC B_PROTS_MIR 28 7 1 36
+#> 4 AMC B_PSDMN_AER 0 0 30 30
+#> 5 AMC B_STPHY_AUR 234 0 1 235
You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R format()
function:
Additional way to calculate co-resistance, i.e. when using multiple antibiotics as input for portion_*
functions or count_*
functions. This can be used to determine the empiric susceptibily of a combination therapy. A new parameter only_all_tested
(which defaults to FALSE
) replaces the old also_single_tested
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 portion
and count
help pages), where the %SI is being determined:
# -------------------------------------------------------------------------
-# only_all_tested = FALSE only_all_tested = TRUE
-# Antibiotic Antibiotic ----------------------- -----------------------
-# A B include as include as include as include as
-# numerator denominator numerator denominator
-# ---------- ---------- ---------- ----------- ---------- -----------
-# S S X X X X
-# I S X X X X
-# R S X X X X
-# not tested S X X - -
-# S I X X X X
-# I I X X X X
-# R I X X X X
-# not tested I X X - -
-# S R X X X X
-# I R X X X X
-# R R - X - X
-# not tested R - - - -
-# S not tested X X - -
-# I not tested X X - -
-# R not tested - - - -
-# not tested not tested - - - -
-# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
+# only_all_tested = FALSE only_all_tested = TRUE
+# Antibiotic Antibiotic ----------------------- -----------------------
+# A B include as include as include as include as
+# numerator denominator numerator denominator
+# ---------- ---------- ---------- ----------- ---------- -----------
+# S S X X X X
+# I S X X X X
+# R S X X X X
+# not tested S X X - -
+# S I X X X X
+# I I X X X X
+# R I X X X X
+# not tested I X X - -
+# S R X X X X
+# I R X X X X
+# R R - X - X
+# not tested R - - - -
+# S not tested X X - -
+# I not tested X X - -
+# R not tested - - - -
+# not tested not tested - - - -
+# -------------------------------------------------------------------------
Since this is a major change, usage of the old also_single_tested
will throw an informative error that it has been replaced by only_all_tested
.
AMR:::get_column_abx()
)Added tibble printing support for classes rsi
, mic
, disk
, ab
mo
. When using tibbles containing antibiotic columns, values S
will print in green, values I
will print in yellow and values R
will print in red. Microbial IDs (class mo
) will emphasise on the genus and species, not on the kingdom.
atc
- using as.atc()
is now deprecated in favour of ab_atc()
and this will return a character, not the atc
class anymoreabname()
, ab_official()
, atc_name()
, atc_official()
, atc_property()
, atc_tradenames()
, atc_trivial_nl()
@@ -318,7 +331,8 @@
antibiotics
data set is now sorted by name and all cephalosporins now have their generation between bracketsguess_ab_col()
which is now 30 times faster for antibiotic abbreviationsfilter_ab_class()
to be more reliable and to support 5th generation cephalosporinsClasses ab
and mo
will now be preserved in any subsetting
ab
and mo
will now be preserved in any subsettingFunction availability()
now uses portion_R()
instead of portion_IR()
, to comply with EUCAST insights
Function rsi_df()
to transform a data.frame
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 count_df()
and portion_df()
to immediately show resistance percentages and number of available isolates:
Support for all scientifically published pathotypes of E. coli to date (that we could find). Supported are:
@@ -364,12 +378,12 @@All these lead to the microbial ID of E. coli:
-as.mo("UPEC")
-# B_ESCHR_COL
-mo_name("UPEC")
-# "Escherichia coli"
-mo_gramstain("EHEC")
-# "Gram-negative"
as.mo("UPEC")
+# B_ESCHR_COL
+mo_name("UPEC")
+# "Escherichia coli"
+mo_gramstain("EHEC")
+# "Gram-negative"
mo_info()
as an analogy to ab_info()
. The mo_info()
prints a list with the full taxonomy, authors, and the URL to the online database of a microorganismFunction mo_synonyms()
to get all previously accepted taxonomic names of a microorganism
exact
to determine ages with decimals
guess_mo()
, guess_atc()
, EUCAST_rules()
, interpretive_reading()
, rsi()
freq()
):
+freq()
):
support for boxplots:
- +freq()
for when all values are NA
+freq()
for when all values are NA
first_isolate()
for when dates are missingguess_ab_col()
@@ -560,32 +574,32 @@ This data is updated annually - check the included version with the new function
New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:
-filter_aminoglycosides()
-filter_carbapenems()
-filter_cephalosporins()
-filter_1st_cephalosporins()
-filter_2nd_cephalosporins()
-filter_3rd_cephalosporins()
-filter_4th_cephalosporins()
-filter_fluoroquinolones()
-filter_glycopeptides()
-filter_macrolides()
-filter_tetracyclines()
filter_aminoglycosides()
+filter_carbapenems()
+filter_cephalosporins()
+filter_1st_cephalosporins()
+filter_2nd_cephalosporins()
+filter_3rd_cephalosporins()
+filter_4th_cephalosporins()
+filter_fluoroquinolones()
+filter_glycopeptides()
+filter_macrolides()
+filter_tetracyclines()
The antibiotics
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 antibiotics
data set. For example:
All ab_*
functions are deprecated and replaced by atc_*
functions:
ab_property -> atc_property()
-ab_name -> atc_name()
-ab_official -> atc_official()
-ab_trivial_nl -> atc_trivial_nl()
-ab_certe -> atc_certe()
-ab_umcg -> atc_umcg()
-ab_tradenames -> atc_tradenames()
ab_property -> atc_property()
+ab_name -> atc_name()
+ab_official -> atc_official()
+ab_trivial_nl -> atc_trivial_nl()
+ab_certe -> atc_certe()
+ab_umcg -> atc_umcg()
+ab_tradenames -> atc_tradenames()
as.atc()
internally. The old atc_property
has been renamed atc_online_property()
. This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc
or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo()
and e.g. mo_genus
.set_mo_source()
and get_mo_source()
to use your own predefined MO codes as input for as.mo()
and consequently all mo_*
functionsdplyr
version 0.8.0as.atc()New function age_groups()
to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.
New function ggplot_rsi_predict()
as well as the base R plot()
function can now be used for resistance prediction calculated with resistance_predict()
:
-
+
Functions filter_first_isolate()
and filter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.:
-
+
is equal to:
-
+
New function availability()
to check the number of available (non-empty) results in a data.frame
@@ -639,33 +653,33 @@ These functions use as.atc()
Now handles incorrect spelling, like i
instead of y
and f
instead of ph
:
-
+
Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default allow_uncertain = TRUE
is equal to uncertainty level 2. Run ?as.mo
for more info about these levels.
-# equal:
-as.mo(..., allow_uncertain = TRUE)
-as.mo(..., allow_uncertain = 2)
-
-# also equal:
-as.mo(..., allow_uncertain = FALSE)
-as.mo(..., allow_uncertain = 0)
+# equal:
+as.mo(..., allow_uncertain = TRUE)
+as.mo(..., allow_uncertain = 2)
+
+# also equal:
+as.mo(..., allow_uncertain = FALSE)
+as.mo(..., allow_uncertain = 0)
Using as.mo(..., allow_uncertain = 3)
could lead to very unreliable results.
Implemented the latest publication of Becker et al. (2019), for categorising coagulase-negative Staphylococci
All microbial IDs that found are now saved to a local file ~/.Rhistory_mo
. Use the new function clean_mo_history()
to delete this file, which resets the algorithms.
Incoercible results will now be considered ‘unknown’, MO code UNKNOWN
. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:
-
+
Fix for vector containing only empty values
Finds better results when input is in other languages
@@ -707,23 +721,23 @@ Using as.mo(..., allow_uncertain = 3)
-Frequency tables (freq()
function):
+ Frequency tables (freq()
function):
-
Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
-# Determine genus of microorganisms (mo) in `septic_patients` data set:
-# OLD WAY
-septic_patients %>%
- mutate(genus = mo_genus(mo)) %>%
- freq(genus)
-# NEW WAY
-septic_patients %>%
- freq(mo_genus(mo))
-
-# Even supports grouping variables:
-septic_patients %>%
- group_by(gender) %>%
- freq(mo_genus(mo))
+# Determine genus of microorganisms (mo) in `septic_patients` data set:
+# OLD WAY
+septic_patients %>%
+ mutate(genus = mo_genus(mo)) %>%
+ freq(genus)
+# NEW WAY
+septic_patients %>%
+ freq(mo_genus(mo))
+
+# Even supports grouping variables:
+septic_patients %>%
+ group_by(gender) %>%
+ freq(mo_genus(mo))
- Header info is now available as a list, with the
header
function
- The parameter
header
is now set to TRUE
at default, even for markdown
@@ -798,10 +812,10 @@ Using as.mo(..., allow_uncertain = 3)Fewer than 3 characters as input for as.mo
will return NA
Function as.mo
(and all mo_*
wrappers) now supports genus abbreviations with “species” attached
-
+
Added parameter combine_IR
(TRUE/FALSE) to functions portion_df
and count_df
, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)
Fix for portion_*(..., as_percent = TRUE)
when minimal number of isolates would not be met
@@ -810,19 +824,19 @@ Using as.mo(..., allow_uncertain = 3)Using portion_*
functions now throws a warning when total available isolate is below parameter minimum
Functions as.mo
, as.rsi
, as.mic
, as.atc
and freq
will not set package name as attribute anymore
-Frequency tables - freq()
:
+ Frequency tables - freq()
:
-
Support for grouping variables, test with:
-
+
-
Support for (un)selecting columns:
-
+
- Check for
hms::is.hms
@@ -902,18 +916,18 @@ Using as.mo(..., allow_uncertain = 3)
They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:
-mo_gramstain("E. coli")
-# [1] "Gram negative"
-mo_gramstain("E. coli", language = "de") # German
-# [1] "Gramnegativ"
-mo_gramstain("E. coli", language = "es") # Spanish
-# [1] "Gram negativo"
-mo_fullname("S. group A", language = "pt") # Portuguese
-# [1] "Streptococcus grupo A"
+mo_gramstain("E. coli")
+# [1] "Gram negative"
+mo_gramstain("E. coli", language = "de") # German
+# [1] "Gramnegativ"
+mo_gramstain("E. coli", language = "es") # Spanish
+# [1] "Gram negativo"
+mo_fullname("S. group A", language = "pt") # Portuguese
+# [1] "Streptococcus grupo A"
Furthermore, former taxonomic names will give a note about the current taxonomic name:
-
+
Functions count_R
, count_IR
, count_I
, count_SI
and count_S
to selectively count resistant or susceptible isolates
@@ -924,18 +938,18 @@ Using as.mo(..., allow_uncertain = 3)
-
Functions as.mo
and is.mo
as replacements for as.bactid
and is.bactid
(since the microoganisms
data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The as.mo
function determines microbial IDs using intelligent rules:
-as.mo("E. coli")
-# [1] B_ESCHR_COL
-as.mo("MRSA")
-# [1] B_STPHY_AUR
-as.mo("S group A")
-# [1] B_STRPTC_GRA
+as.mo("E. coli")
+# [1] B_ESCHR_COL
+as.mo("MRSA")
+# [1] B_STPHY_AUR
+as.mo("S group A")
+# [1] B_STRPTC_GRA
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:
-
+
- Added parameter
reference_df
for as.mo
, so users can supply their own microbial IDs, name or codes as a reference table
- Renamed all previous references to
bactid
to mo
, like:
@@ -963,12 +977,12 @@ Using as.mo(..., allow_uncertain = 3)Added three antimicrobial agents to the antibiotics
data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)
-
Added 163 trade names to the antibiotics
data set, it now contains 298 different trade names in total, e.g.:
-
+
- For
first_isolate
, rows will be ignored when there’s no species available
- Function
ratio
is now deprecated and will be removed in a future release, as it is not really the scope of this package
@@ -979,13 +993,13 @@ Using as.mo(..., allow_uncertain = 3)
-
Support for quasiquotation in the functions series count_*
and portions_*
, and n_rsi
. This allows to check for more than 2 vectors or columns.
-
+
- Edited
ggplot_rsi
and geom_rsi
so they can cope with count_df
. The new fun
parameter has value portion_df
at default, but can be set to count_df
.
- Fix for
ggplot_rsi
when the ggplot2
package was not loaded
@@ -999,12 +1013,12 @@ Using as.mo(..., allow_uncertain = 3)
-
Support for types (classes) list and matrix for freq
-
+
For lists, subsetting is possible:
-
+
as.mo(..., allow_uncertain = 3)
A vignette to explain its usage
Support for rsi
(antimicrobial resistance) to use as input
-Support for table
to use as input: freq(table(x, y))
+ Support for table
to use as input: freq(table(x, y))
Support for existing functions hist
and plot
to use a frequency table as input: hist(freq(df$age))
Support for as.vector
, as.data.frame
, as_tibble
and format
-Support for quasiquotation: freq(mydata, mycolumn)
is the same as mydata %>% freq(mycolumn)
+ Support for quasiquotation: freq(mydata, mycolumn)
is the same as mydata %>% freq(mycolumn)
Function top_freq
function to return the top/below n items as vector
Header of frequency tables now also show Mean Absolute Deviaton (MAD) and Interquartile Range (IQR)
@@ -1238,7 +1252,7 @@ Using as.mo(..., allow_uncertain = 3)
Contents
Easy check for availability of columns in a data set. This makes it easy to get an idea of which antibiotic combination can be used for calculation with e.g. portion_IR
.
Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. portion_R
.
data.frame
with column names of tbl
as row names
The function returns a data.frame
with columns "resistant"
and "visual_resistance"
. The values in that columns are calculated with portion_R
.