From adee419f1cd066d2a5c9d0433f63f1f7e16d7ad8 Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Sat, 20 Sep 2025 17:14:07 +0100 Subject: [PATCH] v3.0.1 --- CRAN-SUBMISSION | 6 +++--- DESCRIPTION | 4 ++-- NAMESPACE | 2 ++ NEWS.md | 4 +++- R/ab.R | 2 +- R/mdro.R | 3 ++- R/mo.R | 2 +- R/plotting.R | 50 ++++++++++++++++++++++++++----------------------- man/plot.Rd | 44 +++++++++++++++++++++---------------------- 9 files changed, 62 insertions(+), 55 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 7d94ea663..f46166915 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 3.0.0 -Date: 2025-06-01 16:52:53 UTC -SHA: 79038fed2169a25a7fc067c80bb25d9d78be21d9 +Version: 3.0.1 +Date: 2025-09-20 10:56:46 UTC +SHA: 33fb1849eb5aa6d33828e643c8f5047dd93447e3 diff --git a/DESCRIPTION b/DESCRIPTION index 7eac5f687..e454aa3e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 3.0.0.9036 -Date: 2025-09-19 +Version: 3.0.1 +Date: 2025-09-20 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/NAMESPACE b/NAMESPACE index 1fe664c4c..25a97f715 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -373,6 +373,8 @@ if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, disk) if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, mic) if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, resistance_predict) if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, sir) +if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, mic) +if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, sir) if(getRversion() >= "3.0.0") S3method(knitr::knit_print, antibiogram) if(getRversion() >= "3.0.0") S3method(knitr::knit_print, formatted_bug_drug_combinations) if(getRversion() >= "3.0.0") S3method(pillar::pillar_shaft, ab) diff --git a/NEWS.md b/NEWS.md index dec039d0a..135cc2a0a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,11 @@ -# AMR 3.0.0.9036 +# AMR 3.0.1 This is a bugfix release following the release of v3.0.0 in June 2025. ### Changed * Fixed bugs introduced by `ggplot2` v4.0.0 (#236) + * MIC scale functions (such as `scale_y_mic()`) will now be applied automatically when plotting values of class `mic` + * SIR scale functions (such as `scale_x_sir()`) will now be applied automatically when plotting values of class `sir` * Fixed a bug in `antibiogram()` for when no antimicrobials are set * Fixed a bug in `antibiogram()` to allow column names containing the `+` character (#222) * Fixed a bug in `as.ab()` for antimicrobial codes with a number in it if they are preceded by a space diff --git a/R/ab.R b/R/ab.R index c65bcdb97..d603f035c 100755 --- a/R/ab.R +++ b/R/ab.R @@ -514,7 +514,7 @@ pillar_shaft.ab <- function(x, ...) { out[is.na(x)] <- font_na(NA) # add the names to the drugs as mouse-over! - if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) { + if (in_rstudio()) { out[!is.na(x)] <- font_url( url = paste0(x[!is.na(x)], ": ", ab_name(x[!is.na(x)])), txt = out[!is.na(x)] diff --git a/R/mdro.R b/R/mdro.R index 996b95dbb..09a075840 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -1499,12 +1499,13 @@ mdro <- function(x = NULL, any_all = "any", reason = "Enterobacterales: carbapenemase" ) + c.freundii_complex <- AMR::microorganisms.groups$mo_name[AMR::microorganisms.groups$mo_group_name == "Citrobacter freundii complex"] trans_tbl( 3, rows = which(col_values(x, SXT) == "R" & (col_values(x, GEN) == "R" | col_values(x, TOB) == "R" | col_values(x, AMK) == "R") & (col_values(x, CIP) == "R" | col_values(x, NOR) == "R" | col_values(x, LVX) == "R") & - (x$genus %in% c("Enterobacter", "Providencia") | paste(x$genus, x$species) %in% c("Citrobacter freundii", "Klebsiella aerogenes", "Hafnia alvei", "Morganella morganii"))), + (x$genus %in% c("Enterobacter", "Providencia") | paste(x$genus, x$species) %in% c(c.freundii_complex, "Klebsiella aerogenes", "Hafnia alvei", "Morganella morganii"))), cols = c(SXT, aminoglycosides, fluoroquinolones), any_all = "any", reason = "Enterobacterales group II: aminoglycoside + fluoroquinolone + cotrimoxazol" diff --git a/R/mo.R b/R/mo.R index dbfbf01dc..19159f9eb 100755 --- a/R/mo.R +++ b/R/mo.R @@ -675,7 +675,7 @@ pillar_shaft.mo <- function(x, ...) { } # add the names to the bugs as mouse-over! - if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) { + if (in_rstudio()) { out[!x %in% c("UNKNOWN", NA)] <- font_url( url = paste0( x[!x %in% c("UNKNOWN", NA)], ": ", diff --git a/R/plotting.R b/R/plotting.R index f6cb0d606..0fc2760a2 100755 --- a/R/plotting.R +++ b/R/plotting.R @@ -52,11 +52,19 @@ #' @details #' ### The `scale_*_mic()` Functions #' -#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] functions allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale. They also allow to rescale the MIC range with an 'inside' or 'outside' range if required, and retain the operators in MIC values (such as `>=`) if desired. Missing intermediate log2 levels will be plotted too. +#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] functions allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale. +#' +#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [mic][as.mic()]. +#' +#' When manually added though, they allow to rescale the MIC range with an 'inside' or 'outside' range if required, and provide the option to retain the operators in MIC values (such as `>=`). Missing intermediate log2 levels will always be plotted too. #' #' ### The `scale_*_sir()` Functions #' -#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] functions allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`). At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the `r length(AMR:::LANGUAGES_SUPPORTED)` supported languages (use `language = NULL` to keep S/I/R). Also, except for [scale_x_sir()], they set colour-blind friendly colours to the `colour` and `fill` aesthetics. +#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] functions allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`). +#' +#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [sir][as.sir()]. +#' +#' At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the `r length(AMR:::LANGUAGES_SUPPORTED)` supported languages (use `language = NULL` to keep S/I/R). Also, except for [scale_x_sir()], they set colour-blind friendly colours to the `colour` and `fill` aesthetics. #' #' ### Additional `ggplot2` Functions #' @@ -114,17 +122,12 @@ #' ) + #' geom_col() #' mic_plot + -#' labs(title = "without scale_x_mic()") +#' labs(title = "scale_x_mic() automatically applied") #' } #' if (require("ggplot2")) { #' mic_plot + -#' scale_x_mic() + -#' labs(title = "with scale_x_mic()") -#' } -#' if (require("ggplot2")) { -#' mic_plot + -#' scale_x_mic(keep_operators = "all") + -#' labs(title = "with scale_x_mic() keeping all operators") +#' scale_x_mic(keep_operators = "none") + +#' labs(title = "with scale_x_mic() keeping no operators") #' } #' if (require("ggplot2")) { #' mic_plot + @@ -151,7 +154,7 @@ #' ) + #' geom_boxplot() + #' geom_violin(linetype = 2, colour = "grey30", fill = NA) + -#' scale_y_mic() +#' labs(title = "scale_y_mic() automatically applied") #' } #' if (require("ggplot2")) { #' ggplot( @@ -183,7 +186,7 @@ #' #' # Plotting using scale_y_mic() and scale_colour_sir() ------------------ #' if (require("ggplot2")) { -#' plain <- ggplot( +#' mic_sir_plot <- ggplot( #' data.frame( #' mic = some_mic_values, #' group = some_groups, @@ -197,21 +200,16 @@ #' theme_minimal() + #' geom_boxplot(fill = NA, colour = "grey30") + #' geom_jitter(width = 0.25) -#' -#' plain +#' labs(title = "scale_y_mic()/scale_colour_sir() automatically applied") +#' +#' mic_sir_plot #' } #' if (require("ggplot2")) { -#' # and now with our MIC and SIR scale functions: -#' plain + -#' scale_y_mic() + -#' scale_colour_sir() -#' } -#' if (require("ggplot2")) { -#' plain + +#' mic_sir_plot + #' scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") + #' scale_colour_sir( -#' language = "pt", -#' name = "Support in 27 languages" +#' language = "pt", # Portuguese +#' name = "Support in 28 languages" #' ) #' } #' } @@ -229,6 +227,9 @@ #' plot(some_sir_values) NULL +#' @rawNamespace if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, mic) +scale_type.mic <- function(x) c("mic", "discrete") + create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) { ggplot_fn <- getExportedValue(paste0("scale_", aest, "_continuous"), ns = asNamespace("ggplot2") @@ -381,6 +382,9 @@ scale_fill_mic <- function(keep_operators = "edges", mic_range = NULL, ...) { create_scale_mic("fill", keep_operators = keep_operators, mic_range = mic_range, ...) } +#' @rawNamespace if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, sir) +scale_type.sir <- function(x) c("sir", "discrete") + create_scale_sir <- function(aesthetics, colours_SIR, language, eucast_I, ...) { args <- list(...) args[c("value", "labels", "limits")] <- NULL diff --git a/man/plot.Rd b/man/plot.Rd index c8757d275..3729cad49 100644 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -172,12 +172,20 @@ Especially the \verb{scale_*_mic()} functions are relevant wrappers to plot MIC \details{ \subsection{The \verb{scale_*_mic()} Functions}{ -The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} functions allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale. They also allow to rescale the MIC range with an 'inside' or 'outside' range if required, and retain the operators in MIC values (such as \code{>=}) if desired. Missing intermediate log2 levels will be plotted too. +The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} functions allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale. + +There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.mic]{mic}. + +When manually added though, they allow to rescale the MIC range with an 'inside' or 'outside' range if required, and provide the option to retain the operators in MIC values (such as \code{>=}). Missing intermediate log2 levels will always be plotted too. } \subsection{The \verb{scale_*_sir()} Functions}{ -The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} functions allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI). At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the 28 supported languages (use \code{language = NULL} to keep S/I/R). Also, except for \code{\link[=scale_x_sir]{scale_x_sir()}}, they set colour-blind friendly colours to the \code{colour} and \code{fill} aesthetics. +The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} functions allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI). + +There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.sir]{sir}. + +At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the 28 supported languages (use \code{language = NULL} to keep S/I/R). Also, except for \code{\link[=scale_x_sir]{scale_x_sir()}}, they set colour-blind friendly colours to the \code{colour} and \code{fill} aesthetics. } \subsection{Additional \code{ggplot2} Functions}{ @@ -235,17 +243,12 @@ if (require("ggplot2")) { ) + geom_col() mic_plot + - labs(title = "without scale_x_mic()") + labs(title = "scale_x_mic() automatically applied") } if (require("ggplot2")) { mic_plot + - scale_x_mic() + - labs(title = "with scale_x_mic()") -} -if (require("ggplot2")) { - mic_plot + - scale_x_mic(keep_operators = "all") + - labs(title = "with scale_x_mic() keeping all operators") + scale_x_mic(keep_operators = "none") + + labs(title = "with scale_x_mic() keeping no operators") } if (require("ggplot2")) { mic_plot + @@ -272,7 +275,7 @@ if (require("ggplot2")) { ) + geom_boxplot() + geom_violin(linetype = 2, colour = "grey30", fill = NA) + - scale_y_mic() + labs(title = "scale_y_mic() automatically applied") } if (require("ggplot2")) { ggplot( @@ -304,7 +307,7 @@ if (require("ggplot2")) { # Plotting using scale_y_mic() and scale_colour_sir() ------------------ if (require("ggplot2")) { - plain <- ggplot( + mic_sir_plot <- ggplot( data.frame( mic = some_mic_values, group = some_groups, @@ -318,21 +321,16 @@ if (require("ggplot2")) { theme_minimal() + geom_boxplot(fill = NA, colour = "grey30") + geom_jitter(width = 0.25) - - plain + labs(title = "scale_y_mic()/scale_colour_sir() automatically applied") + + mic_sir_plot } if (require("ggplot2")) { - # and now with our MIC and SIR scale functions: - plain + - scale_y_mic() + - scale_colour_sir() -} -if (require("ggplot2")) { - plain + + mic_sir_plot + scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") + scale_colour_sir( - language = "pt", - name = "Support in 27 languages" + language = "pt", # Portuguese + name = "Support in 28 languages" ) } }