fix sorting of MICs, MIC autoplot titles

This commit is contained in:
dr. M.S. (Matthijs) Berends 2024-05-30 15:50:17 +02:00
parent c3ce1b551d
commit d4490c7f25
7 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 2.1.1.9033 Version: 2.1.1.9034
Date: 2024-05-24 Date: 2024-05-30
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@ -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!)* *(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 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. * 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`. * 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 * 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 * `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`. * 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`.

View File

@ -889,6 +889,7 @@ eucast_rules <- function(x,
), ),
type = "ansi" type = "ansi"
)) ))
cat("\n")
warned <- FALSE warned <- FALSE
} }
run_changes <- edit_sir( run_changes <- edit_sir(

11
R/mic.R
View File

@ -495,12 +495,17 @@ rep.mic <- function(x, ...) {
#' @noRd #' @noRd
sort.mic <- function(x, decreasing = FALSE, ...) { sort.mic <- function(x, decreasing = FALSE, ...) {
x <- as.mic(x) # make sure that currently implemented MIC levels are used 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) { if (decreasing == TRUE) {
ord <- order(-as.double(x)) x[order(-dbl)]
} else { } else {
ord <- order(as.double(x)) x[order(dbl)]
} }
x[ord]
} }
#' @method hist mic #' @method hist mic

View File

@ -309,7 +309,6 @@ autoplot.mic <- function(object,
breakpoint_type = getOption("AMR_breakpoint_type", "human"), breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...) { ...) {
stop_ifnot_installed("ggplot2") 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(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
meet_criteria(guideline, allow_class = "character", has_length = 1) meet_criteria(guideline, allow_class = "character", has_length = 1)
@ -327,6 +326,7 @@ autoplot.mic <- function(object,
title <- gsub(" +", " ", paste0(title, collapse = " ")) 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) x <- range_as_table(object, expand = expand)
cols_sub <- plot_colours_subtitle_guideline( cols_sub <- plot_colours_subtitle_guideline(
x = x, x = x,

View File

@ -884,6 +884,9 @@ as_sir_method <- function(method_short,
if (length(mo) == 1) { if (length(mo) == 1) {
mo <- rep(mo, length(x)) mo <- rep(mo, length(x))
} }
if (length(ab) == 1) {
ab <- rep(ab, length(x))
}
if (is.null(uti)) { if (is.null(uti)) {
uti <- NA uti <- NA
} }

View File

@ -106,7 +106,7 @@ vec_ptype_full.disk <- function(x, ...) {
"disk" "disk"
} }
vec_ptype_abbr.disk <- function(x, ...) { vec_ptype_abbr.disk <- function(x, ...) {
"disk" "dsk"
} }
vec_ptype2.disk.default <- function (x, y, ..., x_arg = "", y_arg = "") { vec_ptype2.disk.default <- function (x, y, ..., x_arg = "", y_arg = "") {
x x