From f78199890495e9215a09ece09512c467b0792dbe Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Sun, 28 Aug 2022 11:17:53 +0200 Subject: [PATCH] amoxicillin interpretation fix --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/rsi.R | 31 ++++++++++++++++++++++++------- data-raw/_pre_commit_hook.R | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c1674e47..dc3381d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.1.9033 +Version: 1.8.1.9034 Date: 2022-08-28 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 18246250..9050d52d 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.1.9033 +# AMR 1.8.1.9034 ### New * EUCAST 2022 and CLSI 2022 guidelines have been added for `as.rsi()`. EUCAST 2022 is now the new default guideline for all MIC and disks diffusion interpretations. @@ -20,6 +20,7 @@ * Fix for using `info = FALSE` in `mdro()` * All data sets in this package are now exported as `tibble`, instead of base R `data.frame`s. Older R versions are still supported. * Automatic language determination will give a note once a session +* For all interpretation guidelines using `as.rsi()` on amoxicillin, the rules for ampicillin will be used if amoxicillin rules are not available ### Other * New website to make use of the new Bootstrap 5 and pkgdown v2.0. The website now contains results for all examples and will be automatically regenerated with every change to our repository, using GitHub Actions diff --git a/R/rsi.R b/R/rsi.R index b797c39f..8fe4677e 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -722,7 +722,12 @@ as_rsi_method <- function(method_short, agent_formatted <- paste0("'", font_bold(ab), "'") agent_name <- ab_name(ab_coerced, tolower = TRUE, language = NULL) if (generalise_antibiotic_name(ab) != generalise_antibiotic_name(agent_name)) { - agent_formatted <- paste0(agent_formatted, " (", ab_coerced, ", ", agent_name, ")") + agent_formatted <- paste0( + agent_formatted, + " (", ifelse(ab == ab_coerced, "", + paste0(ab_coerced, ", ") + ), agent_name, ")" + ) } message_("=> Interpreting ", method_long, " of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""), agent_formatted, @@ -799,19 +804,31 @@ exec_as.rsi <- function(method, new_rsi <- rep(NA_character_, length(x)) ab_param <- ab - if (ab_param == "AMX") { - ab_param <- "AMP" - if (message_not_thrown_before("as.rsi", "AMP_for_AMX")) { - message_("(using ampicillin rules)", appendLF = FALSE, as_note = FALSE) - } - } + if (identical(reference_data, AMR::rsi_translation)) { trans <- reference_data %pm>% subset(guideline == guideline_coerced & method == method_param & ab == ab_param) + if (ab_param == "AMX" && nrow(trans) == 0) { + ab_param <- "AMP" + if (message_not_thrown_before("as.rsi", "AMP_for_AMX")) { + message_("(using ampicillin rules)", appendLF = FALSE, as_note = FALSE) + } + trans <- reference_data %pm>% + subset(guideline == guideline_coerced & method == method_param & ab == ab_param) + } } else { trans <- reference_data %pm>% subset(method == method_param & ab == ab_param) } + + if (nrow(trans) == 0) { + message_(" OK.", add_fn = list(font_green, font_bold), as_note = FALSE) + load_mo_failures_uncertainties_renamed(metadata_mo) + return(set_clean_class(factor(new_rsi, levels = c("S", "I", "R"), ordered = TRUE), + new_class = c("rsi", "ordered", "factor") + )) + } + trans$lookup <- paste(trans$mo, trans$ab) lookup_mo <- paste(mo, ab_param) diff --git a/data-raw/_pre_commit_hook.R b/data-raw/_pre_commit_hook.R index 4b1d43a2..e744e285 100644 --- a/data-raw/_pre_commit_hook.R +++ b/data-raw/_pre_commit_hook.R @@ -494,4 +494,4 @@ invisible(capture.output(styler::style_dir( # Finished ---------------------------------------------------------------- -usethis::ui_info("All done") +usethis::ui_done("All done")