diff --git a/DESCRIPTION b/DESCRIPTION index 943f76434..03430d621 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 3.0.1.9019 -Date: 2026-02-08 +Version: 3.0.1.9020 +Date: 2026-02-09 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 0d71f378f..0ce89e0e0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 3.0.1.9019 +# AMR 3.0.1.9020 ### New * Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes` diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index f32e2f0fd..9c13f8632 100644 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -498,11 +498,6 @@ word_wrap <- function(..., url = paste0("ide:help:AMR::", gsub("()", "", parts[cmds & parts %like% "[.]"], fixed = TRUE)), txt = parts[cmds & parts %like% "[.]"] ) - # otherwise, give a 'click to run' popup - parts[cmds & parts %unlike% "[.]"] <- font_url( - url = paste0("ide:run:AMR::", parts[cmds & parts %unlike% "[.]"]), - txt = parts[cmds & parts %unlike% "[.]"] - ) # datasets should give help page as well parts[parts %in% c("antimicrobials", "microorganisms", "microorganisms.codes", "microorganisms.groups")] <- font_url( url = paste0("ide:help:AMR::", gsub("()", "", parts[parts %in% c("antimicrobials", "microorganisms", "microorganisms.codes", "microorganisms.groups")], fixed = TRUE)), diff --git a/R/interpretive_rules.R b/R/interpretive_rules.R index 1e709e066..02b3094ae 100755 --- a/R/interpretive_rules.R +++ b/R/interpretive_rules.R @@ -164,9 +164,9 @@ format_eucast_version_nr <- function(version, markdown = TRUE) { #' eucast_dosage(c("tobra", "genta", "cipro"), "iv", version_breakpoints = 10) interpretive_rules <- function(x, col_mo = NULL, - guideline = getOption("AMR_guideline", "EUCAST"), info = interactive(), rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")), + guideline = getOption("AMR_guideline", "EUCAST"), verbose = FALSE, version_breakpoints = 15.0, version_expected_phenotypes = 1.2, @@ -190,6 +190,11 @@ interpretive_rules <- function(x, meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE) meet_criteria(overwrite, allow_class = "logical", has_length = 1) + stop_if( + guideline == "CLSI", + "CLSI guideline is not yet supported." + ) + stop_if( !is.na(ampc_cephalosporin_resistance) && !any(c("expert", "all") %in% rules), "For the `ampc_cephalosporin_resistance` argument to work, the `rules` argument must contain `\"expert\"` or `\"all\"`." @@ -1103,20 +1108,24 @@ interpretive_rules <- function(x, #' @rdname interpretive_rules #' @export eucast_rules <- function(x, + col_mo = NULL, + info = interactive(), rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")), ...) { if (!is.null(getOption("AMR_eucastrules", default = NULL))) { warning_("The global option `AMR_eucastrules` that you have set is now invalid was ignored - set `AMR_interpretive_rules` instead. See `?AMR-options`.") } - interpretive_rules(x = x, guideline = "EUCAST", rules = rules, ...) + interpretive_rules(x = x, col_mo = col_mo, info = info, rules = rules, guideline = "EUCAST", ...) } #' @rdname interpretive_rules #' @export clsi_rules <- function(x, + col_mo = NULL, + info = interactive(), rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")), ...) { - interpretive_rules(x = x, guideline = "CLSI", rules = rules, ...) + interpretive_rules(x = x, col_mo = col_mo, info = info, rules = rules, guideline = "CLSI", ...) } # helper function for editing the table ---- diff --git a/R/key_antimicrobials.R b/R/key_antimicrobials.R index 1ead34817..516b527fc 100755 --- a/R/key_antimicrobials.R +++ b/R/key_antimicrobials.R @@ -314,7 +314,9 @@ antimicrobials_equal <- function(y, key2sir <- function(val) { val <- strsplit(val, "", fixed = TRUE)[[1L]] - as.double(as.sir(val)) + val.int <- rep(NA_real_, length(val)) + val.int[val %in% VALID_SIR_LEVELS] <- as.double(as.sir(val[val %in% VALID_SIR_LEVELS])) + val.int } # only run on uniques uniq <- unique(c(y, z)) diff --git a/data/example_isolates.rda b/data/example_isolates.rda index bb1308843..034e147a4 100644 Binary files a/data/example_isolates.rda and b/data/example_isolates.rda differ diff --git a/man/interpretive_rules.Rd b/man/interpretive_rules.Rd index cbeda0052..da41a05cc 100644 --- a/man/interpretive_rules.Rd +++ b/man/interpretive_rules.Rd @@ -21,19 +21,21 @@ Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility test } } \usage{ -interpretive_rules(x, col_mo = NULL, guideline = getOption("AMR_guideline", - "EUCAST"), info = interactive(), +interpretive_rules(x, col_mo = NULL, info = interactive(), rules = getOption("AMR_interpretive_rules", default = c("breakpoints", - "expected_phenotypes")), verbose = FALSE, version_breakpoints = 15, + "expected_phenotypes")), guideline = getOption("AMR_guideline", "EUCAST"), + verbose = FALSE, version_breakpoints = 15, version_expected_phenotypes = 1.2, version_expertrules = 3.3, ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)), custom_rules = NULL, overwrite = FALSE, ...) -eucast_rules(x, rules = getOption("AMR_interpretive_rules", default = - c("breakpoints", "expected_phenotypes")), ...) +eucast_rules(x, col_mo = NULL, info = interactive(), + rules = getOption("AMR_interpretive_rules", default = c("breakpoints", + "expected_phenotypes")), ...) -clsi_rules(x, rules = getOption("AMR_interpretive_rules", default = - c("breakpoints", "expected_phenotypes")), ...) +clsi_rules(x, col_mo = NULL, info = interactive(), + rules = getOption("AMR_interpretive_rules", default = c("breakpoints", + "expected_phenotypes")), ...) eucast_dosage(ab, administration = "iv", version_breakpoints = 15) } @@ -42,12 +44,12 @@ eucast_dosage(ab, administration = "iv", version_breakpoints = 15) \item{col_mo}{Column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} -\item{guideline}{A guideline name, either "EUCAST" (default) or "CLSI". This can be set with the package option \code{\link[=AMR-options]{AMR_guideline}}.} - \item{info}{A \link{logical} to indicate whether progress should be printed to the console - the default is only print while in interactive sessions.} \item{rules}{A \link{character} vector that specifies which rules should be applied. Must be one or more of \code{"breakpoints"}, \code{"expected_phenotypes"}, \code{"expert"}, \code{"other"}, \code{"custom"}, \code{"all"}, and defaults to \code{c("breakpoints", "expected_phenotypes")}. The default value can be set to another value using the package option \code{\link[=AMR-options]{AMR_interpretive_rules}}: \code{options(AMR_interpretive_rules = "all")}. If using \code{"custom"}, be sure to fill in argument \code{custom_rules} too. Custom rules can be created with \code{\link[=custom_eucast_rules]{custom_eucast_rules()}}.} +\item{guideline}{A guideline name, either "EUCAST" (default) or "CLSI". This can be set with the package option \code{\link[=AMR-options]{AMR_guideline}}.} + \item{verbose}{A \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.} \item{version_breakpoints}{The version number to use for the EUCAST Clinical Breakpoints guideline. Can be "15.0", "14.0", "13.1", "12.0", "11.0", or "10.0".} diff --git a/tests/testthat/test-sir.R b/tests/testthat/test-sir.R index 889e823ed..1b38d1e24 100644 --- a/tests/testthat/test-sir.R +++ b/tests/testthat/test-sir.R @@ -354,11 +354,11 @@ test_that("test-sir.R", { mo = mo_name(rep(c("B_ESCHR_COLI", "B_PSTRL_MLTC", "B_MNNHM_HMLY"), 4)[-1]) ) - out_vet <- as.sir(vet, host = vet$animal, guideline = "CLSI 2023") + out_vet <- suppressWarnings(as.sir(vet, host = vet$animal, guideline = "CLSI 2023")) # give host column name instead of values expect_identical( out_vet, - as.sir(vet, host = "animal", guideline = "CLSI 2023") + suppressWarnings(as.sir(vet, host = "animal", guideline = "CLSI 2023")) ) # check outcomes @@ -384,8 +384,12 @@ test_that("test-sir.R", { # ECOFF ----------------------------------------------------------------- expect_equal( - suppressMessages(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020", breakpoint_type = "ECOFF")), - as.sir("S") + suppressMessages(as.sir(as.mic(c(2, 32)), "E. coli", "ampicillin", guideline = "EUCAST 2020", breakpoint_type = "ECOFF")), + as.sir(c("WT", "NWT")) # since ECOFF returns WT/NWT at default + ) + expect_equal( + suppressMessages(as.sir(as.mic(c(2, 32)), "E. coli", "ampicillin", guideline = "EUCAST 2020", breakpoint_type = "ECOFF", as_wt_nwt = FALSE)), + as.sir(c("S", "R")) ) # old method expect_warning(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020", ecoff = TRUE)) @@ -397,10 +401,10 @@ test_that("test-sir.R", { out2 <- as.sir(as.mic(c("0.125", "<0.125", ">0.125")), mo = "E. coli", ab = "Cipro", guideline = "EUCAST 2025", breakpoint_type = "ECOFF", capped_mic_handling = "conservative") out3 <- as.sir(as.mic(c("0.125", "<0.125", ">0.125")), mo = "E. coli", ab = "Cipro", guideline = "EUCAST 2025", breakpoint_type = "ECOFF", capped_mic_handling = "standard") out4 <- as.sir(as.mic(c("0.125", "<0.125", ">0.125")), mo = "E. coli", ab = "Cipro", guideline = "EUCAST 2025", breakpoint_type = "ECOFF", capped_mic_handling = "lenient") - expect_equal(out1, as.sir(c("R", "R", "R"))) - expect_equal(out2, as.sir(c("R", "NI", "R"))) - expect_equal(out3, as.sir(c("R", "S", "R"))) - expect_equal(out4, as.sir(c("R", "S", "R"))) + expect_equal(out1, as.sir(c("NWT", "NWT", "NWT"))) + expect_equal(out2, as.sir(c("NWT", "NI", "NWT"))) + expect_equal(out3, as.sir(c("NWT", "WT", "NWT"))) + expect_equal(out4, as.sir(c("NWT", "WT", "NWT"))) # Parallel computing ---------------------------------------------------- diff --git a/tests/testthat/test-translate.R b/tests/testthat/test-translate.R index 28dae6721..a22ad14ac 100644 --- a/tests/testthat/test-translate.R +++ b/tests/testthat/test-translate.R @@ -40,7 +40,7 @@ test_that("test-translate.R", { expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (SCN)") expect_identical(mo_fullname("CoNS", "fi"), "Koagulaasinegatiivinen stafylokokki (KNS)") expect_identical(mo_fullname("CoNS", "fr"), "Staphylococcus à coagulase négative (CoNS)") - expect_identical(mo_fullname("CoNS", "it"), "Staphylococcus negativo coagulasi (CoNS)") + expect_identical(mo_fullname("CoNS", "it"), "Stafilococco coagulasi-negativo (CoNS)") expect_identical(mo_fullname("CoNS", "ja"), "コアグラーゼ陰性ブドウ球菌 (グラム陰性)") expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)") expect_identical(mo_fullname("CoNS", "no"), "Koagulase-negative stafylokokker (KNS)")