diff --git a/R/antibiogram.R b/R/antibiogram.R index a614ef7ac..6a8d086e5 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -1206,7 +1206,7 @@ retrieve_wisca_parameters <- function(wisca_model, ...) { #' @rawNamespace if(getRversion() >= "3.0.0") S3method(pillar::tbl_sum, antibiogram) tbl_sum.antibiogram <- function(x, ...) { dims <- paste(format(NROW(x), big.mark = ","), AMR_env$cross_icon, format(NCOL(x), big.mark = ",")) - names(dims) <- "An Antibiogram" + names(dims) <- "An antibiogram" if (isTRUE(attributes(x)$wisca)) { dims <- c(dims, Type = paste0("WISCA with ", attributes(x)$conf_interval * 100, "% CI")) } else if (isTRUE(attributes(x)$formatting_type >= 13)) { @@ -1226,8 +1226,7 @@ tbl_format_footer.antibiogram <- function(x, ...) { } c(footer, font_subtle(paste0( "# Use `ggplot2::autoplot()` or base R `plot()` to create a plot of this antibiogram,\n", - "# or use it directly in R Markdown or ", - font_url("https://quarto.org", "Quarto"), ", see ", word_wrap("?antibiogram") + "# or use it directly in R Markdown or Quarto, see ", word_wrap("?antibiogram") ))) } diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index 6ab0f1f73..a2d78971a 100755 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -129,16 +129,21 @@ bug_drug_combinations <- function(x, # turn and merge everything pivot <- lapply(x_mo_filter, function(x) { m <- as.matrix(table(as.sir(x), useNA = "always")) + na_idx <- which(is.na(rownames(m))) + get_row <- function(lbl) { + idx <- which(rownames(m) == lbl) + if (length(idx) == 1L) unname(m[idx, ]) else rep(0L, ncol(m)) + } data.frame( - S = m["S", ], - SDD = m["SDD", ], - I = m["I", ], - R = m["R", ], - NI = m["NI", ], - WT = m["WT", ], - NWT = m["NWT", ], - NS = m["NS", ], - na = m[which(is.na(rownames(m))), ], + S = get_row("S"), + SDD = get_row("SDD"), + I = get_row("I"), + R = get_row("R"), + NI = get_row("NI"), + WT = get_row("WT"), + NWT = get_row("NWT"), + NS = get_row("NS"), + na = if (length(na_idx) == 1L) unname(m[na_idx, ]) else rep(0L, ncol(m)), stringsAsFactors = FALSE ) }) diff --git a/tests/testthat/test-sir.R b/tests/testthat/test-sir.R index 82d3af144..a648a0e83 100644 --- a/tests/testthat/test-sir.R +++ b/tests/testthat/test-sir.R @@ -491,13 +491,13 @@ test_that("test-sir.R", { expect_identical(sir_par[["AMC"]], sir_par2[["AMC"]]) expect_identical(sir_par[["GEN"]], sir_par2[["GEN"]]) - # 5. max_cores = 1 gives same results as default sequential + # 5. used cores = 1 gives same results as default sequential future::plan(future::multicore, workers = 1) sir_mc1 <- suppressMessages(as.sir(df_par, col_mo = "mo", info = FALSE, parallel = TRUE)) expect_identical(sir_seq[["AMC"]], sir_mc1[["AMC"]]) expect_identical(sir_seq[["GEN"]], sir_mc1[["GEN"]]) - # 6. max_cores = 2 and max_cores = 3 give same results as sequential + # 6. used cores = 2 and used cores = 3 give same results as sequential if (n_max_workers >= 3) { future::plan(future::multicore, workers = 2) sir_mc2 <- suppressMessages(as.sir(df_par, col_mo = "mo", info = FALSE, parallel = TRUE)) @@ -515,9 +515,9 @@ test_that("test-sir.R", { sir_single_par <- suppressMessages(as.sir(df_single, col_mo = "mo", info = FALSE, parallel = TRUE)) expect_identical(sir_single_seq[["AMC"]], sir_single_par[["AMC"]]) - # 8. row-batch mode (n_cols < n_cores): force row splitting via max_cores and + # 8. row-batch mode (n_cols < n_cores): force row splitting via used cores and # verify identical output to sequential for a dataset with 2 AB columns so - # pieces_per_col = ceiling(max_cores / 2) >= 2 and row batching activates + # pieces_per_col = ceiling(used cores / 2) >= 2 and row batching activates df_wide <- data.frame( mo = "B_ESCHR_COLI", AMC = as.mic(sample(c("1", "2", "4", "8"), n_par, TRUE)), @@ -529,7 +529,7 @@ test_that("test-sir.R", { future::plan(future::multicore) sir_wide_par <- suppressMessages(as.sir(df_wide, col_mo = "mo", info = FALSE, - parallel = TRUE, max_cores = 8L + parallel = TRUE )) expect_identical(sir_wide_seq[["AMC"]], sir_wide_par[["AMC"]]) expect_identical(sir_wide_seq[["GEN"]], sir_wide_par[["GEN"]])