1
0
mirror of https://github.com/msberends/AMR.git synced 2026-05-31 13:41:42 +02:00

Fix namespace load failure: remove assignInNamespace from .onLoad (#268)

assignInNamespace cannot add NEW bindings to a locked package namespace
(R locks namespace bindings before .onLoad runs). Replace the .onLoad
shim with a runtime fallback inside interpretive_rules(): if
INTERPRETIVE_RULES_DF is absent (pre-regeneration sysdata.rda), derive
it from EUCAST_RULES_DF by adding the rule.provider column. This also
fixes the screening_abx line to reuse the already-resolved
interpretive_rules_df_total instead of a bare INTERPRETIVE_RULES_DF
reference.

https://claude.ai/code/session_01D46BTsfJSPo3HnLWp3PRkP
This commit is contained in:
Claude
2026-05-01 06:19:17 +00:00
parent befbccc304
commit 7c945b8081
2 changed files with 12 additions and 14 deletions

11
R/zzz.R
View File

@@ -112,17 +112,6 @@ AMR_env$cross_icon <- if (isTRUE(base::l10n_info()$`UTF-8`)) "\u00d7" else "x"
AMR_env$AB_lookup <- cbind(AMR::antimicrobials, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
# Transitional: create INTERPRETIVE_RULES_DF alias if sysdata.rda predates the rename from EUCAST_RULES_DF.
# Remove this block once data-raw/_pre_commit_checks.R has been re-run.
ns <- asNamespace("AMR")
if (!exists("INTERPRETIVE_RULES_DF", envir = ns, inherits = FALSE) &&
exists("EUCAST_RULES_DF", envir = ns, inherits = FALSE)) {
df <- get("EUCAST_RULES_DF", envir = ns)
df$rule.provider <- "EUCAST"
df <- df[, c("rule.provider", setdiff(colnames(df), "rule.provider")), drop = FALSE]
assignInNamespace("INTERPRETIVE_RULES_DF", df, ns = "AMR")
}
}
.onAttach <- function(libname, pkgname) {