mirror of
https://github.com/msberends/AMR.git
synced 2026-02-10 00:33:05 +01:00
(v3.0.1.9020) unit test fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 3.0.1.9019
|
Version: 3.0.1.9020
|
||||||
Date: 2026-02-08
|
Date: 2026-02-09
|
||||||
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
|
||||||
|
|||||||
2
NEWS.md
2
NEWS.md
@@ -1,4 +1,4 @@
|
|||||||
# AMR 3.0.1.9019
|
# AMR 3.0.1.9020
|
||||||
|
|
||||||
### New
|
### New
|
||||||
* Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes`
|
* Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes`
|
||||||
|
|||||||
@@ -498,11 +498,6 @@ word_wrap <- function(...,
|
|||||||
url = paste0("ide:help:AMR::", gsub("()", "", parts[cmds & parts %like% "[.]"], fixed = TRUE)),
|
url = paste0("ide:help:AMR::", gsub("()", "", parts[cmds & parts %like% "[.]"], fixed = TRUE)),
|
||||||
txt = parts[cmds & parts %like% "[.]"]
|
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
|
# datasets should give help page as well
|
||||||
parts[parts %in% c("antimicrobials", "microorganisms", "microorganisms.codes", "microorganisms.groups")] <- font_url(
|
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)),
|
url = paste0("ide:help:AMR::", gsub("()", "", parts[parts %in% c("antimicrobials", "microorganisms", "microorganisms.codes", "microorganisms.groups")], fixed = TRUE)),
|
||||||
|
|||||||
@@ -164,9 +164,9 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
|
|||||||
#' eucast_dosage(c("tobra", "genta", "cipro"), "iv", version_breakpoints = 10)
|
#' eucast_dosage(c("tobra", "genta", "cipro"), "iv", version_breakpoints = 10)
|
||||||
interpretive_rules <- function(x,
|
interpretive_rules <- function(x,
|
||||||
col_mo = NULL,
|
col_mo = NULL,
|
||||||
guideline = getOption("AMR_guideline", "EUCAST"),
|
|
||||||
info = interactive(),
|
info = interactive(),
|
||||||
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")),
|
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")),
|
||||||
|
guideline = getOption("AMR_guideline", "EUCAST"),
|
||||||
verbose = FALSE,
|
verbose = FALSE,
|
||||||
version_breakpoints = 15.0,
|
version_breakpoints = 15.0,
|
||||||
version_expected_phenotypes = 1.2,
|
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(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE)
|
||||||
meet_criteria(overwrite, allow_class = "logical", has_length = 1)
|
meet_criteria(overwrite, allow_class = "logical", has_length = 1)
|
||||||
|
|
||||||
|
stop_if(
|
||||||
|
guideline == "CLSI",
|
||||||
|
"CLSI guideline is not yet supported."
|
||||||
|
)
|
||||||
|
|
||||||
stop_if(
|
stop_if(
|
||||||
!is.na(ampc_cephalosporin_resistance) && !any(c("expert", "all") %in% rules),
|
!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\"`."
|
"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
|
#' @rdname interpretive_rules
|
||||||
#' @export
|
#' @export
|
||||||
eucast_rules <- function(x,
|
eucast_rules <- function(x,
|
||||||
|
col_mo = NULL,
|
||||||
|
info = interactive(),
|
||||||
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")),
|
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")),
|
||||||
...) {
|
...) {
|
||||||
if (!is.null(getOption("AMR_eucastrules", default = NULL))) {
|
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`.")
|
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
|
#' @rdname interpretive_rules
|
||||||
#' @export
|
#' @export
|
||||||
clsi_rules <- function(x,
|
clsi_rules <- function(x,
|
||||||
|
col_mo = NULL,
|
||||||
|
info = interactive(),
|
||||||
rules = getOption("AMR_interpretive_rules", default = c("breakpoints", "expected_phenotypes")),
|
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 ----
|
# helper function for editing the table ----
|
||||||
|
|||||||
@@ -314,7 +314,9 @@ antimicrobials_equal <- function(y,
|
|||||||
|
|
||||||
key2sir <- function(val) {
|
key2sir <- function(val) {
|
||||||
val <- strsplit(val, "", fixed = TRUE)[[1L]]
|
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
|
# only run on uniques
|
||||||
uniq <- unique(c(y, z))
|
uniq <- unique(c(y, z))
|
||||||
|
|||||||
Binary file not shown.
@@ -21,19 +21,21 @@ Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
\usage{
|
\usage{
|
||||||
interpretive_rules(x, col_mo = NULL, guideline = getOption("AMR_guideline",
|
interpretive_rules(x, col_mo = NULL, info = interactive(),
|
||||||
"EUCAST"), info = interactive(),
|
|
||||||
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
|
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,
|
version_expected_phenotypes = 1.2, version_expertrules = 3.3,
|
||||||
ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)),
|
ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)),
|
||||||
custom_rules = NULL, overwrite = FALSE, ...)
|
custom_rules = NULL, overwrite = FALSE, ...)
|
||||||
|
|
||||||
eucast_rules(x, rules = getOption("AMR_interpretive_rules", default =
|
eucast_rules(x, col_mo = NULL, info = interactive(),
|
||||||
c("breakpoints", "expected_phenotypes")), ...)
|
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
|
||||||
|
"expected_phenotypes")), ...)
|
||||||
|
|
||||||
clsi_rules(x, rules = getOption("AMR_interpretive_rules", default =
|
clsi_rules(x, col_mo = NULL, info = interactive(),
|
||||||
c("breakpoints", "expected_phenotypes")), ...)
|
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
|
||||||
|
"expected_phenotypes")), ...)
|
||||||
|
|
||||||
eucast_dosage(ab, administration = "iv", version_breakpoints = 15)
|
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{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{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{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{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".}
|
\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".}
|
||||||
|
|||||||
@@ -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])
|
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
|
# give host column name instead of values
|
||||||
expect_identical(
|
expect_identical(
|
||||||
out_vet,
|
out_vet,
|
||||||
as.sir(vet, host = "animal", guideline = "CLSI 2023")
|
suppressWarnings(as.sir(vet, host = "animal", guideline = "CLSI 2023"))
|
||||||
)
|
)
|
||||||
|
|
||||||
# check outcomes
|
# check outcomes
|
||||||
@@ -384,8 +384,12 @@ test_that("test-sir.R", {
|
|||||||
# ECOFF -----------------------------------------------------------------
|
# ECOFF -----------------------------------------------------------------
|
||||||
|
|
||||||
expect_equal(
|
expect_equal(
|
||||||
suppressMessages(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020", breakpoint_type = "ECOFF")),
|
suppressMessages(as.sir(as.mic(c(2, 32)), "E. coli", "ampicillin", guideline = "EUCAST 2020", breakpoint_type = "ECOFF")),
|
||||||
as.sir("S")
|
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
|
# old method
|
||||||
expect_warning(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020", ecoff = TRUE))
|
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")
|
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")
|
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")
|
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(out1, as.sir(c("NWT", "NWT", "NWT")))
|
||||||
expect_equal(out2, as.sir(c("R", "NI", "R")))
|
expect_equal(out2, as.sir(c("NWT", "NI", "NWT")))
|
||||||
expect_equal(out3, as.sir(c("R", "S", "R")))
|
expect_equal(out3, as.sir(c("NWT", "WT", "NWT")))
|
||||||
expect_equal(out4, as.sir(c("R", "S", "R")))
|
expect_equal(out4, as.sir(c("NWT", "WT", "NWT")))
|
||||||
|
|
||||||
# Parallel computing ----------------------------------------------------
|
# Parallel computing ----------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ test_that("test-translate.R", {
|
|||||||
expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (SCN)")
|
expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (SCN)")
|
||||||
expect_identical(mo_fullname("CoNS", "fi"), "Koagulaasinegatiivinen stafylokokki (KNS)")
|
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", "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", "ja"), "コアグラーゼ陰性ブドウ球菌 (グラム陰性)")
|
||||||
expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)")
|
expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)")
|
||||||
expect_identical(mo_fullname("CoNS", "no"), "Koagulase-negative stafylokokker (KNS)")
|
expect_identical(mo_fullname("CoNS", "no"), "Koagulase-negative stafylokokker (KNS)")
|
||||||
|
|||||||
Reference in New Issue
Block a user