From 66eeeb4b88d5a7196b5d1fe8b5f173044535ea3f Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Tue, 11 Jul 2023 14:29:40 +0200 Subject: [PATCH] cleanup --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/ab.R | 2 +- R/disk.R | 2 +- R/mo.R | 2 +- R/sir.R | 16 ++++++++++------ 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 83a80995..3a953fda 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.0.0.9034 +Version: 2.0.0.9035 Date: 2023-07-11 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 11b9b081..aa994c98 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.0.0.9034 +# AMR 2.0.0.9035 ## New * Clinical breakpoints and intrinsic resistance of EUCAST 2023 and CLSI 2023 have been added for `as.sir()`. EUCAST 2023 (v13.0) is now the new default guideline for all MIC and disks diffusion interpretations diff --git a/R/ab.R b/R/ab.R index e302dbea..64be3a43 100755 --- a/R/ab.R +++ b/R/ab.R @@ -548,7 +548,7 @@ pillar_shaft.ab <- function(x, ...) { # add the names to the drugs as mouse-over! if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) { - out[!is.na(x)] <- font_url(url = ab_name(x[!is.na(x)], language = NULL), + out[!is.na(x)] <- font_url(url = ab_name(x[!is.na(x)]), txt = out[!is.na(x)]) } diff --git a/R/disk.R b/R/disk.R index 946a0cda..a939f21c 100755 --- a/R/disk.R +++ b/R/disk.R @@ -70,7 +70,7 @@ #' # interpret whole data set, pretend to be all from urinary tract infections: #' as.sir(df, uti = TRUE) as.disk <- function(x, na.rm = FALSE) { - meet_criteria(x, allow_class = c("disk", "character", "numeric", "integer"), allow_NA = TRUE) + meet_criteria(x, allow_NA = TRUE) meet_criteria(na.rm, allow_class = "logical", has_length = 1) if (!is.disk(x)) { diff --git a/R/mo.R b/R/mo.R index 9f02d6e2..d7f8282d 100755 --- a/R/mo.R +++ b/R/mo.R @@ -630,7 +630,7 @@ pillar_shaft.mo <- function(x, ...) { # add the names to the bugs as mouse-over! if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) { - out[!x %in% c("UNKNOWN", NA)] <- font_url(url = mo_name(x[!x %in% c("UNKNOWN", NA)], language = NULL, keep_synonyms = TRUE), + out[!x %in% c("UNKNOWN", NA)] <- font_url(url = mo_name(x[!x %in% c("UNKNOWN", NA)], keep_synonyms = TRUE), txt = out[!x %in% c("UNKNOWN", NA)]) } diff --git a/R/sir.R b/R/sir.R index 15266d64..07aa2c4d 100755 --- a/R/sir.R +++ b/R/sir.R @@ -741,8 +741,10 @@ as_sir_method <- function(method_short, check_reference_data(reference_data, .call_depth = -2) meet_criteria(breakpoint_type, allow_class = "character", is_in = reference_data$type, has_length = 1, .call_depth = -2) + guideline_coerced <- get_guideline(guideline, reference_data) + if (message_not_thrown_before("as.sir", "sir_interpretation_history")) { - message_("Run `sir_interpretation_history()` afterwards to retrieve a logbook with all the details of the breakpoint interpretations.\n\n") + message_("Run `sir_interpretation_history()` afterwards to retrieve a logbook with all the details of the breakpoint interpretations. Note that some microorganisms might not have breakpoints for each antimicrobial drug in ", guideline_coerced, ".\n\n") } # for dplyr's across() @@ -798,7 +800,6 @@ as_sir_method <- function(method_short, } # be sure to take current taxonomy, as the 'clinical_breakpoints' data set only contains current taxonomy mo <- suppressWarnings(suppressMessages(as.mo(mo, keep_synonyms = FALSE, info = FALSE))) - guideline_coerced <- get_guideline(guideline, reference_data) if (is.na(ab)) { message_("Returning NAs for unknown antibiotic: '", font_bold(ab.bak), "'. Rename this column to a valid name or code, and check the output with `as.ab()`.", @@ -919,7 +920,7 @@ as_sir_method <- function(method_short, paste0(font_rose_bg(" WARNING "), "\n"), font_black(paste0(" ", AMR_env$bullet_icon, " No ", method_coerced, " breakpoints available for ", suppressMessages(suppressWarnings(ab_name(ab_coerced, language = NULL, tolower = TRUE))), - " (", ab_coerced, ")"))) + " (", ab_coerced, ")."))) load_mo_uncertainties(metadata_mo) return(rep(NA_sir_, nrow(df))) @@ -1017,8 +1018,11 @@ as_sir_method <- function(method_short, } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_current, ab_coerced)) { # breakpoints for multiple body sites available msgs <- c(msgs, paste0("Multiple breakpoints available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, ".")) + } else if (nrow(breakpoints_current) == 0) { + # # do not note - it's already in the header before the interpretation starts + next } - + # first check if mo is intrinsic resistant if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_current, ab_coerced) %in% AMR_env$intrinsic_resistant) { msgs <- c(msgs, paste0("Intrinsic resistance applied for ", ab_formatted, " in ", mo_formatted, "")) @@ -1031,10 +1035,10 @@ as_sir_method <- function(method_short, breakpoints_current <- breakpoints_current[1L, , drop = FALSE] if (any(breakpoints_current$mo == "UNKNOWN", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "PK.*PD", na.rm = TRUE)) { - msgs <- c(msgs, "(Some) PK/PD breakpoints were applied - use `include_PKPD = FALSE` to prevent this") + msgs <- c(msgs, "Some PK/PD breakpoints were applied - use `include_PKPD = FALSE` to prevent this") } if (any(breakpoints_current$site %like% "screen", na.rm = TRUE) | any(breakpoints_current$ref_tbl %like% "screen", na.rm = TRUE)) { - msgs <- c(msgs, "(Some) screening breakpoints were applied - use `include_screening = FALSE` to prevent this") + msgs <- c(msgs, "Some screening breakpoints were applied - use `include_screening = FALSE` to prevent this") } if (method == "mic") {