From c57ad26c5b9f99e0b0577933eec698531fddb472 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Thu, 4 Jul 2019 15:26:07 +0200 Subject: [PATCH] (v0.7.1.9007) mdro update --- DESCRIPTION | 4 +- NEWS.md | 4 +- R/freq.R | 22 +++++++-- R/mdro.R | 76 ++++++++++++++--------------- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 4 +- docs/news/index.html | 10 ++-- docs/reference/AMR-deprecated.html | 2 +- docs/reference/WHONET.html | 2 +- docs/reference/as.mo.html | 2 +- docs/reference/as.rsi.html | 2 +- docs/reference/count.html | 2 +- docs/reference/freq.html | 8 +-- docs/reference/ggplot_rsi.html | 2 +- docs/reference/index.html | 2 +- docs/reference/mdro.html | 45 +++++++++-------- docs/reference/mo_property.html | 2 +- docs/reference/portion.html | 2 +- docs/reference/septic_patients.html | 2 +- index.md | 2 +- man/freq.Rd | 6 +-- man/mdro.Rd | 41 ++++++++-------- tests/testthat/test-freq.R | 3 ++ tests/testthat/test-mdro.R | 12 ++--- 26 files changed, 146 insertions(+), 117 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f2e0ac7b..24a28dfa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9006 -Date: 2019-07-02 +Version: 0.7.1.9007 +Date: 2019-07-04 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index f1bff2a6..a0dd0e32 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9006 +# AMR 0.7.1.9007 ### New * 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: @@ -37,6 +37,8 @@ * Fix and speed improvement for `mo_shortname()` * Fix for `as.mo()` where misspelled input would not be understood * Fix for using `mo_*` functions where the coercion uncertainties and failures would not be available through `mo_uncertainties()` and `mo_failures()` anymore +* Deprecated the `country` parameter of `mdro()` in favour of the already existing `guideline` parameter to support multiple guidelines within one country +* Fix for frequency tables when creating one directly on a group (using `group_by()`) # AMR 0.7.1 diff --git a/R/freq.R b/R/freq.R index 91d636fe..83cadbe9 100755 --- a/R/freq.R +++ b/R/freq.R @@ -31,7 +31,7 @@ #' @param row.names a logical value indicating whether row indices should be printed as \code{1:nrow(x)} #' @param markdown a logical value indicating whether the frequency table should be printed in markdown format. This will print all rows (except when \code{nmax} is defined) and is default behaviour in non-interactive R sessions (like when knitting RMarkdown files). #' @param digits how many significant digits are to be used for numeric values in the header (not for the items themselves, that depends on \code{\link{getOption}("digits")}) -#' @param quote a logical value indicating whether or not strings should be printed with surrounding quotes +#' @param quote a logical value indicating whether or not strings should be printed with surrounding quotes. Default is to print them only around characters that are actually numeric values. #' @param header a logical value indicating whether an informative header should be printed #' @param title text to show above frequency table, at default to tries to coerce from the variables passed to \code{x} #' @param na a character string that should be used to show empty (\code{NA}) values (only useful when \code{na.rm = FALSE}) @@ -201,7 +201,7 @@ freq <- function(x, row.names = TRUE, markdown = !interactive(), digits = 2, - quote = FALSE, + quote = NULL, header = TRUE, title = NULL, na = "", @@ -218,12 +218,15 @@ freq <- function(x, cols.names <- NULL if (any(class(x) == "list")) { cols <- names(x) + cols.names <- cols x <- as.data.frame(x, stringsAsFactors = FALSE) x.name <- "a list" } else if (any(class(x) == "matrix")) { x <- as.data.frame(x, stringsAsFactors = FALSE) x.name <- "a matrix" cols <- colnames(x) + quote <- FALSE + cols.names <- cols if (all(cols %like% "V[0-9]")) { cols <- NULL } @@ -245,7 +248,7 @@ freq <- function(x, } else { x.name <- "a data.frame" } - } else { + } else if (!x.name %in% c("a list", "a matrix")) { x.name <- paste0("`", x.name, "`") } x.name.dims <- x %>% @@ -291,6 +294,11 @@ freq <- function(x, df <- x } + if (identical(x.group, cols.names)) { + # ... %>% group_by(var = calculation(..)) %>% freq(var) + x.group <- NULL + } + # support grouping variables if (length(x.group) > 0) { x.group_cols <- c(x.group, cols.names) @@ -526,6 +534,14 @@ freq <- function(x, df <- df %>% mutate(item = item %>% gsub("\033", " ", ., fixed = TRUE)) } + if (is.null(quote)) { + if (!is.numeric(df$item) & all(df$item %like% "^[0-9]+$", na.rm = TRUE)) { + quote <- TRUE + } else { + quote <- FALSE + } + } + if (quote == TRUE) { df$item <- paste0('"', df$item, '"') if (length(x.group) != 0) { diff --git a/R/mdro.R b/R/mdro.R index a34506ca..e177fe30 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -21,33 +21,36 @@ #' Determine multidrug-resistant organisms (MDRO) #' -#' Determine which isolates are multidrug-resistant organisms (MDRO) according to country-specific guidelines. +#' Determine which isolates are multidrug-resistant organisms (MDRO) according to (country-specific) guidelines. #' @param x table with antibiotic columns, like e.g. \code{AMX} and \code{AMC} -#' @param country country code to determine guidelines. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive. -#' @param guideline a specific guideline to mention. For some countries this will be determined automatically, see Details. EUCAST guidelines will be used when left empty, see Details. +#' @param guideline a specific guideline to mention, see Details. EUCAST guidelines will be used when left empty, see Details. #' @param info print progress #' @inheritParams eucast_rules #' @param verbose print additional info: missing antibiotic columns per parameter #' @inheritSection eucast_rules Antibiotics -#' @details When \code{country} is set, the parameter guideline will be ignored as these guidelines will be used: -#' +#' @details Currently supported guidelines are: #' \itemize{ -#' \item{\code{country = "nl"}: Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link})} +#' \item{\code{guideline = "EUCAST"}: EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link})} +#' \item{\code{guideline = "TB"}: World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link})} +#' \item{\code{guideline = "MRGN"}: (work in progress)} +#' \item{\code{guideline = "BRMO"}: Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link})} #' } #' -#' Please suggest your own country's specific guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}. +#' Please suggest your own (country-specific) guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}. +#' @return For TB (\code{mdr_tb()}): Ordered factor with levels \code{Negative < Mono-resistance < Poly-resistance < Multidrug resistance < Extensive drug resistance}. #' -#' Other currently supported guidelines are: -#' \itemize{ -#' \item{\code{guideline = "eucast"}: EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link})} -#' \item{\code{guideline = "tb"}: World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link})} -#' } -#' @return Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}. +#' For everything else: Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}. The value \code{"Positive, unconfirmed"} means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests. #' @rdname mdro #' @importFrom dplyr %>% #' @importFrom crayon red blue bold #' @export #' @inheritSection AMR Read more on our website! +#' @source +#' EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link}) +#' +#' World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link}) +#' +#' Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link}) #' @examples #' library(dplyr) #' @@ -55,7 +58,6 @@ #' mutate(EUCAST = mdro(.), #' BRMO = brmo(.)) mdro <- function(x, - country = NULL, guideline = NULL, col_mo = NULL, info = TRUE, @@ -66,19 +68,25 @@ mdro <- function(x, stop("`x` must be a data frame.", call. = FALSE) } + + if (!is.null(list(...)$country)) { + warning("Using `country` is deprecated, use `guideline` instead. Please see ?mdro.", call. = FALSE) + guideline <- list(...)$country + } if (length(guideline) > 1) { stop("`guideline` must be a length one character string.", call. = FALSE) } - if (length(country) > 1) { - stop("`country` must be a length one character string.", call. = FALSE) - } - if (!is.null(country)) { - guideline <- country - } + if (is.null(guideline)) { guideline <- "eucast" } - if (!tolower(guideline) %in% c("nl", "de", "eucast", "tb")) { + if (tolower(guideline) == "nl") { + guideline <- "BRMO" + } + if (tolower(guideline) == "de") { + guideline <- "MRGN" + } + if (!tolower(guideline) %in% c("brmo", "mrgn", "eucast", "tb")) { stop("invalid guideline: ", guideline, call. = FALSE) } guideline <- list(code = tolower(guideline)) @@ -90,8 +98,7 @@ mdro <- function(x, } if (is.null(col_mo) & guideline$code == "tb") { message(blue("NOTE: No column found as input for `col_mo`,", - bold("assuming all records contain", - italic("Mycobacterium tuberculosis.\n")))) + bold("assuming all records contain", italic("Mycobacterium tuberculosis.\n")))) x$mo <- AMR::as.mo("Mycobacterium tuberculosis") col_mo <- "mo" } @@ -99,10 +106,6 @@ mdro <- function(x, stop("`col_mo` must be set.", call. = FALSE) } - if (length(country) > 1) { - stop("`country` must be a length one character string.", call. = FALSE) - } - if (guideline$code == "eucast") { guideline$name <- "EUCAST Expert Rules, \"Intrinsic Resistance and Exceptional Phenotypes Tables\"" guideline$author <- "EUCAST (European Committee on Antimicrobial Susceptibility Testing)" @@ -116,19 +119,16 @@ mdro <- function(x, guideline$source <- "https://www.who.int/tb/publications/pmdt_companionhandbook/en/" # support per country: - } else if (guideline$code == "de") { + } else if (guideline$code == "mrgn") { guideline$name <- "Germany" guideline$name <- "" guideline$version <- "" guideline$source <- "" - } else if (guideline$code == "nl") { + } else if (guideline$code == "brmo") { guideline$name <- "WIP-Richtlijn Bijzonder Resistente Micro-organismen (BRMO)" guideline$author <- "RIVM (Rijksinstituut voor de Volksgezondheid)" guideline$version <- "Revision as of December 2017" guideline$source <- "https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH" - # add here more countries like this: - # } else if (country$code == "xx") { - # country$name <- "country name" } else { stop("This guideline is currently unsupported: ", guideline$code, call. = FALSE) } @@ -336,12 +336,12 @@ mdro <- function(x, "any") } - if (guideline$code == "de") { + if (guideline$code == "mrgn") { # Germany ----------------------------------------------------------------- stop("We are still working on German guidelines in this beta version.", call. = FALSE) } - if (guideline$code == "nl") { + if (guideline$code == "brmo") { # Netherlands ------------------------------------------------------------- aminoglycosides <- aminoglycosides[!is.na(aminoglycosides)] fluoroquinolones <- fluoroquinolones[!is.na(fluoroquinolones)] @@ -496,14 +496,14 @@ mdro <- function(x, #' @rdname mdro #' @export -brmo <- function(..., country = "nl") { - mdro(..., country = "nl") +brmo <- function(..., guideline = "BRMO") { + mdro(..., guideline = "BRMO") } #' @rdname mdro #' @export -mrgn <- function(x, country = "de", ...) { - mdro(x = x, country = "de", ...) +mrgn <- function(x, guideline = "MRGN", ...) { + mdro(x = x, guideline = "MRGN", ...) } #' @rdname mdro diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 8a29f7dc..2a58abe8 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9006 + 0.7.1.9007 diff --git a/docs/articles/index.html b/docs/articles/index.html index 9a136fef..4a1d6344 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9006 + 0.7.1.9007 diff --git a/docs/authors.html b/docs/authors.html index a55b79fb..4aa8c317 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9006 + 0.7.1.9007 diff --git a/docs/index.html b/docs/index.html index 32901c15..1ce0adff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9006 + 0.7.1.9007 @@ -202,7 +202,7 @@

We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and is free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. Read the full license here.

This package can be used for:

@@ -1192,7 +1194,7 @@ Using as.mo(..., allow_uncertain = 3)

Contents