mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 06:30:48 +01:00
- One cache design for as.ab() and as.mo() in R/aa_session_cache.R: lazily built lookup indices (ATC codes, drug synonyms, SNOMED codes) and coercion caches with the same structure (key, input, value), keyed on input plus outcome-relevant settings - Caches are invalidated whenever the lookup tables change (custom antimicrobials or microorganisms, set_mo_source()) - mo_*() functions use a fast path for valid <mo> input and work on unique values only - synonym_mo_to_accepted_mo() is memoised per code - Fix as.mo() cache keys that never matched again, fast_mode results of as.ab() being reused by regular calls, and ab_reset_session() clearing as.mo() uncertainties Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ca43df459
commit
891d248fab
14 files changed
+462
-124
No files matched your search
@@ -153,8 +153,9 @@ add_custom_antimicrobials <- function(x) {
|
||||
}
|
||||
AMR_env$AB_lookup <- unique(rbind_AMR(AMR_env$AB_lookup, new_df))
|
||||
|
||||
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% c(x$ab, x$generalised_name) & !AMR_env$ab_previously_coerced$x %in% c(x$ab, x$generalised_name)), , drop = FALSE]
|
||||
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
|
||||
# the lookup table changed, so earlier coercions and lookup indices are no longer valid
|
||||
reset_ab_cache()
|
||||
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal {.code antimicrobials} data set.")
|
||||
}
|
||||
|
||||
@@ -165,6 +166,6 @@ clear_custom_antimicrobials <- function() {
|
||||
AMR_env$AB_lookup <- cbind(AMR::antimicrobials, AB_LOOKUP)
|
||||
n2 <- nrow(AMR_env$AB_lookup)
|
||||
AMR_env$custom_ab_codes <- character(0)
|
||||
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(AMR_env$ab_previously_coerced$ab %in% AMR_env$AB_lookup$ab), , drop = FALSE]
|
||||
reset_ab_cache()
|
||||
message_("Cleared ", nr2char(n - n2), " custom record", ifelse(n - n2 > 1, "s", ""), " from the internal {.help [antimicrobials](AMR::antimicrobials)} data set.")
|
||||
}
|
||||
Reference in new issue
Block a user