1
0
mirror of https://github.com/msberends/AMR.git synced 2025-09-30 02:49:03 +02:00
This commit is contained in:
2025-09-20 17:14:07 +01:00
parent 33fb1849eb
commit adee419f1c
9 changed files with 62 additions and 55 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

2
R/ab.R
View File

@@ -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)]

View File

@@ -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"

2
R/mo.R
View File

@@ -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)], ": ",

View File

@@ -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

View File

@@ -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"
)
}
}