1
0
mirror of https://github.com/msberends/AMR.git synced 2025-06-07 23:54:05 +02:00

(v2.1.1.9288) mdro fix

This commit is contained in:
dr. M.S. (Matthijs) Berends 2025-06-01 15:35:04 +02:00
parent 5667ce3eae
commit 46f80b1378
No known key found for this signature in database
5 changed files with 22 additions and 22 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 2.1.1.9287 Version: 2.1.1.9288
Date: 2025-06-01 Date: 2025-06-01
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)

View File

@ -1,4 +1,4 @@
# AMR 2.1.1.9287 # AMR 2.1.1.9288
*(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://amr-for-r.org/#get-this-package).)* *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://amr-for-r.org/#get-this-package).)*

View File

@ -272,25 +272,24 @@ get_column_abx <- function(x,
} else { } else {
message_(" WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE) message_(" WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE)
} }
for (i in seq_len(length(out))) { for (i in seq_len(length(out))) {
if (isTRUE(verbose) && !names(out[i]) %in% names(duplicates)) { if (isTRUE(verbose) && !out[i] %in% duplicates) {
message_( message_(
"Using column '", font_bold(out[i]), "' as input for ", names(out)[i], "Using column '", font_bold(out[i]), "' as input for ", names(out)[i],
" (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")." " (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")."
) )
} }
if (names(out[i]) %in% names(duplicates)) { if (out[i] %in% duplicates) {
already_set_as <- out[unname(out) == unname(out[i])][1L] already_set_as <- out[which(out == out[i])[1L]]
if (names(out)[i] != names(already_set_as)) { if (names(out)[i] != already_set_as) {
warning_( message_(
paste0( paste0(
"Column '", font_bold(out[i]), "' will not be used for ", "Column '", font_bold(out[i]), "' will not be used for ",
names(out)[i], " (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")", names(out)[i], " (", suppressMessages(ab_name(names(out)[i], tolower = TRUE, language = NULL, fast_mode = TRUE)), ")",
", as it is already set for ", ", as this antimicrobial has already been set."
names(already_set_as), " (", ab_name(names(already_set_as), tolower = TRUE, language = NULL), ")"
), ),
add_fn = font_red, add_fn = font_red
immediate = verbose
) )
} }
} }

View File

@ -204,14 +204,14 @@ mdro <- function(x = NULL,
} }
if (is.character(vanA)) { if (is.character(vanA)) {
meet_criteria(vanA, is_in = colnames(x), allow_NA = FALSE, has_length = 1) meet_criteria(vanA, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
vanA <- x[[vanA]] vanA <- x[[VanA]]
meet_criteria(vanA, allow_class = "logical", allow_NA = TRUE) meet_criteria(vanA, allow_class = "logical", allow_NA = TRUE)
} else if (length(vanA) == 1) { } else if (length(vanA) == 1) {
vanA <- rep(vanA, NROW(x)) vanA <- rep(vanA, NROW(x))
} }
if (is.character(vanB)) { if (is.character(vanB)) {
meet_criteria(vanB, is_in = colnames(x), allow_NA = FALSE, has_length = 1) meet_criteria(vanB, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
vanB <- x[[vanB]] vanB <- x[[VanB]]
meet_criteria(vanB, allow_class = "logical", allow_NA = TRUE) meet_criteria(vanB, allow_class = "logical", allow_NA = TRUE)
} else if (length(vanB) == 1) { } else if (length(vanB) == 1) {
vanB <- rep(vanB, NROW(x)) vanB <- rep(vanB, NROW(x))
@ -1526,9 +1526,9 @@ mdro <- function(x = NULL,
) )
trans_tbl( trans_tbl(
3, 3,
rows = which(x[[SXT]] == "R" & rows = which(col_values(x, SXT) == "R" &
(x[[GEN]] == "R" | x[[TOB]] == "R" | x[[AMK]] == "R") & (col_values(x, GEN) == "R" | col_values(x, TOB) == "R" | col_values(x, AMK) == "R") &
(x[[CIP]] == "R" | x[[NOR]] == "R" | x[[LVX]] == "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("Citrobacter freundii", "Klebsiella aerogenes", "Hafnia alvei", "Morganella morganii"))),
cols = c(SXT, aminoglycosides, fluoroquinolones), cols = c(SXT, aminoglycosides, fluoroquinolones),
any_all = "any", any_all = "any",
@ -1536,9 +1536,9 @@ mdro <- function(x = NULL,
) )
trans_tbl( trans_tbl(
3, 3,
rows = which(x[[SXT]] == "R" & rows = which(col_values(x, SXT) == "R" &
x[[GEN]] == "R" & col_values(x, GEN) == "R" &
(x[[CIP]] == "R" | x[[NOR]] == "R" | x[[LVX]] == "R") & (col_values(x, CIP) == "R" | col_values(x, NOR) == "R" | col_values(x, LVX) == "R") &
paste(x$genus, x$species) == "Serratia marcescens"), paste(x$genus, x$species) == "Serratia marcescens"),
cols = c(SXT, aminoglycosides_serratia_marcescens, fluoroquinolones), cols = c(SXT, aminoglycosides_serratia_marcescens, fluoroquinolones),
any_all = "any", any_all = "any",
@ -1548,8 +1548,8 @@ mdro <- function(x = NULL,
# Acinetobacter baumannii-calcoaceticus complex # Acinetobacter baumannii-calcoaceticus complex
trans_tbl( trans_tbl(
3, 3,
rows = which((x[[GEN]] == "R" | x[[TOB]] == "R" | x[[AMK]] == "R") & rows = which((col_values(x, GEN) == "R" | col_values(x, TOB) == "R" | col_values(x, AMK) == "R") &
(x[[CIP]] == "R" | x[[LVX]] == "R") & (col_values(x, CIP) == "R" | col_values(x, LVX) == "R") &
x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"]), x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"]),
cols = c(aminoglycosides, CIP, LVX), cols = c(aminoglycosides, CIP, LVX),
any_all = "any", any_all = "any",

View File

@ -71,6 +71,7 @@ test_that("test-data.R", {
if (AMR:::pkg_is_available("tibble")) { if (AMR:::pkg_is_available("tibble")) {
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy) # there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE] datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE]
datasets <- datasets[datasets != "antibiotics"]
for (i in seq_len(length(datasets))) { for (i in seq_len(length(datasets))) {
dataset <- get(datasets[i], envir = asNamespace("AMR")) dataset <- get(datasets[i], envir = asNamespace("AMR"))
expect_identical(AMR:::dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i]) expect_identical(AMR:::dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i])