From 82585901a7c328ab17fa8b2bb5b3f9db75ca6c59 Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Wed, 19 Jun 2024 15:41:45 +0200 Subject: [PATCH] (v2.1.1.9061) animal host fix --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/sir.R | 13 ++++++++++--- inst/tinytest/test-sir.R | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 38539428..c1c22119 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.1.1.9060 +Version: 2.1.1.9061 Date: 2024-06-19 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index d1aee2df..c86a2b8b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9060 +# AMR 2.1.1.9061 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)* diff --git a/R/sir.R b/R/sir.R index a1efb0d3..4d8d62e6 100755 --- a/R/sir.R +++ b/R/sir.R @@ -832,7 +832,7 @@ get_guideline <- function(guideline, reference_data) { } convert_host <- function(x, lang = get_AMR_locale()) { - x <- trimws2(tolower(as.character(x))) + x <- gsub("[^a-zA-Z ]", "", trimws2(tolower(as.character(x))), perl = TRUE) x_out <- rep(NA_character_, length(x)) x_out[trimws2(tolower(x)) == "human"] <- "human" x_out[trimws2(tolower(x)) == "ecoff"] <- "ecoff" @@ -860,8 +860,15 @@ 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 (message_not_thrown_before("convert_host", x) && any(is.na(x_out) & !is.na(x))) { - warning_("The following host(s) are invalid: ", vector_and(x[is.na(x_out) & !is.na(x)]), call = FALSE, immediate = TRUE) + 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 diff --git a/inst/tinytest/test-sir.R b/inst/tinytest/test-sir.R index 428d8462..6c410f79 100644 --- a/inst/tinytest/test-sir.R +++ b/inst/tinytest/test-sir.R @@ -36,7 +36,7 @@ expect_identical( c("EUCAST", "CLSI") ) # no missing SDDs -expect_identical(sum(is.na(AMR::clinical_breakpoints$is_SDD)), 0) +expect_identical(sum(is.na(AMR::clinical_breakpoints$is_SDD)), 0L) expect_true(as.sir("S") < as.sir("I")) expect_true(as.sir("I") < as.sir("R"))