diff --git a/DESCRIPTION b/DESCRIPTION index f2d93e9f0..575e6fc58 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 3.0.0.9030 -Date: 2025-09-11 +Version: 3.0.0.9031 +Date: 2025-09-12 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 @@ -70,5 +70,5 @@ BugReports: https://github.com/msberends/AMR/issues License: GPL-2 | file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE, old_usage = TRUE) diff --git a/NEWS.md b/NEWS.md index 418492f53..fd97c0436 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,9 @@ -# AMR 3.0.0.9030 +# AMR 3.0.0.9031 This is a bugfix release following the release of v3.0.0 in June 2025. ### Changed +* Allow support for newest `ggplot2` v4.0.0 * 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/plotting.R b/R/plotting.R index 81464e18e..3e2e1c195 100755 --- a/R/plotting.R +++ b/R/plotting.R @@ -247,6 +247,7 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) { as.double(rescale_mic(x = as.double(as.mic(x)), keep_operators = keep_operators, mic_range = mic_range, as.mic = TRUE)) } scale$transform_df <- function(self, df) { + out <- list() if (!aest %in% colnames(df)) { # support for geom_hline(), geom_vline(), etc other_x <- c("xintercept", "xmin", "xmax", "xend", "width") @@ -258,11 +259,11 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) { } else { stop_("No support for plotting df with `scale_", aest, "_mic()` with columns ", vector_and(colnames(df), sort = FALSE)) } - out <- rescale_mic(x = as.double(as.mic(df[[aest_val]])), keep_operators = "none", mic_range = NULL, as.mic = TRUE) - if (!is.null(self$mic_values_rescaled) && any(out < min(self$mic_values_rescaled, na.rm = TRUE) | out > max(self$mic_values_rescaled, na.rm = TRUE), na.rm = TRUE)) { + mics <- rescale_mic(x = as.double(as.mic(df[[aest_val]])), keep_operators = "none", mic_range = NULL, as.mic = TRUE) + if (!is.null(self$mic_values_rescaled) && any(mics < min(self$mic_values_rescaled, na.rm = TRUE) | mics > max(self$mic_values_rescaled, na.rm = TRUE), na.rm = TRUE)) { warning_("The value for `", aest_val, "` is outside the plotted MIC range, consider using/updating the `mic_range` argument in `scale_", aest, "_mic()`.") } - df[[aest_val]] <- log2(as.double(out)) + out[[aest_val]] <- log2(as.double(mics)) } else { self$mic_values_rescaled <- rescale_mic(x = as.double(as.mic(df[[aest]])), keep_operators = keep_operators, mic_range = mic_range, as.mic = TRUE) # create new breaks and labels here @@ -286,11 +287,11 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) { self$mic_values_log <- log2(as.double(self$mic_values_rescaled)) if (aest == "y" && "group" %in% colnames(df) && "x" %in% colnames(df)) { - df$group <- as.integer(factor(df$x)) + out$group <- as.integer(factor(df$x)) } - df[[aest]] <- self$mic_values_log + out[[aest]] <- self$mic_values_log } - df + out } scale$breaks <- function(..., self) { @@ -317,7 +318,6 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) { } } } - scale$limits <- function(x, ..., self) { if (!is.null(self$mic_limits_set)) { if (is.function(self$mic_limits_set)) { diff --git a/tests/testthat/test-_misc.R b/tests/testthat/test-_misc.R index 024ae0518..da6e9d3db 100755 --- a/tests/testthat/test-_misc.R +++ b/tests/testthat/test-_misc.R @@ -77,7 +77,7 @@ test_that("test-misc.R", { if (!is_right) { # otherwise, this is needed for older versions df <- example_isolates[c(1:3), check_df("xx")] - expect_true(is_right, info = "the environmental data cannot be found for base `x` or `xx`") + expect_true(is_right, info = "the environmental data cannot be found for base `x` or `xx`") } if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {