From 551aaf651768b3faa884ce03994cefdf4099ca09 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Wed, 22 Feb 2023 16:00:52 +0100 Subject: [PATCH] auto-remove missing ABs in `antibiogram()` --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/antibiogram.R | 20 ++++++++++++-------- index.md | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd06087f..f78e837c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.2.9139 +Version: 1.8.2.9140 Date: 2023-02-22 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 70b0e25f..2efd3b2a 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9139 +# AMR 1.8.2.9140 *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* diff --git a/R/antibiogram.R b/R/antibiogram.R index 940bbd3d..c599a24e 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -313,15 +313,19 @@ antibiogram <- function(x, df_ab <- get_column_abx(x, verbose = FALSE, info = FALSE) # get antibiotics from user user_ab <- suppressMessages(suppressWarnings(lapply(antibiotics, as.ab, flag_multiple_results = FALSE, info = FALSE))) - user_ab <- lapply(user_ab, function(x) unname(df_ab[match(x, names(df_ab))])) - - # remove non-existing columns - # non_existing <- unlist(antibiotics)[is.na(unlist(abx_ab))] - # if (length(non_existing) > 0) { - # warning_("The following antibiotics were not available and ignored: ", vector_and(non_existing, sort = FALSE)) - # abx_user <- Map(antibiotics, abx_user, f = function(input, ab) input[!is.na(ab)]) - # } + non_existing <- character(0) + user_ab <- lapply(user_ab, function(x) { + out <- unname(df_ab[match(x, names(df_ab))]) + non_existing <<- c(non_existing, x[is.na(out) & !is.na(x)]) + # remove non-existing columns + out[!is.na(out)] + }) + user_ab <- user_ab[unlist(lapply(user_ab, length)) > 0] + if (length(non_existing) > 0) { + warning_("The following antibiotics were not available and ignored: ", vector_and(ab_name(non_existing, language = NULL, tolower = TRUE), quotes = FALSE)) + } + # make list unique antibiotics <- unique(user_ab) # go through list to set AMR in combinations diff --git a/index.md b/index.md index 00358f38..e6d6134b 100644 --- a/index.md +++ b/index.md @@ -115,7 +115,7 @@ Like many other functions in this package, `antibiogram()` comes with support fo ```r antibiogram(example_isolates, - antibiotics = c("CIP", "TOB", "GEN"), + antibiotics = c("cipro", "tobra", "genta"), # any arbitrary name or code will work mo_transform = "gramstain", ab_transform = "name", language = "uk") # Ukrainian