mirror of
https://github.com/msberends/AMR.git
synced 2026-05-31 17:41:49 +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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user