From ab38fb911d3bdcd50bdcb854452624c36736f2ee Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Wed, 24 Jun 2026 10:19:15 +0200 Subject: [PATCH] (v3.0.1.9062) Fix older R versions --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- R/aa_helper_functions.R | 8 +++++++- R/mdro.R | 12 ++++++------ R/sir.R | 12 ++++++------ R/zzz.R | 8 ++++---- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1a3b979ae..6b9bb0d04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 3.0.1.9061 -Date: 2026-06-23 +Version: 3.0.1.9062 +Date: 2026-06-24 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 d66c10a33..864e398d6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 3.0.1.9061 +# AMR 3.0.1.9062 Planned as v3.1.0, end of June 2026. diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 759efe81c..f8bb6d198 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -708,7 +708,7 @@ stop_ifnot <- function(expr, ..., call = TRUE) { } } -"%or%" <- function(x, y) { +"%or_if_na%" <- function(x, y) { if (is.null(x) || is.null(y)) { if (is.null(x)) { return(y) @@ -1846,4 +1846,10 @@ if (getRversion() < "4.0.0") { } } +if (getRversion() < "4.4.0") { + `%||%` <- function(x, y) { + if (is.null(x)) y else x + } +} + # nolint end diff --git a/R/mdro.R b/R/mdro.R index 6831c6e55..10d1698d8 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -1511,8 +1511,8 @@ mdro <- function(x = NULL, fluoroquinolones <- c(CIP, NOR, LVX) # note 5: ciprofloxacin or norfloxacin or levofloxacin carbapenems <- carbapenems[!is.na(carbapenems)] carbapenems_without_imipenem <- carbapenems[carbapenems != IPM] - amino <- AMX %or% AMP - third <- CAZ %or% CTX + amino <- AMX %or_if_na% AMP + third <- CAZ %or_if_na% CTX ESBLs <- c(amino, third) ESBLs <- ESBLs[!is.na(ESBLs)] if (length(ESBLs) != 2) { @@ -1524,7 +1524,7 @@ mdro <- function(x = NULL, trans_tbl( 2, # positive, unconfirmed rows = which(x$order == "Enterobacterales" & col_values(x, ESBLs[1]) == "R" & col_values(x, ESBLs[2]) == "R" & is.na(esbl)), - cols = c(AMX %or% AMP, cephalosporins_3rd), + cols = c(AMX %or_if_na% AMP, cephalosporins_3rd), any_all = "all", reason = "Enterobacterales: potential ESBL" ) @@ -1634,7 +1634,7 @@ mdro <- function(x = NULL, trans_tbl( 3, rows = which(x$genus == "Enterococcus" & x$species == "faecium"), - cols = c(PEN %or% AMX %or% AMP, VAN), + cols = c(PEN %or_if_na% AMX %or_if_na% AMP, VAN), any_all = "all", reason = "E. faecium: vancomycin + penicillin group" ) @@ -1677,8 +1677,8 @@ mdro <- function(x = NULL, aminoglycosides <- aminoglycosides[!is.na(aminoglycosides)] fluoroquinolones <- fluoroquinolones[!is.na(fluoroquinolones)] carbapenems <- carbapenems[!is.na(carbapenems)] - amino <- AMX %or% AMP - third <- CAZ %or% CTX + amino <- AMX %or_if_na% AMP + third <- CAZ %or_if_na% CTX ESBLs <- c(amino, third) ESBLs <- ESBLs[!is.na(ESBLs)] if (length(ESBLs) != 2) { diff --git a/R/sir.R b/R/sir.R index d10134377..a0fe78dac 100755 --- a/R/sir.R +++ b/R/sir.R @@ -2292,12 +2292,12 @@ c.sir <- function(...) { lst <- list(...) # TODO for #170 - # guideline <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$guideline %or% NA_character_) - # mo <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$mo %or% NA_character_) - # ab <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ab %or% NA_character_) - # method <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$method %or% NA_character_) - # ref_tbl <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_tbl %or% NA_character_) - # ref_breakpoints <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_breakpoints %or% NA_character_) + # guideline <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$guideline %||% NA_character_) + # mo <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$mo %||% NA_character_) + # ab <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ab %||% NA_character_) + # method <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$method %||% NA_character_) + # ref_tbl <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_tbl %||% NA_character_) + # ref_breakpoints <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_breakpoints %||% NA_character_) out <- as.sir(unlist(lapply(list(...), as.character))) diff --git a/R/zzz.R b/R/zzz.R index 39eca912f..16f33fabb 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -86,10 +86,10 @@ AMR_env$chmatch <- import_fn("chmatch", "data.table", error_on_fail = FALSE) AMR_env$chin <- import_fn("%chin%", "data.table", error_on_fail = FALSE) # take cli symbols and error function if available -AMR_env$bullet_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$bullet %or% "*" -AMR_env$ellipsis_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$ellipsis %or% "..." -AMR_env$info_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$info %or% "i" -AMR_env$sup_1_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$sup_1 %or% "*" +AMR_env$bullet_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$bullet %||% "*" +AMR_env$ellipsis_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$ellipsis %||% "..." +AMR_env$info_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$info %||% "i" +AMR_env$sup_1_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$sup_1 %||% "*" AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE) AMR_env$cross_icon <- if (isTRUE(base::l10n_info()$`UTF-8`)) "\u00d7" else "x"