1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 07:51:57 +02:00

(v1.2.0.9000) eucast_rules() fix for tibbles

This commit is contained in:
2020-06-02 16:05:56 +02:00
parent b44e2c9202
commit 02d07b9fb3
13 changed files with 284 additions and 253 deletions

19
R/ab.R
View File

@ -103,21 +103,20 @@ as.ab <- function(x, ...) {
x <- unique(x_bak_clean)
x_new <- rep(NA_character_, length(x))
x_unknown <- character(0)
for (i in seq_len(length(x))) {
if (is.na(x[i]) | is.null(x[i])) {
next
}
if (identical(x[i], "")) {
if (identical(x[i], "") |
# no short names:
nchar(x[i]) <= 2 |
# prevent "bacteria" from coercing to TMP, since Bacterial is a brand name of it:
identical(tolower(x[i]), "bacteria")) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
next
}
# prevent "bacteria" from coercing to TMP, since Bacterial is a brand name of it
if (identical(tolower(x[i]), "bacteria")) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
next
}
# exact AB code
found <- antibiotics[which(antibiotics$ab == toupper(x[i])), ]$ab
if (length(found) > 0) {
@ -217,7 +216,7 @@ as.ab <- function(x, ...) {
x_spelling <- gsub("(.)\\1+", "\\1+", x_spelling)
# replace spaces and slashes with a possibility on both
x_spelling <- gsub("[ /]", "( .*|.*/)", x_spelling)
# try if name starts with it
found <- antibiotics[which(antibiotics$name %like% paste0("^", x_spelling)), ]$ab
if (length(found) > 0) {
@ -303,7 +302,7 @@ as.ab <- function(x, ...) {
next
}
}
# not found
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
}