auto-remove missing ABs in `antibiogram()`

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-02-22 16:00:52 +01:00
parent c2cfc5ef84
commit 551aaf6517
4 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 1.8.2.9139 Version: 1.8.2.9140
Date: 2023-02-22 Date: 2023-02-22
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)

View File

@ -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!)* *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*

View File

@ -313,14 +313,18 @@ antibiogram <- function(x,
df_ab <- get_column_abx(x, verbose = FALSE, info = FALSE) df_ab <- get_column_abx(x, verbose = FALSE, info = FALSE)
# get antibiotics from user # get antibiotics from user
user_ab <- suppressMessages(suppressWarnings(lapply(antibiotics, as.ab, flag_multiple_results = FALSE, info = FALSE))) 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))])) 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 # remove non-existing columns
# non_existing <- unlist(antibiotics)[is.na(unlist(abx_ab))] out[!is.na(out)]
# if (length(non_existing) > 0) { })
# warning_("The following antibiotics were not available and ignored: ", vector_and(non_existing, sort = FALSE)) user_ab <- user_ab[unlist(lapply(user_ab, length)) > 0]
# abx_user <- Map(antibiotics, abx_user, f = function(input, ab) input[!is.na(ab)])
# } 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 # make list unique
antibiotics <- unique(user_ab) antibiotics <- unique(user_ab)

View File

@ -115,7 +115,7 @@ Like many other functions in this package, `antibiogram()` comes with support fo
```r ```r
antibiogram(example_isolates, antibiogram(example_isolates,
antibiotics = c("CIP", "TOB", "GEN"), antibiotics = c("cipro", "tobra", "genta"), # any arbitrary name or code will work
mo_transform = "gramstain", mo_transform = "gramstain",
ab_transform = "name", ab_transform = "name",
language = "uk") # Ukrainian language = "uk") # Ukrainian