mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 03:00:48 +01:00
(v3.0.1.9153) Speed up mdro(), as.sir(), wisca() and wisca_plot() and the binding of mo vectors, fix PDR in the CMI 2012 guideline of mdro() being assigned to the wrong rows, and limit the stratified WISCA example to the 5 most common species
This commit is contained in:
1 parent
08aa47842e
commit
30021a9831
12 files changed
+153
-79
No files matched your search
@@ -101,7 +101,31 @@ reset_ab_cache <- function() {
|
||||
AMR_env$ab_previously_coerced <- new_coercion_cache()
|
||||
}
|
||||
|
||||
mo_codes_valid <- function(x) {
|
||||
# whether codes are in `AMR_env$MO_lookup`; a hashed set avoids scanning the whole lookup table for every check, as `[<-.mo` runs one for every piece that rbind() binds
|
||||
x <- as.character(x)
|
||||
if (length(x) > 1000) {
|
||||
# for long vectors, base matching is faster than looking up every unique value
|
||||
add_MO_lookup_to_AMR_env()
|
||||
return(x %in% as.character(AMR_env$MO_lookup$mo))
|
||||
}
|
||||
if (is.null(AMR_env$MO_codes_hash)) {
|
||||
add_MO_lookup_to_AMR_env()
|
||||
codes <- unique(as.character(AMR_env$MO_lookup$mo))
|
||||
AMR_env$MO_codes_hash <- list2env(stats::setNames(as.list(rep(TRUE, length(codes))), codes), hash = TRUE, size = length(codes))
|
||||
}
|
||||
ux <- unique(x)
|
||||
valid <- vapply(
|
||||
FUN.VALUE = logical(1),
|
||||
ux,
|
||||
function(code) !is.na(code) && nzchar(code) && exists(code, envir = AMR_env$MO_codes_hash, inherits = FALSE),
|
||||
USE.NAMES = FALSE
|
||||
)
|
||||
valid[match(x, ux)]
|
||||
}
|
||||
|
||||
reset_mo_cache <- function() {
|
||||
AMR_env$MO_codes_hash <- NULL
|
||||
AMR_env$MO_index <- NULL
|
||||
AMR_env$MO_translated <- NULL
|
||||
AMR_env$mo_accepted <- NULL
|
||||
|
||||
Reference in new issue
Block a user