diff --git a/NAMESPACE b/NAMESPACE index 8a5b116f..5eb6c006 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,8 +41,8 @@ export(MDRO) export(MRGN) export(ab_atc) export(ab_certe) +export(ab_name) export(ab_official) -export(ab_official_nl) export(ab_property) export(ab_tradenames) export(ab_trivial_nl) diff --git a/NEWS.md b/NEWS.md index 684de83b..6341d900 100755 --- a/NEWS.md +++ b/NEWS.md @@ -37,7 +37,7 @@ mo_fullname("S. group A") # when run on a on a Portuguese system # [1] "Streptococcus grupo A" ``` -* Function `ab_property` and its aliases: `ab_official`, `ab_tradenames`, `ab_certe`, `ab_umcg`, `ab_official_nl` and `ab_trivial_nl` +* Function `ab_property` and its aliases: `ab_name`, `ab_tradenames`, `ab_certe`, `ab_umcg` and `ab_trivial_nl` * Introduction to AMR as a vignette #### Changed @@ -47,7 +47,7 @@ ```r ab_official("Bactroban") # [1] "Mupirocin" - ab_official(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) + ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin" ab_atc(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "R01AX06" "J01CA04" "J01FA10" "J01CF05" @@ -56,7 +56,7 @@ * Function `ratio` is now deprecated and will be removed in a future release, as it is not really the scope of this package * Fix for `as.mic` for values ending in zeroes after a real number * Small fix where *B. fragilis* would not be found in the `microorganisms.umcg` data set -* Fix for `is.rsi.eligible`, now ignores reading marks +* Added `prevalence` column to the `microorganisms` data set * Added parameters `minimum` and `as_percent` to `portion_df` * Support for quasiquotation in the functions series `count_*` and `portions_*`, and `n_rsi`. This allows to check for more than 2 vectors or columns. ```r diff --git a/R/ab_property.R b/R/ab_property.R index ac5a1fee..19c056fd 100644 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -21,6 +21,7 @@ #' Use these functions to return a specific property of an antibiotic from the \code{\link{antibiotics}} data set, based on their ATC code. Get such a code with \code{\link{as.atc}}. #' @param x a (vector of a) valid \code{\link{atc}} code or any text that can be coerced to a valid atc with \code{\link{as.atc}} #' @param property one of the column names of one of the \code{\link{antibiotics}} data set, like \code{"atc"} and \code{"official"} +#' @param language language of the returned text, defaults to the systems language. Either one of \code{"en"} (English) or \code{"nl"} (Dutch). #' @rdname ab_property #' @return A vector of values. In case of \code{ab_tradenames}, if \code{x} is of length one, a vector will be returned. Otherwise a \code{\link{list}}, with \code{x} as names. #' @export @@ -28,8 +29,8 @@ #' @seealso \code{\link{antibiotics}} #' @examples #' ab_atc("amcl") # J01CR02 -#' ab_official("amcl") # Amoxicillin and beta-lactamase inhibitor -#' ab_official_nl("amcl") # Amoxicilline met enzymremmer +#' ab_name("amcl") # Amoxicillin and beta-lactamase inhibitor +#' ab_name("amcl", "nl") # Amoxicilline met enzymremmer #' ab_trivial_nl("amcl") # Amoxicilline/clavulaanzuur #' ab_certe("amcl") # amcl #' ab_umcg("amcl") # AMCL @@ -56,15 +57,25 @@ ab_atc <- function(x) { #' @rdname ab_property #' @export -ab_official <- function(x) { - ab_property(x, "official") +ab_official <- function(x, language = NULL) { + + if (is.null(language)) { + language <- Sys.locale() + } else { + language <- tolower(language[1]) + } + if (language %in% c("en", "")) { + ab_property(x, "official") + } else if (language == "nl") { + ab_property(x, "official_nl") + } else { + stop("Unsupported language: '", language, "' - use one of: 'en', 'nl'", call. = FALSE) + } } #' @rdname ab_property #' @export -ab_official_nl <- function(x) { - ab_property(x, "official_nl") -} +ab_name <- ab_official #' @rdname ab_property #' @export diff --git a/R/data.R b/R/data.R index 6d391b7c..3600cefd 100755 --- a/R/data.R +++ b/R/data.R @@ -122,8 +122,8 @@ #' Data set with human pathogenic microorganisms #' -#' A data set containing 2,630 (potential) human pathogenic microorganisms. MO codes can be looked up using \code{\link{guess_mo}}. -#' @format A \code{\link{tibble}} with 2,630 observations and 10 variables: +#' A data set containing (potential) human pathogenic microorganisms. MO codes can be looked up using \code{\link{guess_mo}}. +#' @format A \code{\link{tibble}} with 2,642 observations and 11 variables: #' \describe{ #' \item{\code{mo}}{ID of microorganism} #' \item{\code{bactsys}}{Bactsyscode of microorganism} @@ -135,6 +135,7 @@ #' \item{\code{aerobic}}{Logical whether bacteria is aerobic} #' \item{\code{type}}{Type of microorganism, like \code{"Bacteria"} and \code{"Fungus/yeast"}} #' \item{\code{gramstain}}{Gram of microorganism, like \code{"Negative rods"}} +#' \item{\code{prevalence}}{A rounded integer based on prevalence of the microorganism. Used internally by \code{\link{as.mo}}, otherwise quite meaningless.} #' } # source MOLIS (LIS of Certe) - \url{https://www.certe.nl} # new <- microorganisms %>% filter(genus == "Bacteroides") %>% .[1,] diff --git a/R/globals.R b/R/globals.R index 268258d2..da66cc39 100755 --- a/R/globals.R +++ b/R/globals.R @@ -47,6 +47,7 @@ globalVariables(c(".", "Pasted", "patient_id", "Percentage", + "prevalence", "R", "real_first_isolate", "S", diff --git a/R/misc.R b/R/misc.R index f5097fa3..f8d18207 100755 --- a/R/misc.R +++ b/R/misc.R @@ -155,6 +155,20 @@ tbl_parse_guess <- function(tbl, tbl } +#' @importFrom dplyr case_when +Sys.locale <- function() { + sys <- base::Sys.getlocale() + case_when( + sys %like% '(Deutsch|German|de_)' ~ "de", + sys %like% '(Nederlands|Dutch|nl_)' ~ "nl", + sys %like% '(Espa.ol|Spanish|es_)' ~ "es", + sys %like% '(Fran.ais|French|fr_)' ~ "fr", + sys %like% '(Portugu.s|Portuguese|pt_)' ~ "pt", + sys %like% '(Italiano|Italian|it_)' ~ "it", + TRUE ~ "en" + ) +} + # transforms date format like "dddd d mmmm yyyy" to "%A %e %B %Y" date_generic <- function(format) { if (!grepl('%', format, fixed = TRUE)) { diff --git a/R/mo.R b/R/mo.R index 7aa4a13c..9ebcea60 100644 --- a/R/mo.R +++ b/R/mo.R @@ -33,12 +33,12 @@ #' #' Use the \code{\link{mo_property}} functions to get properties based on the returned code, see Examples. #' -#' Some exceptions have been built in to get more logical results, based on prevalence of human pathogens. These are: +#' Thus function uses Artificial Intelligence (AI) to help getting more logical results, based on type of input and known prevalence of human pathogens. For example: #' \itemize{ #' \item{\code{"E. coli"} will return the ID of \emph{Escherichia coli} and not \emph{Entamoeba coli}, although the latter would alphabetically come first} -#' \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae}} +#' \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae} for the same reason} #' \item{Something like \code{"p aer"} will return the ID of \emph{Pseudomonas aeruginosa} and not \emph{Pasteurella aerogenes}} -#' \item{Something like \code{"stau"} or \code{"staaur"} will return the ID of \emph{Staphylococcus aureus} and not \emph{Staphylococcus auricularis}} +#' \item{Something like \code{"stau"} or \code{"S aur"} will return the ID of \emph{Staphylococcus aureus} and not \emph{Staphylococcus auricularis}} #' } #' Moreover, this function also supports ID's based on only Gram stain, when the species is not known. \cr #' For example, \code{"Gram negative rods"} and \code{"GNR"} will both return the ID of a Gram negative rod: \code{GNR}. @@ -47,7 +47,7 @@ #' #' [2] Lancefield RC \strong{A serological differentiation of human and other groups of hemolytic streptococci}. 1933. J Exp Med. 57(4): 571–95. \url{https://dx.doi.org/10.1084/jem.57.4.571} #' @export -#' @importFrom dplyr %>% pull left_join +#' @importFrom dplyr %>% pull left_join arrange #' @return Character (vector) with class \code{"mo"}. Unknown values will return \code{NA}. #' @seealso \code{\link{microorganisms}} for the dataframe that is being used to determine ID's. #' @examples @@ -118,7 +118,10 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { } } - MOs <- AMR::microorganisms %>% filter(!mo %like% '^_FAM') # dont search in those + MOs <- AMR::microorganisms %>% + arrange(prevalence) %>% # more expected result on multiple findings + filter(!mo %like% '^_FAM', # don't search in those + (nchar(mo) > 3 | mo %in% c("GNR", "GPR", "GNC", "GPC"))) # no genera failures <- character(0) x_input <- x @@ -144,11 +147,11 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { x_withspaces_start <- paste0('^', x_withspaces) x_withspaces <- paste0('^', x_withspaces, '$') - # print(x) - # print(x_withspaces_all) - # print(x_withspaces_start) - # print(x_withspaces) - # print(x_backup) + # cat(paste0('x "', x, '"\n')) + # cat(paste0('x_withspaces_all "', x_withspaces_all, '"\n')) + # cat(paste0('x_withspaces_start "', x_withspaces_start, '"\n')) + # cat(paste0('x_withspaces "', x_withspaces, '"\n')) + # cat(paste0('x_backup "', x_backup, '"\n')) for (i in 1:length(x)) { if (identical(x_trimmed[i], "")) { @@ -201,7 +204,7 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { next } if (toupper(x_trimmed[i]) == 'VRE') { - x[i] <- 'ENC' + x[i] <- 'ENCSPP' next } if (toupper(x_trimmed[i]) == 'MRPA') { @@ -234,6 +237,13 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { next } + # try any match with genus, keeping spaces, not ending with $ ---- + found <- MOs[which(MOs$genus %like% x_withspaces_start[i] & MOs$mo %like% 'SPP$'),]$mo + if (length(found) > 0) { + x[i] <- found[1L] + next + } + # try any match keeping spaces, not ending with $ ---- found <- MOs[which(MOs$fullname %like% x_withspaces_start[i]),]$mo if (length(found) > 0) { @@ -297,19 +307,6 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { } - # avoid detection of Staphylococcus auricularis in case of S. aureus ---- - x[x == "STAAUC" & toupper(x_backup) != "STAAUC" & !x_backup %like% 'auri'] <- "STAAUR" - # avoid detection of Entamoeba coli in case of E. coli ---- - x[x == "ENMCOL" & toupper(x_backup) != "ENMCOL" & !x_backup %like% '^ent?'] <- "ESCCOL" - # avoid detection of Haematobacter influenzae in case of H. influenzae ---- - x[x == "HABINF" & toupper(x_backup) != "HABINF" & !x_backup %like% '^haema'] <- "HAEINF" - # avoid detection of Pasteurella aerogenes in case of P. aeruginosa ---- - x[x == "PASAER" & toupper(x_backup) != "PASAER" & !(x_backup %like% '^pas?' | x_backup %like% 'aero')] <- "PSEAER" - # avoid detection of Legionella non pneumophila in case of Legionella pneumophila ---- - x[x == "LEGNON" & toupper(x_backup) != "LEGNON" & !x_backup %like% 'non'] <- "LEGPNE" - # avoid detection of Streptobacillus in case of Streptococcus ---- - x[x == "STB" & toupper(x_backup) != "STB" & !x_backup %like% 'streptob'] <- "STC" - failures <- failures[!failures %in% c(NA, NULL, NaN)] if (length(failures) > 0) { warning("These ", length(failures) , " values could not be coerced to a valid mo: ", @@ -376,7 +373,9 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE) { # for the returned genera without species, add species ---- # like "ESC" -> "ESCSPP", but only where the input contained it - indices <- unique(x_input) %like% "[A-Z]{3}SPP" & !x %like% "[A-Z]{3}SPP" + indices <- nchar(unique(x)) == 3 & !x %like% "[A-Z]{3}SPP" & !x %in% c("GNR", "GPR", "GNC", "GPC", + "GNS", "GPS", "GNK", "GPK") + indices <- indices[!is.na(indices)] x[indices] <- paste0(x[indices], 'SPP') # left join the found results to the original input values (x_input) diff --git a/R/mo_property.R b/R/mo_property.R index bf8a3f4d..c712d69f 100644 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -207,7 +207,7 @@ mo_property <- function(x, property = 'fullname', Becker = FALSE, Lancefield = F #' @importFrom dplyr %>% case_when mo_translate <- function(x, language) { if (is.null(language)) { - language <- mo_getlangcode() + language <- Sys.locale() } else { language <- tolower(language[1]) } @@ -350,17 +350,3 @@ mo_translate <- function(x, language) { ) } - -#' @importFrom dplyr case_when -mo_getlangcode <- function() { - sys <- base::Sys.getlocale() - case_when( - sys %like% '(Deutsch|German|de_)' ~ "de", - sys %like% '(Nederlands|Dutch|nl_)' ~ "nl", - sys %like% '(Espa.ol|Spanish|es_)' ~ "es", - sys %like% '(Fran.ais|French|fr_)' ~ "fr", - sys %like% '(Portugu.s|Portuguese|pt_)' ~ "pt", - sys %like% '(Italiano|Italian|it_)' ~ "it", - TRUE ~ "en" - ) -} diff --git a/README.md b/README.md index a75579e4..e6cb07c7 100755 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ This `AMR` package basically does four important things: * You can also identify first *weighted* isolates of every patient, an adjusted version of the CLSI guideline. This takes into account key antibiotics of every strain and compares them. * Use `MDRO` (abbreviation of Multi Drug Resistant Organisms) to check your isolates for exceptional resistance with country-specific guidelines or EUCAST rules. Currently, national guidelines for Germany and the Netherlands are supported. * The data set `microorganisms` contains the family, genus, species, subspecies, colloquial name and Gram stain of almost 3,000 potential human pathogenic microorganisms (bacteria, fungi/yeasts and parasites). This enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like `mo_genus`, `mo_family` or `mo_gramstain`. As they use `as.mo` internally, they also use artificial intelligence. For example, `mo_genus("MRSA")` and `mo_genus("S. aureus")` will both return `"Staphylococcus"`. They also come with support for German, Dutch, French, Italian, Spanish and Portuguese. These functions can be used to add new variables to your data. - * The data set `antibiotics` contains the ATC code, LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains a total of 298 trade names. Use functions like `ab_official` and `ab_tradenames` to look up values. As the `mo_*` functions use `as.mo` internally, the `ab_*` functions use `as.atc` internally so it uses AI to guess your expected result. For example, `ab_official("Fluclox")`, `ab_official("Floxapen")` and `ab_official("J01CF05")` will all return `"Flucloxacillin"`. These functions can again be used to add new variables to your data. + * The data set `antibiotics` contains the ATC code, LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains a total of 298 trade names. Use functions like `ab_name` and `ab_tradenames` to look up values. As the `mo_*` functions use `as.mo` internally, the `ab_*` functions use `as.atc` internally so it uses AI to guess your expected result. For example, `ab_name("Fluclox")`, `ab_name("Floxapen")` and `ab_name("J01CF05")` will all return `"Flucloxacillin"`. These functions can again be used to add new variables to your data. 3. It **analyses the data** with convenient functions that use well-known methods. @@ -388,7 +388,7 @@ antibiotics # A tibble: 423 x 18 # Dataset with bacteria codes and properties like gram stain and # aerobic/anaerobic -microorganisms # A tibble: 2,630 x 10 +microorganisms # A tibble: 2,642 x 11 ``` ## Copyright diff --git a/data/microorganisms.rda b/data/microorganisms.rda index 1bb364a1..a6d4843b 100755 Binary files a/data/microorganisms.rda and b/data/microorganisms.rda differ diff --git a/man/ab_property.Rd b/man/ab_property.Rd index e34fdf7d..f149077d 100644 --- a/man/ab_property.Rd +++ b/man/ab_property.Rd @@ -4,7 +4,7 @@ \alias{ab_property} \alias{ab_atc} \alias{ab_official} -\alias{ab_official_nl} +\alias{ab_name} \alias{ab_trivial_nl} \alias{ab_certe} \alias{ab_umcg} @@ -15,9 +15,9 @@ ab_property(x, property = "official") ab_atc(x) -ab_official(x) +ab_official(x, language = NULL) -ab_official_nl(x) +ab_name(x, language = NULL) ab_trivial_nl(x) @@ -31,6 +31,8 @@ ab_tradenames(x) \item{x}{a (vector of a) valid \code{\link{atc}} code or any text that can be coerced to a valid atc with \code{\link{as.atc}}} \item{property}{one of the column names of one of the \code{\link{antibiotics}} data set, like \code{"atc"} and \code{"official"}} + +\item{language}{language of the returned text, defaults to the systems language. Either one of \code{"en"} (English) or \code{"nl"} (Dutch).} } \value{ A vector of values. In case of \code{ab_tradenames}, if \code{x} is of length one, a vector will be returned. Otherwise a \code{\link{list}}, with \code{x} as names. @@ -40,8 +42,8 @@ Use these functions to return a specific property of an antibiotic from the \cod } \examples{ ab_atc("amcl") # J01CR02 -ab_official("amcl") # Amoxicillin and beta-lactamase inhibitor -ab_official_nl("amcl") # Amoxicilline met enzymremmer +ab_name("amcl") # Amoxicillin and beta-lactamase inhibitor +ab_name("amcl", "nl") # Amoxicilline met enzymremmer ab_trivial_nl("amcl") # Amoxicilline/clavulaanzuur ab_certe("amcl") # amcl ab_umcg("amcl") # AMCL diff --git a/man/as.mo.Rd b/man/as.mo.Rd index 41d658a6..18cb943e 100644 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -40,12 +40,12 @@ Use this function to determine a valid ID based on a genus (and species). Determ Use the \code{\link{mo_property}} functions to get properties based on the returned code, see Examples. -Some exceptions have been built in to get more logical results, based on prevalence of human pathogens. These are: +Thus function uses Artificial Intelligence (AI) to help getting more logical results, based on type of input and known prevalence of human pathogens. For example: \itemize{ \item{\code{"E. coli"} will return the ID of \emph{Escherichia coli} and not \emph{Entamoeba coli}, although the latter would alphabetically come first} - \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae}} + \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae} for the same reason} \item{Something like \code{"p aer"} will return the ID of \emph{Pseudomonas aeruginosa} and not \emph{Pasteurella aerogenes}} - \item{Something like \code{"stau"} or \code{"staaur"} will return the ID of \emph{Staphylococcus aureus} and not \emph{Staphylococcus auricularis}} + \item{Something like \code{"stau"} or \code{"S aur"} will return the ID of \emph{Staphylococcus aureus} and not \emph{Staphylococcus auricularis}} } Moreover, this function also supports ID's based on only Gram stain, when the species is not known. \cr For example, \code{"Gram negative rods"} and \code{"GNR"} will both return the ID of a Gram negative rod: \code{GNR}. diff --git a/man/microorganisms.Rd b/man/microorganisms.Rd index 73944191..f7eecd09 100755 --- a/man/microorganisms.Rd +++ b/man/microorganisms.Rd @@ -4,7 +4,7 @@ \name{microorganisms} \alias{microorganisms} \title{Data set with human pathogenic microorganisms} -\format{A \code{\link{tibble}} with 2,630 observations and 10 variables: +\format{A \code{\link{tibble}} with 2,642 observations and 11 variables: \describe{ \item{\code{mo}}{ID of microorganism} \item{\code{bactsys}}{Bactsyscode of microorganism} @@ -16,12 +16,13 @@ \item{\code{aerobic}}{Logical whether bacteria is aerobic} \item{\code{type}}{Type of microorganism, like \code{"Bacteria"} and \code{"Fungus/yeast"}} \item{\code{gramstain}}{Gram of microorganism, like \code{"Negative rods"}} + \item{\code{prevalence}}{A rounded integer based on prevalence of the microorganism. Used internally by \code{\link{as.mo}}, otherwise quite meaningless.} }} \usage{ microorganisms } \description{ -A data set containing 2,630 (potential) human pathogenic microorganisms. MO codes can be looked up using \code{\link{guess_mo}}. +A data set containing (potential) human pathogenic microorganisms. MO codes can be looked up using \code{\link{guess_mo}}. } \seealso{ \code{\link{guess_mo}} \code{\link{antibiotics}} \code{\link{microorganisms.umcg}} diff --git a/tests/testthat/test-ab_property.R b/tests/testthat/test-ab_property.R index fb32a170..89d7a50f 100644 --- a/tests/testthat/test-ab_property.R +++ b/tests/testthat/test-ab_property.R @@ -2,8 +2,9 @@ context("ab_property.R") test_that("ab_property works", { expect_equal(ab_certe("amox"), "amox") - expect_equal(ab_official("amox"), "Amoxicillin") - expect_equal(ab_official_nl("amox"), "Amoxicilline") + expect_equal(ab_name("amox", language = "en"), "Amoxicillin") + expect_equal(ab_name("amox", language = "nl"), "Amoxicilline") + expect_equal(ab_official("amox", language = "en"), "Amoxicillin") expect_equal(ab_trivial_nl("amox"), "Amoxicilline") expect_equal(ab_umcg("amox"), "AMOX") expect_equal(class(ab_tradenames("amox")), "character") @@ -11,4 +12,6 @@ test_that("ab_property works", { expect_equal(ab_atc("amox"), as.character(as.atc("amox"))) expect_error(ab_property("amox", "invalid property")) + expect_error(ab_name("amox", language = "INVALID")) + expect_output(print(ab_name("amox", language = NULL))) }) diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index fc1e3343..1e459dac 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -3,7 +3,7 @@ context("mo.R") test_that("as.mo works", { library(dplyr) - MOs <- AMR::microorganisms %>% filter(!is.na(mo)) + MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3) expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo))) expect_identical( @@ -12,18 +12,20 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL") expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL") - expect_equal(as.character(as.mo("Escherichia species")), "ESC") + expect_equal(as.character(as.mo("Escherichia species")), "ESCSPP") + expect_equal(as.character(as.mo("Escherichia")), "ESCSPP") expect_equal(as.character(as.mo(" ESCCOL ")), "ESCCOL") + expect_equal(as.character(as.mo("coli")), "ESCCOL") # not Campylobacter expect_equal(as.character(as.mo("klpn")), "KLEPNE") - expect_equal(as.character(as.mo("Klebsiella")), "KLE") + expect_equal(as.character(as.mo("Klebsiella")), "KLESPP") expect_equal(as.character(as.mo("K. pneu rhino")), "KLEPNERH") # K. pneumoniae subspp. rhinoscleromatis - expect_equal(as.character(as.mo("Bartonella")), "BAR") + expect_equal(as.character(as.mo("Bartonella")), "BARSPP") expect_equal(as.character(as.mo("C. difficile")), "CLODIF") expect_equal(as.character(as.mo("L. pneumophila")), "LEGPNE") expect_equal(as.character(as.mo("L. non pneumophila")), "LEGNON") expect_equal(as.character(as.mo("S. beta-haemolytic")), "STCHAE") - expect_equal(as.character(as.mo("Strepto")), "STC") # not Streptobacillus - expect_equal(as.character(as.mo("Streptococcus")), "STC") # not Peptostreptoccus + expect_equal(as.character(as.mo("Strepto")), "STCSPP") + expect_equal(as.character(as.mo("Streptococcus")), "STCSPP") # not Peptostreptoccus expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("STCGRA", "STCGRB")) @@ -39,7 +41,7 @@ test_that("as.mo works", { expect_equal(as.character(as.mo("bctfgr")), "BACFRA") expect_equal(as.character(as.mo("MRSE")), "STAEPI") - expect_equal(as.character(as.mo("VRE")), "ENC") + expect_equal(as.character(as.mo("VRE")), "ENCSPP") expect_equal(as.character(as.mo("MRPA")), "PSEAER") expect_equal(as.character(as.mo("PISP")), "STCPNE") expect_equal(as.character(as.mo("PRSP")), "STCPNE") @@ -67,8 +69,9 @@ test_that("as.mo works", { expect_identical(as.character(guess_mo("S. epidermidis", Becker = FALSE)), "STAEPI") expect_identical(as.character(guess_mo("S. epidermidis", Becker = TRUE)), "STACNS") expect_identical(as.character(guess_mo("STAEPI", Becker = TRUE)), "STACNS") - expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "STAINT") - expect_identical(as.character(guess_mo("S. intermedius", Becker = TRUE)), "STACPS") + expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "STCINT") # Strep (!) intermedius + expect_identical(as.character(guess_mo("Sta intermedius",Becker = FALSE)), "STAINT") + expect_identical(as.character(guess_mo("Sta intermedius",Becker = TRUE)), "STACPS") expect_identical(as.character(guess_mo("STAINT", Becker = TRUE)), "STACPS") # aureus must only be influenced if Becker = "all" expect_identical(as.character(guess_mo("STAAUR", Becker = FALSE)), "STAAUR") @@ -103,8 +106,9 @@ test_that("as.mo works", { select(genus) %>% as.mo() %>% as.character(), - c("ESC", "ESC", "STA", "STA", "STA", - "STA", "STA", "STA", "STA", "STA")) + paste0(c("ESC", "ESC", "STA", "STA", "STA", + "STA", "STA", "STA", "STA", "STA"), + "SPP")) # select with two columns expect_identical( diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 391e73ce..ca183bd2 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -18,7 +18,7 @@ test_that("mo_property works", { # test integrity library(dplyr) - MOs <- AMR::microorganisms %>% filter(!is.na(mo)) + MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3) expect_identical(MOs$fullname, mo_fullname(MOs$fullname, language = "en")) mo_clean <- MOs$mo