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

(v0.7.0.9006) ab algorithm fix for ATC codes

This commit is contained in:
2019-06-11 15:31:32 +02:00
parent 8f674e19bb
commit 44ab53128e
10 changed files with 30 additions and 25 deletions

15
R/ab.R
View File

@ -203,7 +203,8 @@ as.ab <- function(x) {
# try by removing all spaces
if (x[i] %like% " ") {
found <- suppressWarnings(as.ab(gsub(" +", "", x[i])))
if (length(found) > 0) {
print(found)
if (length(found) > 0 & !is.na(found)) {
x_new[i] <- found[1L]
next
}
@ -212,7 +213,7 @@ as.ab <- function(x) {
# try by removing all spaces and numbers
if (x[i] %like% " " | x[i] %like% "[0-9]") {
found <- suppressWarnings(as.ab(gsub("[ 0-9]", "", x[i])))
if (length(found) > 0) {
if (length(found) > 0 & !is.na(found)) {
x_new[i] <- found[1L]
next
}
@ -222,6 +223,16 @@ as.ab <- function(x) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
}
# take failed ATC codes apart from rest
x_unknown_ATCs <- x_unknown[x_unknown %like% "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]"]
x_unknown <- x_unknown[!x_unknown %in% x_unknown_ATCs]
if (length(x_unknown_ATCs) > 0) {
warning("These ATC codes are not (yet) in the antibiotics data set: ",
paste('"', sort(unique(x_unknown_ATCs)), '"', sep = "", collapse = ', '),
".",
call. = FALSE)
}
if (length(x_unknown) > 0) {
warning("These values could not be coerced to a valid antibiotic ID: ",
paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ', '),