1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-10 06:21:50 +02:00

Replace RSI with SIR

This commit is contained in:
Dr. Matthijs Berends
2023-01-21 23:47:20 +01:00
committed by GitHub
parent 24b12024ce
commit 98e62c9af2
127 changed files with 1746 additions and 1648 deletions

66
R/zzz.R
View File

@ -55,7 +55,7 @@ AMR_env$av_previously_coerced <- data.frame(
av = character(0),
stringsAsFactors = FALSE
)
AMR_env$rsi_interpretation_history <- data.frame(
AMR_env$sir_interpretation_history <- data.frame(
datetime = Sys.time()[0],
index = integer(0),
ab_input = character(0),
@ -97,32 +97,34 @@ if (utf8_supported && !is_latex) {
s3_register("pillar::pillar_shaft", "ab")
s3_register("pillar::pillar_shaft", "av")
s3_register("pillar::pillar_shaft", "mo")
s3_register("pillar::pillar_shaft", "rsi")
s3_register("pillar::pillar_shaft", "sir")
s3_register("pillar::pillar_shaft", "rsi") # remove in a later version
s3_register("pillar::pillar_shaft", "mic")
s3_register("pillar::pillar_shaft", "disk")
s3_register("pillar::type_sum", "ab")
s3_register("pillar::type_sum", "av")
s3_register("pillar::type_sum", "mo")
s3_register("pillar::type_sum", "rsi")
s3_register("pillar::type_sum", "sir")
s3_register("pillar::type_sum", "rsi") # remove in a later version
s3_register("pillar::type_sum", "mic")
s3_register("pillar::type_sum", "disk")
# Support for frequency tables from the cleaner package
s3_register("cleaner::freq", "mo")
s3_register("cleaner::freq", "rsi")
s3_register("cleaner::freq", "sir")
# Support for skim() from the skimr package
if (pkg_is_available("skimr", also_load = FALSE, min_version = "2.0.0")) {
s3_register("skimr::get_skimmers", "mo")
s3_register("skimr::get_skimmers", "rsi")
s3_register("skimr::get_skimmers", "sir")
s3_register("skimr::get_skimmers", "mic")
s3_register("skimr::get_skimmers", "disk")
}
# Support for autoplot() from the ggplot2 package
s3_register("ggplot2::autoplot", "rsi")
s3_register("ggplot2::autoplot", "sir")
s3_register("ggplot2::autoplot", "mic")
s3_register("ggplot2::autoplot", "disk")
s3_register("ggplot2::autoplot", "resistance_predict")
# Support for fortify from the ggplot2 package
s3_register("ggplot2::fortify", "rsi")
s3_register("ggplot2::fortify", "sir")
s3_register("ggplot2::fortify", "mic")
s3_register("ggplot2::fortify", "disk")
# Support vctrs package for use in e.g. dplyr verbs
@ -164,11 +166,11 @@ if (utf8_supported && !is_latex) {
s3_register("vctrs::vec_cast", "mic.character")
s3_register("vctrs::vec_cast", "mic.double")
s3_register("vctrs::vec_math", "mic")
# S3: rsi
s3_register("vctrs::vec_ptype2", "character.rsi")
s3_register("vctrs::vec_ptype2", "rsi.character")
s3_register("vctrs::vec_cast", "character.rsi")
s3_register("vctrs::vec_cast", "rsi.character")
# S3: sir
s3_register("vctrs::vec_ptype2", "character.sir")
s3_register("vctrs::vec_ptype2", "sir.character")
s3_register("vctrs::vec_cast", "character.sir")
s3_register("vctrs::vec_cast", "sir.character")
# if mo source exists, fire it up (see mo_source())
if (tryCatch(file.exists(getOption("AMR_mo_source", "~/mo_source.rds")), error = function(e) FALSE)) {
@ -179,11 +181,10 @@ if (utf8_supported && !is_latex) {
try(loadNamespace("tibble"), silent = TRUE)
}
# reference data - they have additional columns compared to `antibiotics` and `microorganisms` to improve speed
# reference data - they have additional to improve algorithm speed
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
AMR_env$AB_lookup <- create_AB_lookup()
AMR_env$AV_lookup <- create_AV_lookup()
AMR_env$MO_lookup <- create_MO_lookup()
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
}
.onAttach <- function(lib, pkg) {
@ -206,36 +207,3 @@ if (utf8_supported && !is_latex) {
}, error = function(e) packageStartupMessage("Failed: ", e$message))
}
}
# Helper functions --------------------------------------------------------
create_AB_lookup <- function() {
cbind(AMR::antibiotics, AB_LOOKUP)
}
create_AV_lookup <- function() {
cbind(AMR::antivirals, AV_LOOKUP)
}
create_MO_lookup <- function() {
MO_lookup <- AMR::microorganisms
MO_lookup$kingdom_index <- NA_real_
MO_lookup[which(MO_lookup$kingdom == "Bacteria" | MO_lookup$mo == "UNKNOWN"), "kingdom_index"] <- 1
MO_lookup[which(MO_lookup$kingdom == "Fungi"), "kingdom_index"] <- 2
MO_lookup[which(MO_lookup$kingdom == "Protozoa"), "kingdom_index"] <- 3
MO_lookup[which(MO_lookup$kingdom == "Archaea"), "kingdom_index"] <- 4
# all the rest
MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5
if (length(MO_FULLNAME_LOWER) != nrow(MO_lookup)) {
packageStartupMessage("fullname_lower not same size - applied tolower(), update sysdata.rda!")
MO_lookup$fullname_lower <- tolower(MO_lookup$fullname)
} else {
MO_lookup$fullname_lower <- MO_FULLNAME_LOWER
}
MO_lookup$full_first <- substr(MO_lookup$fullname_lower, 1, 1)
MO_lookup$species_first <- tolower(substr(MO_lookup$species, 1, 1)) # tolower for groups (Streptococcus, Salmonella)
MO_lookup$subspecies_first <- tolower(substr(MO_lookup$subspecies, 1, 1)) # tolower for Salmonella serovars
MO_lookup
}