1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-10 17:01:52 +02:00

(v2.1.1.9073) unit tests

This commit is contained in:
2024-09-19 13:57:36 +02:00
parent ef8ef28650
commit 4e96a56b6a
5 changed files with 16 additions and 26 deletions

17
R/sir.R
View File

@ -623,7 +623,7 @@ as.sir.data.frame <- function(x,
}
# -- host
if (missing(breakpoint_type) && any(host %in% AMR_env$host_preferred_order, na.rm = TRUE)) {
if (missing(breakpoint_type) && any(host %in% clinical_breakpoints$host[!clinical_breakpoints$host %in% c("human", "ECOFF")], na.rm = TRUE)) {
message_("Assuming `breakpoint_type = \"animal\"` since `host` contains animal species.")
breakpoint_type <- "animal"
} else if (any(!suppressMessages(convert_host(host)) %in% c("human", "ECOFF"), na.rm = TRUE)) {
@ -865,16 +865,7 @@ convert_host <- function(x, lang = get_AMR_locale()) {
x_out[is.na(x_out) & (x %like% "sheep|ovine" | x %like% translate_AMR("sheep|sheeps|ovine", lang))] <- "sheep"
x_out[is.na(x_out) & (x %like% "snake|serpentine" | x %like% translate_AMR("snake|snakes|serpentine", lang))] <- "snakes"
x_out[is.na(x_out) & (x %like% "turkey|meleagrine" | x %like% translate_AMR("turkey|turkeys|meleagrine", lang))] <- "turkey"
if (any(x_out %in% c(NA_character_, "animal"))) {
x_out[is.na(x_out) & x == "animal"] <- AMR_env$host_preferred_order[1]
if (message_not_thrown_before("as.sir", "convert_host_missing")) {
message_(ifelse(any(is.na(x_out) & !is.na(x), na.rm = TRUE),
paste0("The following host(s) are invalid: ", vector_and(x[is.na(x_out) & !is.na(x)]), ". "),
""),
"For missing animal hosts, assuming \"", AMR_env$host_preferred_order[1], "\", since these have the highest breakpoint availability.")
x_out[is.na(x_out)] <- AMR_env$host_preferred_order[1]
}
}
x_out[x_out == "ecoff"] <- "ECOFF"
x_out
}
@ -929,9 +920,9 @@ as_sir_method <- function(method_short,
# get host
if (breakpoint_type == "animal") {
if (is.null(host)) {
host <- AMR_env$host_preferred_order[1]
host <- "dogs"
if (message_not_thrown_before("as.sir", "host_missing")) {
message_("Animal hosts not set in `host`, assuming `host = \"", host, "\"`, since these have the highest breakpoint availability.\n\n")
message_("Animal hosts not set in `host`, assuming `host = \"dogs\"`, since these have the highest breakpoint availability.\n\n")
}
}
} else {

View File

@ -205,8 +205,6 @@ AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE)
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
AMR_env$host_preferred_order <- names(sort(table(AMR::clinical_breakpoints$host[!AMR::clinical_breakpoints$host %in% AMR::clinical_breakpoints$type]), decreasing = TRUE))
}
.onAttach <- function(lib, pkg) {