From 92ae56eaaa919fb2d9cc865be73643bfd8cad1fa Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Fri, 20 Mar 2026 16:10:02 +0100 Subject: [PATCH] fixes --- R/aa_helper_functions.R | 2 +- R/ab.R | 24 ++++++++++++------------ R/amr_selectors.R | 4 ++-- R/custom_mdro_guideline.R | 4 ++-- R/mo.R | 4 ++-- R/sir.R | 2 +- tests/testthat/test-mo.R | 2 -- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 3239865b2..5b8090ab0 100644 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -1061,7 +1061,7 @@ get_current_data <- function(arg_name, call) { } else { examples <- "" } - stop_("this function must be used inside a {.pkg dplyr} verb or {.code data.frame} call", + stop_("this function must be used inside a {.pkg dplyr} verb or {.cls data.frame} call", examples, call = call ) diff --git a/R/ab.R b/R/ab.R index 5af1f3b51..a67b53cb4 100755 --- a/R/ab.R +++ b/R/ab.R @@ -484,7 +484,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), } message_( "Antimicrobial translation was uncertain for ", examples, - ". If required, use `add_custom_antimicrobials()` to add custom entries." + ". If required, use {.help [{.fun add_custom_antimicrobials}](AMR::add_custom_antimicrobials)} to add custom entries." ) } } @@ -556,21 +556,21 @@ print.ab <- function(x, ...) { function_name <- attributes(x)$amr_selector if (pkg_is_available("cli", min_version = "3.0.0")) { cli::cli_inform(c( - "i" = paste0("This {.cls ab} vector was retrieved using {.fun ", function_name, "}, which should normally be used inside a {.pkg dplyr} verb or {.code data.frame} call, e.g.:"), - "*" = highlight_code(paste0("your_data %>% select(", function_name, "()")), - "*" = highlight_code(paste0("your_data %>% select(column_a, column_b, ", function_name, "()")), - "*" = highlight_code(paste0("your_data %>% filter(any(", function_name, "() == \"R\"))")), - "*" = highlight_code(paste0("your_data[, ", function_name, "()]")), - "*" = highlight_code(paste0("your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]")) + "i" = paste0("This {.cls ab} vector was retrieved using {.fun ", function_name, "}, which should normally be used inside a {.pkg dplyr} verb or {.cls data.frame} call, e.g.:"), + paste0("\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0("your_data %>% select(", function_name, "())"))), + paste0("\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0("your_data %>% select(column_a, column_b, ", function_name, "())"))), + paste0("\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0("your_data %>% filter(any(", function_name, "() == \"R\"))"))), + paste0("\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0("your_data[, ", function_name, "()]"))), + paste0("\u00a0\u00a0", AMR_env$bullet_icon, " ", highlight_code(paste0("your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]"))) )) } else { message(word_wrap(paste0( "This 'ab' vector was retrieved using `", function_name, "()`, which should normally be used inside a dplyr verb or data.frame call, e.g.:\n", - " ", AMR_env$bullet_icon, " your_data %>% select(", function_name, "())\n", - " ", AMR_env$bullet_icon, " your_data %>% select(column_a, column_b, ", function_name, "())\n", - " ", AMR_env$bullet_icon, " your_data %>% filter(any(", function_name, "() == \"R\"))\n", - " ", AMR_env$bullet_icon, " your_data[, ", function_name, "()]\n", - " ", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]" + "\u00a0\u00a0", AMR_env$bullet_icon, " your_data %>% select(", function_name, "())\n", + "\u00a0\u00a0", AMR_env$bullet_icon, " your_data %>% select(column_a, column_b, ", function_name, "())\n", + "\u00a0\u00a0", AMR_env$bullet_icon, " your_data %>% filter(any(", function_name, "() == \"R\"))\n", + "\u00a0\u00a0", AMR_env$bullet_icon, " your_data[, ", function_name, "()]\n", + "\u00a0\u00a0", AMR_env$bullet_icon, " your_data[, c(\"column_a\", \"column_b\", ", function_name, "())]" ), as_note = TRUE)) } } diff --git a/R/amr_selectors.R b/R/amr_selectors.R index 78ea41626..c27f0f791 100755 --- a/R/amr_selectors.R +++ b/R/amr_selectors.R @@ -722,7 +722,7 @@ amr_select_exec <- function(function_name, if (any(untreatable %in% names(ab_in_data))) { if (message_not_thrown_before(function_name, "amr_class", "untreatable")) { warning_( - "in `", function_name, "()`: some drugs were ignored since they cannot be used for treatment: ", + "in {.help [{.fun ", function_name, "}](AMR::", function_name, ")}: some drugs were ignored since they cannot be used for treatment: ", vector_and( ab_name(names(ab_in_data)[names(ab_in_data) %in% untreatable], language = NULL, @@ -797,7 +797,7 @@ amr_select_exec <- function(function_name, if (only_treatable == TRUE) { if (message_not_thrown_before(function_name, "amr_class", "untreatable")) { message_( - "in `", function_name, "()`: ", + "in {.help [{.fun ", function_name, "}](AMR::", function_name, ")}: ", vector_and( paste0( ab_name(abx[abx %in% untreatable], diff --git a/R/custom_mdro_guideline.R b/R/custom_mdro_guideline.R index d415b998a..4db6b6cff 100755 --- a/R/custom_mdro_guideline.R +++ b/R/custom_mdro_guideline.R @@ -235,9 +235,9 @@ print.custom_mdro_guideline <- function(x, ...) { for (i in seq_len(length(x))) { rule <- x[[i]] rule$query <- format_custom_query_rule(rule$query) - cat(" ", i, ". ", font_bold("If "), font_blue(rule$query), font_bold(" then: "), font_red(rule$value), "\n", sep = "") + cat("\u00a0\u00a0", i, ". ", font_bold("If "), font_blue(rule$query), font_bold(" then: "), font_red(rule$value), "\n", sep = "") } - cat(" ", i + 1, ". ", font_bold("Otherwise: "), font_red(paste0("Negative")), "\n", sep = "") + cat("\u00a0\u00a0", i + 1, ". ", font_bold("Otherwise: "), font_red(paste0("Negative")), "\n", sep = "") cat("\nUnmatched rows will return ", font_red("NA"), ".\n", sep = "") if (isTRUE(attributes(x)$as_factor)) { cat("Results will be of class 'factor', with ordered levels: ", paste0(attributes(x)$values, collapse = " < "), "\n", sep = "") diff --git a/R/mo.R b/R/mo.R index cfac9b427..2dd8cc9c6 100755 --- a/R/mo.R +++ b/R/mo.R @@ -977,8 +977,8 @@ print.mo_uncertainties <- function(x, n = 10, ...) { out <- paste0( paste0( - "", strrep(font_grey("-"), times = getOption("width", 100)), "\n", - '"', x[i, ]$original_input, '"', + "", strrep(font_grey("-"), times = getOption("width", 100) - 1), "\n", + "{.val ", x[i, ]$original_input, "}", " -> ", paste0( font_bold(italicise(x[i, ]$fullname)), diff --git a/R/sir.R b/R/sir.R index 1f66477aa..e09561dec 100755 --- a/R/sir.R +++ b/R/sir.R @@ -1946,7 +1946,7 @@ as_sir_method <- function(method_short, message_(notes[i], as_note = FALSE) } } else { - # message(word_wrap(" ", AMR_env$bullet_icon, " There were multiple notes. Print or View `sir_interpretation_history()` to examine them, or use `as.sir(..., verbose = TRUE)` next time to directly print them here.", add_fn = font_black)) + # message(word_wrap("\u00a0\u00a0", AMR_env$bullet_icon, " There were multiple notes. Print or View `sir_interpretation_history()` to examine them, or use `as.sir(..., verbose = TRUE)` next time to directly print them here.", add_fn = font_black)) } } else { message(font_green_bg(" OK ")) diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index 7e69b2bf9..78653ce2e 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -272,8 +272,6 @@ test_that("test-mo.R", { ) x <- as.mo("Sta. aur") - # many hits - expect_output(print(mo_uncertainties())) # no viruses expect_equal(suppressWarnings(as.mo("Virus")), as.mo("UNKNOWN"))