From 05d536ebb7e1897cf0606c1308ff9b3bbdf0239f Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Thu, 17 Nov 2022 15:23:29 +0100 Subject: [PATCH] complexes --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- R/mo.R | 6 +++++- R/rsi.R | 7 ++++++- README.md | 2 +- inst/tinytest/test-mo.R | 2 ++ inst/tinytest/test-rsi.R | 6 ++++++ 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 55008ba3..b6546527 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.8.2.9051 -Date: 2022-11-14 +Version: 1.8.2.9052 +Date: 2022-11-17 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index bc251510..20b07483 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9051 +# AMR 1.8.2.9052 This version will eventually become v2.0! We're happy to reach a new major milestone soon! diff --git a/R/mo.R b/R/mo.R index daaf67d1..7c1b851c 100755 --- a/R/mo.R +++ b/R/mo.R @@ -180,6 +180,10 @@ as.mo <- function(x, x <- replace_ignore_pattern(x, ignore_pattern) x_lower <- tolower(x) + + if (any(trimws2(x_lower) %like_case% "complex$", na.rm = TRUE)) { + warning_("in `as.mo()`: translation of complexes is not supported at the moment - the input text 'complex' was ignored.", call = FALSE) + } # WHONET: xxx = no growth x[x_lower %in% c("", "xxx", "na", "nan")] <- NA_character_ @@ -521,7 +525,7 @@ mo_cleaning_regex <- function() { "|", "([({]|\\[).+([})]|\\])", "|", - "(^| )(e?spp|e?ssp|e?ss|e?sp|e?subsp|sube?species|biovar|biotype|serovar|e?species)[.]*( |$))" + "(^| )(e?spp|e?ssp|e?ss|e?sp|e?subsp|sube?species|biovar|biotype|serovar|serogr.?up|e?species|complex)[.]*( |$))" ) } diff --git a/R/rsi.R b/R/rsi.R index c8ca6588..7b98a3b0 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -285,7 +285,7 @@ as.rsi.default <- function(x, ...) { x.bak <- x x <- as.character(x) # this is needed to prevent the vctrs pkg from throwing an error - + if (inherits(x.bak, c("integer", "numeric", "double")) && all(x %in% c(1:3, NA))) { # support haven package for importing e.g., from SPSS - it adds the 'labels' attribute lbls <- attributes(x.bak)$labels @@ -298,6 +298,10 @@ as.rsi.default <- function(x, ...) { x[x.bak == 2] <- "I" x[x.bak == 3] <- "R" } + } else if (inherits(x.bak, "character") && all(x %in% c("1", "2", "3", "S", "I", "R", NA_character_))) { + x[x.bak == "1"] <- "S" + x[x.bak == "2"] <- "I" + x[x.bak == "3"] <- "R" } else if (!all(is.na(x)) && !identical(levels(x), c("R", "S", "I")) && !all(x %in% c("R", "S", "I", NA))) { if (all(x %unlike% "(R|S|I)", na.rm = TRUE)) { # check if they are actually MICs or disks @@ -312,6 +316,7 @@ as.rsi.default <- function(x, ...) { x <- trimws2(as.character(unlist(x))) x[x %in% c(NA, "", "-", "NULL")] <- NA_character_ x.bak <- x + na_before <- length(x[is.na(x)]) # correct for translations diff --git a/README.md b/README.md index 22667bef..c28e9582 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `AMR` (for R) - + ---- diff --git a/inst/tinytest/test-mo.R b/inst/tinytest/test-mo.R index 66ca08a9..8cd2e83f 100644 --- a/inst/tinytest/test-mo.R +++ b/inst/tinytest/test-mo.R @@ -80,6 +80,8 @@ expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MILL") expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAMN", "B_GRAMP")) +expect_warning(as.mo("Acinetobacter calcoaceticus/baumannii complex")) + # prevalent MO expect_identical( suppressWarnings(as.character( diff --git a/inst/tinytest/test-rsi.R b/inst/tinytest/test-rsi.R index 6467c6aa..0a8c3f8e 100644 --- a/inst/tinytest/test-rsi.R +++ b/inst/tinytest/test-rsi.R @@ -81,6 +81,12 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { expect_equal(sum(is.rsi(example_isolates)), 40) expect_stdout(print(tibble(ab = as.rsi("S")))) + + expect_true(example_isolates %>% + select(AMC, MEM) %>% + mutate(MEM = as.rsi(ifelse(AMC == "S", "S", MEM))) %>% + pull(MEM) %>% + is.rsi()) } if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) { expect_inherits(