1
0
mirror of https://github.com/msberends/AMR.git synced 2026-03-07 21:10:12 +01:00

Fix stats::setNames, test accessor bug, and version script verification

R/mdro.R:
  Qualify setNames() as stats::setNames() in the drug+inhibitor inference
  block to satisfy R CMD CHECK's global-function checks.

tests/testthat/test-mdro.R:
  mdro() with verbose=FALSE returns an atomic ordered factor, not a
  data.frame. Fix three test errors introduced in the previous commit:
  - Line 320: result_no_pip$MDRO -> result_no_pip (factor, no $ accessor)
  - Line 328: result_tzp_s$MDRO / result_no_pip$MDRO -> direct factor refs
  - Line 347: expect_inherits(..., "data.frame") -> c("factor","ordered")
  Also fix the comment on line 347 to match the actual return type.

Version: confirmed at 3.0.1.9029 (no further bump; one bump already made
this PR). git describe failed (no tags in dev environment) — fallback
applies. The +1 in CLAUDE.md's formula is correct for tagged repos:
currentcommit + 9001 + 1 = 27 + 9001 + 1 = 9029 ✓

https://claude.ai/code/session_01Cp154UtssHg84bw38xiiTG
This commit is contained in:
Claude
2026-03-07 14:54:07 +00:00
parent 83fcb1a224
commit 80d5aabed0
2 changed files with 6 additions and 5 deletions

View File

@@ -507,7 +507,7 @@ mdro <- function(x = NULL,
)
.new_col <- paste0(".sir_proxy_", .base_code)
x[[.new_col]] <- ifelse(rowSums(.sir_chars == "R", na.rm = TRUE) > 0L, "R", NA_character_)
cols_ab <- c(cols_ab, setNames(.new_col, .base_code))
cols_ab <- c(cols_ab, stats::setNames(.new_col, .base_code))
if (isTRUE(verbose)) {
message_(
"Inferring resistance for ", ab_name(.base_code, language = NULL),

View File

@@ -316,8 +316,9 @@ test_that("test-mdro.R", {
stringsAsFactors = FALSE
)
# With TZP=R, PIP should be inferred R; result should be XDR or PDR (integer > 2)
# mdro() with verbose=FALSE returns an atomic factor, not a data.frame
result_no_pip <- suppressMessages(suppressWarnings(mdro(pseud_no_pip, guideline = "EUCAST", info = FALSE)))
expect_true(as.integer(result_no_pip$MDRO) > 1L)
expect_true(as.integer(result_no_pip) > 1L)
# Susceptibility in combination must NOT be propagated to base drug
# (the inhibitor may be responsible; we cannot conclude PIP=S from TZP=S)
@@ -325,7 +326,7 @@ test_that("test-mdro.R", {
pseud_tzp_s$TZP <- as.sir("S")
result_tzp_s <- suppressMessages(suppressWarnings(mdro(pseud_tzp_s, guideline = "EUCAST", info = FALSE)))
# Proxy column is NA (not S), so the classification should be lower than when TZP=R
expect_true(as.integer(result_tzp_s$MDRO) < as.integer(result_no_pip$MDRO))
expect_true(as.integer(result_tzp_s) < as.integer(result_no_pip))
# verbose mode should emit an inference message when a proxy column is created
expect_output(
@@ -343,6 +344,6 @@ test_that("test-mdro.R", {
DAP = as.sir("R"),
stringsAsFactors = FALSE
)
# Should run without error and return a data.frame; AMX inferred R from AMC
expect_inherits(suppressMessages(suppressWarnings(mdro(ente_no_amx, guideline = "EUCAST", info = FALSE))), "data.frame")
# Should run without error and return an ordered factor; AMX inferred R from AMC
expect_inherits(suppressMessages(suppressWarnings(mdro(ente_no_amx, guideline = "EUCAST", info = FALSE))), c("factor", "ordered"))
})