mirror of
https://github.com/msberends/AMR.git
synced 2026-05-31 19:41:51 +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:
@@ -619,9 +619,18 @@ interpretive_rules <- function(x,
|
||||
} else if (!is.null(list(...)$eucast_rules_df)) {
|
||||
# deprecated parameter name kept for backward compatibility
|
||||
interpretive_rules_df_total <- list(...)$eucast_rules_df
|
||||
} else {
|
||||
# otherwise internal data file, created in data-raw/_pre_commit_checks.R
|
||||
} else if (exists("INTERPRETIVE_RULES_DF", envir = asNamespace("AMR"), inherits = FALSE)) {
|
||||
# internal data file, created in data-raw/_pre_commit_checks.R
|
||||
interpretive_rules_df_total <- INTERPRETIVE_RULES_DF
|
||||
} else {
|
||||
# transitional fallback: sysdata.rda predates the rename from EUCAST_RULES_DF
|
||||
# re-run data-raw/_pre_commit_checks.R to regenerate sysdata.rda
|
||||
interpretive_rules_df_total <- EUCAST_RULES_DF
|
||||
interpretive_rules_df_total$rule.provider <- "EUCAST"
|
||||
interpretive_rules_df_total <- interpretive_rules_df_total[
|
||||
, c("rule.provider", setdiff(colnames(interpretive_rules_df_total), "rule.provider")),
|
||||
drop = FALSE
|
||||
]
|
||||
}
|
||||
|
||||
## filter on guideline provider and user-set guideline versions ----
|
||||
@@ -661,7 +670,7 @@ interpretive_rules <- function(x,
|
||||
# sometimes, the screenings are missing but the names are actually available
|
||||
# we only hints on remaining rows in `interpretive_rules_df`
|
||||
screening_abx <- as.character(AMR::antimicrobials$ab[which(AMR::antimicrobials$ab %like% "-S$")])
|
||||
screening_abx <- screening_abx[screening_abx %in% unique(unlist(strsplit(INTERPRETIVE_RULES_DF$and_these_antibiotics[!is.na(INTERPRETIVE_RULES_DF$and_these_antibiotics)], ", *")))]
|
||||
screening_abx <- screening_abx[screening_abx %in% unique(unlist(strsplit(interpretive_rules_df_total$and_these_antibiotics[!is.na(interpretive_rules_df_total$and_these_antibiotics)], ", *")))]
|
||||
if (isTRUE(info)) {
|
||||
cat("\n")
|
||||
}
|
||||
|
||||
11
R/zzz.R
11
R/zzz.R
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user