Let aggregated analyses follow the guideline for the 'I' category in count_df(), proportion_df(), sir_df(), the plotting functions, antibiogram(), wisca(), and bug_drug_combinations(), deprecate combine_SI in favour of guideline, fix format() on bug_drug_combinations() counting I as resistant, and add a shared section 'Interpretation of SIR'

This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2026-10-15 09:58:21 +02:00
1 parent dbd95ffa46
commit 0efc8826c8
32 files changed
+511 -199

No files matched your search

+10
View File
@@ -30,6 +30,16 @@
test_that("test-antibiogram.R", {
skip_on_cran()
# 'I' follows the guideline, see section 'Interpretation of SIR' in ?as.sir
get_gen <- function(...) suppressWarnings(antibiogram(example_isolates, antimicrobials = "GEN", ab_transform = NULL, formatting_type = 1, ...))$GEN
gen_eucast <- get_gen(guideline = "EUCAST")
gen_clsi <- get_gen(guideline = "CLSI")
expect_true(all(gen_eucast >= gen_clsi, na.rm = TRUE) && any(gen_eucast > gen_clsi, na.rm = TRUE))
expect_error(antibiogram(example_isolates, antimicrobials = "GEN", guideline = NULL))
# the deprecated combine_SI must be followed literally if set, regardless of the guideline
expect_identical(get_gen(combine_SI = TRUE, guideline = "CLSI"), gen_eucast)
expect_identical(get_gen(combine_SI = FALSE, guideline = "EUCAST"), gen_clsi) # identical since example_isolates contains no SDD
# Traditional antibiogram ----------------------------------------------
@@ -35,6 +35,24 @@ test_that("test-bug/drug.R", {
expect_output(suppressMessages(print(b)))
expect_true(is.data.frame(format(b)))
expect_true(is.data.frame(format(b, add_ab_group = FALSE)))
# format() calculates resistance following the guideline, taken from bug_drug_combinations() unless set
b_eucast <- suppressMessages(bug_drug_combinations(example_isolates, FUN = function(x) x, guideline = "EUCAST"))
b_clsi <- suppressMessages(bug_drug_combinations(example_isolates, FUN = function(x) x, guideline = "CLSI"))
expect_identical(attr(b_clsi, "guideline"), "CLSI")
cons_gen <- subset(b_eucast, mo == "B_STPHY_CONS" & ab == "GEN")
n_R <- cons_gen$R + cons_gen$NWT + cons_gen$NS
n_IR <- n_R + cons_gen$I
get_cons_gen <- function(f) f[f$Drug %like% "GEN", "B_STPHY_CONS", drop = TRUE]
expect_true(grepl(paste0("(", n_R, "/", cons_gen$total, ")"), get_cons_gen(format(b_eucast, translate_ab = "ab", language = "en")), fixed = TRUE))
expect_true(grepl(paste0("(", n_IR, "/", cons_gen$total, ")"), get_cons_gen(format(b_clsi, translate_ab = "ab", language = "en")), fixed = TRUE))
expect_identical(format(b_eucast, guideline = "CLSI"), format(b_clsi))
# with guideline = NULL, format() requires its own guideline
b_none <- suppressMessages(bug_drug_combinations(example_isolates, FUN = function(x) x, guideline = NULL))
expect_error(format(b_none))
expect_identical(format(b_none, guideline = "CLSI"), format(b_clsi))
# the deprecated combine_SI must be followed literally if set, regardless of the guideline
expect_identical(suppressWarnings(format(b_clsi, combine_SI = TRUE)), format(b_eucast))
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_true(example_isolates %>%
group_by(ward) %>%
+14 -1
View File
@@ -111,14 +111,27 @@ test_that("test-count.R", {
old_opts <- options(AMR_guideline = "CLSI")
expect_identical(count_df(example_isolates[, "AMX"]), count_df(example_isolates[, "AMX"], guideline = "CLSI"))
options(old_opts)
# guideline = NULL or FALSE keeps S, I, and R separate
expect_equal(
example_isolates %>% select(AMX) %>% count_df(combine_SI = FALSE) %>% pull(value),
example_isolates %>% select(AMX) %>% count_df(guideline = NULL) %>% pull(value),
c(
suppressWarnings(example_isolates$AMX %>% count_S()),
example_isolates$AMX %>% count_I(),
example_isolates$AMX %>% count_R()
)
)
expect_identical(count_df(example_isolates[, "AMX"], guideline = FALSE), count_df(example_isolates[, "AMX"], guideline = NULL))
expect_error(count_df(example_isolates[, "AMX"], guideline = "WHO"))
expect_error(count_susceptible(example_isolates$AMX, guideline = NULL))
# the deprecated combine_SI must be followed literally if set, regardless of the guideline
expect_identical(
suppressWarnings(count_df(example_isolates[, "AMX"], combine_SI = TRUE, guideline = "CLSI")),
count_df(example_isolates[, "AMX"], guideline = "EUCAST")
)
expect_identical(
suppressWarnings(count_df(example_isolates[, "AMX"], combine_SI = FALSE, guideline = "CLSI")),
count_df(example_isolates[, "AMX"], guideline = NULL)
)
# grouping in sir_calc_df() (= backbone of sir_df())
expect_true("ward" %in% (example_isolates %>%
+10
View File
@@ -101,6 +101,16 @@ test_that("test-ggplot_sir.R", {
levels(ggplot_sir(example_isolates[, c("AMC", "CIP")], guideline = "CLSI")$layers[[1]]$data(example_isolates[, c("AMC", "CIP")])$interpretation),
c("S", "IR")
)
# S, I, and R are kept separate with guideline = NULL
expect_identical(
levels(ggplot_sir(example_isolates[, c("AMC", "CIP")], guideline = NULL)$layers[[1]]$data(example_isolates[, c("AMC", "CIP")])$interpretation),
c("S", "I", "R")
)
# the deprecated combine_SI must be followed literally if set, regardless of the guideline
expect_identical(
levels(suppressWarnings(ggplot_sir(example_isolates[, c("AMC", "CIP")], combine_SI = TRUE, guideline = "CLSI"))$layers[[1]]$data(example_isolates[, c("AMC", "CIP")])$interpretation),
c("SI", "R")
)
# support for scale_type ab and mo
expect_inherits(
+7 -1
View File
@@ -122,7 +122,7 @@ test_that("test-proportion.R", {
)
)
expect_equal(
example_isolates %>% select(AMX) %>% proportion_df(combine_SI = FALSE) %>% pull(value),
example_isolates %>% select(AMX) %>% proportion_df(guideline = NULL) %>% pull(value),
c(
example_isolates$AMX %>% proportion_S(),
example_isolates$AMX %>% proportion_I(),
@@ -130,6 +130,12 @@ test_that("test-proportion.R", {
)
)
expect_error(susceptibility(example_isolates$AMX, guideline = NULL))
expect_identical(
suppressWarnings(sir_df(example_isolates[, "AMX"], combine_SI = TRUE, guideline = "CLSI")),
sir_df(example_isolates[, "AMX"], guideline = "EUCAST")
)
# expect_warning(example_isolates %>% group_by(ward) %>% summarise(across(KAN, sir_confidence_interval)))
}