From d4490c7f25ec38a211c41719aa94e3d5ca776e8e Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Thu, 30 May 2024 15:50:17 +0200 Subject: [PATCH] fix sorting of MICs, MIC autoplot titles --- DESCRIPTION | 4 ++-- NEWS.md | 3 ++- R/eucast_rules.R | 1 + R/mic.R | 11 ++++++++--- R/plot.R | 2 +- R/sir.R | 3 +++ R/vctrs.R | 2 +- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5449f6f4..0f0ff48a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 2.1.1.9033 -Date: 2024-05-24 +Version: 2.1.1.9034 +Date: 2024-05-30 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index c685ffb2..363258d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9033 +# AMR 2.1.1.9034 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support!)* @@ -26,6 +26,7 @@ This package now supports not only tools for AMR data analysis in clinical setti * Added as valid levels: 4096, 6 powers of 0.0625, and 5 powers of 192 (192, 384, 576, 768, 960) * Added new argument `keep_operators` to `as.mic()`. This can be `"all"` (default), `"none"`, or `"edges"`. This argument is also available in the new `rescale_mic()` and `scale_*_mic()` functions. * Comparisons of MIC values are now more strict. For example, `>32` is higher than (and never equal to) `32`. Thus, `as.mic(">32") == as.mic(32)` now returns `FALSE`, and `as.mic(">32") > as.mic(32)` now returns `TRUE`. + * Sorting of MIC values (using `sort()`) was fixed in the same manner; `<0.001` now gets sorted before `0.001`, and `>0.001` gets sorted after `0.001`. * Updated `italicise_taxonomy()` to support HTML output * `mo_info()` now contains an extra element `group_members`, with the contents of the new `mo_group_members()` function * Greatly improved `vctrs` integration, a Tidyverse package working in the background for many Tidyverse functions. For users, this means that functions such as `dplyr`'s `bind_rows()`, `rowwise()` and `c_across()` are now supported for e.g. columns of class `mic`. Despite this, this `AMR` package is still zero-dependent on any other package, including `dplyr` and `vctrs`. diff --git a/R/eucast_rules.R b/R/eucast_rules.R index a9567b4d..c74c05d8 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -889,6 +889,7 @@ eucast_rules <- function(x, ), type = "ansi" )) + cat("\n") warned <- FALSE } run_changes <- edit_sir( diff --git a/R/mic.R b/R/mic.R index 653d64a3..5c7efa03 100644 --- a/R/mic.R +++ b/R/mic.R @@ -495,12 +495,17 @@ rep.mic <- function(x, ...) { #' @noRd sort.mic <- function(x, decreasing = FALSE, ...) { x <- as.mic(x) # make sure that currently implemented MIC levels are used + dbl <- as.double(x) + # make sure that e.g. '<0.001' comes before '0.001', and '>0.001' comes after + dbl[as.character(x) %like% "<[0-9]"] <- dbl[as.character(x) %like% "<[0-9]"] - 0.000002 + dbl[as.character(x) %like% "<="] <- dbl[as.character(x) %like% "<="] - 0.000001 + dbl[as.character(x) %like% ">="] <- dbl[as.character(x) %like% ">="] + 0.000001 + dbl[as.character(x) %like% ">[0-9]"] <- dbl[as.character(x) %like% ">[0-9]"] + 0.000002 if (decreasing == TRUE) { - ord <- order(-as.double(x)) + x[order(-dbl)] } else { - ord <- order(as.double(x)) + x[order(dbl)] } - x[ord] } #' @method hist mic diff --git a/R/plot.R b/R/plot.R index 07e7ac82..92da3a38 100755 --- a/R/plot.R +++ b/R/plot.R @@ -309,7 +309,6 @@ autoplot.mic <- function(object, breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...) { stop_ifnot_installed("ggplot2") - object <- as.mic(object) # make sure that currently implemented MIC levels are used meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) @@ -327,6 +326,7 @@ autoplot.mic <- function(object, title <- gsub(" +", " ", paste0(title, collapse = " ")) } + object <- as.mic(object) # make sure that currently implemented MIC levels are used x <- range_as_table(object, expand = expand) cols_sub <- plot_colours_subtitle_guideline( x = x, diff --git a/R/sir.R b/R/sir.R index 4232e070..d264514f 100755 --- a/R/sir.R +++ b/R/sir.R @@ -884,6 +884,9 @@ as_sir_method <- function(method_short, if (length(mo) == 1) { mo <- rep(mo, length(x)) } + if (length(ab) == 1) { + ab <- rep(ab, length(x)) + } if (is.null(uti)) { uti <- NA } diff --git a/R/vctrs.R b/R/vctrs.R index bb2e2268..dd86f5c3 100755 --- a/R/vctrs.R +++ b/R/vctrs.R @@ -106,7 +106,7 @@ vec_ptype_full.disk <- function(x, ...) { "disk" } vec_ptype_abbr.disk <- function(x, ...) { - "disk" + "dsk" } vec_ptype2.disk.default <- function (x, y, ..., x_arg = "", y_arg = "") { x