(v3.0.1.9116) New sir_combine() for combination therapy as one engine for antibiogram(), wisca(), count_*() and proportion_*() (#321), and make all suggested packages runtime-only with a new CI workflow without dplyr

- New sir_combine() to combine SIR results of multiple antimicrobials into one variable; antibiogram(), wisca() and the count/proportion functions now use the same engine (antibiogram() and wisca() output unchanged)
- With multiple antimicrobials, count_*() and proportion_*() now follow the documented combination therapy rules: resistance() is the proportion of failing combinations, count_all() excludes isolates with an unknown combination result, and WT/NWT/NS/NI are handled correctly
- where() is now decided at runtime instead of at installation, fixing antibiogram() and wisca() without tidyselect (e.g. CRAN binaries without dplyr)
- Imports from data.table and cli moved to .onLoad(); data.table functions are only used while it is loaded; the like() example no longer unloads data.table, which crashed R
- Static test that fails on code outside functions depending on suggested packages
- New check-without-dplyr workflow: installs AMR with all suggested packages, removes dplyr (and tidyselect), then runs all unit tests and examples against the installed package
- g.test() now returns the degrees of freedom as 'parameter', so they are printed
- Fix R CMD check NOTEs (hidden .claude folder, lost braces in inherited g.test and ggplot_pca docs)
This commit is contained in:
dr. M.S. (Matthijs) Berends committed 2026-10-11 20:36:31 +02:00
1 parent 80afedeb8c
commit 53d0704271
30 files changed
+939 -268

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
# ==================================================================== #
# TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE CODE: #
# https://github.com/msberends/AMR #
# #
# PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
# Journal of Statistical Software, 104(3), 1-31. #
# https://doi.org/10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in the Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://amr-for-r.org #
# ==================================================================== #
# Run all unit tests and all examples against the INSTALLED AMR package, in a library where some suggested packages are not available.
# Used by .github/workflows/check-without-dplyr.yaml; run from the root of the repository:
# Rscript .github/scripts/test_installed_without.R dplyr tidyselect
# The package must have been installed BEFORE the listed packages were made unavailable, as binary packages from CRAN are built on machines that have all suggested packages: code that depends on what was available at installation (instead of at runtime) then fails, which R CMD check cannot detect as it reinstalls the package.
unavailable <- commandArgs(trailingOnly = TRUE)
if (length(unavailable) == 0) {
stop("provide the package(s) that must be unavailable, e.g.: Rscript test_installed_without.R dplyr tidyselect")
}
still_available <- unavailable[vapply(unavailable, requireNamespace, logical(1), quietly = TRUE)]
if (length(still_available) > 0) {
stop("these packages must not be available, but are: ", paste(still_available, collapse = ", "))
}
cat("Not available:", paste(unavailable, collapse = ", "), "\n")
cat("AMR", format(utils::packageVersion("AMR")), "installed in", find.package("AMR"), "\n\n")
Sys.setenv(NOT_CRAN = "true")
library(AMR)
# 1. all unit tests, against the installed package
cat("== Unit tests ==\n")
results <- as.data.frame(testthat::test_dir(
"tests/testthat",
package = "AMR",
load_package = "installed",
reporter = "summary",
stop_on_failure = FALSE
))
n_failed <- sum(results$failed) + sum(results$error)
cat("\nTests: ", sum(results$nb), " expectations, ", sum(results$failed), " failed, ", sum(results$error), " errored, ", sum(results$skipped), " skipped\n", sep = "")
# 2. all examples, including \donttest{} (not \dontrun{}), against the installed package
cat("\n== Examples ==\n")
rd_db <- tools::Rd_db("AMR")
failed_examples <- character(0)
n_examples <- 0
for (rd in sort(names(rd_db))) {
ex_file <- tempfile(fileext = ".R")
tools::Rd2ex(rd_db[[rd]], ex_file, commentDonttest = FALSE)
if (!file.exists(ex_file)) next
n_examples <- n_examples + 1
# print the name first, so that a crash of R itself shows which help page caused it
cat(rd, "\n")
ok <- tryCatch(
{
utils::capture.output(suppressMessages(suppressWarnings(source(ex_file, local = new.env(parent = globalenv()), echo = FALSE))))
TRUE
},
error = function(e) {
cat("FAILED: ", rd, ": ", conditionMessage(e), "\n", sep = "")
FALSE
}
)
if (!ok) failed_examples <- c(failed_examples, rd)
grDevices::graphics.off()
}
cat("Examples: ", length(failed_examples), " of ", n_examples, " help pages failed\n", sep = "")
if (n_failed > 0 || length(failed_examples) > 0) {
stop(n_failed, " test(s) failed and ", length(failed_examples), " example(s) failed without ", paste(unavailable, collapse = " and "), call. = FALSE)
}
cat("\nAll tests and examples passed without ", paste(unavailable, collapse = " and "), ".\n", sep = "")