diff --git a/DESCRIPTION b/DESCRIPTION index 80507039..fd06087f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.2.9138 +Version: 1.8.2.9139 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 f6840775..70b0e25f 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9138 +# AMR 1.8.2.9139 *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* diff --git a/R/ab.R b/R/ab.R index 73590bba..e57754cd 100755 --- a/R/ab.R +++ b/R/ab.R @@ -249,8 +249,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) { next } - print("here") - # length of input is quite long, and Levenshtein distance is only max 2 if (nchar(x[i]) >= 10) { levenshtein <- as.double(utils::adist(x[i], AMR_env$AB_lookup$generalised_name)) diff --git a/R/antibiogram.R b/R/antibiogram.R index da4ae427..940bbd3d 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -31,7 +31,7 @@ #' #' Generate an antibiogram, and communicate the results in plots or tables. These functions follow the logic of Klinker *et al.* and Barbieri *et al.* (see *Source*), and allow reporting in e.g. R Markdown and Quarto as well. #' @param x a [data.frame] containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see [as.sir()]) -#' @param antibiotics vector of column names, or (any combinations of) [antibiotic selectors][antibiotic_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be column names separated with `"+"`, such as "TZP+TOB" given that the data set contains columns "TZP" and "TOB". See *Examples*. +#' @param antibiotics vector of any antibiotic name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antibiotic selectors][antibiotic_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be set to values separated with `"+"`, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in `x`. See *Examples*. #' @param mo_transform a character to transform microorganism input - must be "name", "shortname", "gramstain", or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input. #' @param ab_transform a character to transform antibiotic input - must be one of the column names of the [antibiotics] data set: `r vector_or(colnames(antibiotics), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input. #' @param syndromic_group a column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*. @@ -165,8 +165,9 @@ #' mo_transform = "gramstain" #' ) #' +#' # names of antibiotics do not need to resemble columns exactly: #' antibiogram(example_isolates, -#' antibiotics = c("TZP", "TZP+TOB"), +#' antibiotics = c("Cipro", "cipro + genta"), #' mo_transform = "gramstain", #' ab_transform = "name", #' sep = " & " @@ -313,25 +314,16 @@ antibiogram <- function(x, # 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))])) - # - # names(user_ab) <- antibiotics.bak - # user_ab <- user_ab - return(1) - # cols <- - # convert antibiotics to valid AB codes - abx_ab <- suppressMessages(suppressWarnings(lapply(antibiotics, as.ab, flag_multiple_results = FALSE, info = FALSE))) - # match them to existing column names - abx_user <- lapply(abx_ab, function(a) unname(names(cols)[match(a, names(cols))])) - + # 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 <- 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)]) + # } + # make list unique - antibiotics <- unique(abx_user) - print(antibiotics) + antibiotics <- unique(user_ab) # go through list to set AMR in combinations for (i in seq_len(length(antibiotics))) { abx <- antibiotics[[i]] diff --git a/R/data.R b/R/data.R index ab7b2f88..5773d73b 100755 --- a/R/data.R +++ b/R/data.R @@ -197,7 +197,7 @@ #' Data Set with `r format(nrow(WHONET), big.mark = " ")` Isolates - WHONET Example #' -#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our [example_isolates] data set. All patient names are created using online surname generators and are only in place for practice purposes. +#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our [example_isolates] data set. All patient names were created using online surname generators and are only in place for practice purposes. #' @format A [tibble][tibble::tibble] with `r format(nrow(WHONET), big.mark = " ")` observations and `r ncol(WHONET)` variables: #' - `Identification number`\cr ID of the sample #' - `Specimen number`\cr ID of the specimen diff --git a/R/sir.R b/R/sir.R index 14d658e3..3a20c0e0 100755 --- a/R/sir.R +++ b/R/sir.R @@ -300,7 +300,7 @@ is_sir_eligible <- function(x, threshold = 0.05) { #' @export # extra param: warn (logical, to never throw a warning) as.sir.default <- function(x, ...) { - if (is.sir(x)) { + if (inherits(x, "sir")) { return(x) } diff --git a/R/zz_deprecated.R b/R/zz_deprecated.R index b43304ce..46755748 100755 --- a/R/zz_deprecated.R +++ b/R/zz_deprecated.R @@ -92,8 +92,7 @@ ggplot_rsi_predict <- function(...) { #' @export is.rsi <- function(...) { # REMINDER: change as.sir() to remove the deprecation warning there - deprecation_warning("is.rsi", "is.sir") - is.sir(...) + suppressWarnings(is.sir(...)) } #' @rdname AMR-deprecated #' @export diff --git a/data/WHONET.rda b/data/WHONET.rda index b4b8159f..386ccfc3 100644 Binary files a/data/WHONET.rda and b/data/WHONET.rda differ diff --git a/man/WHONET.Rd b/man/WHONET.Rd index c07d4c71..cdb85747 100644 --- a/man/WHONET.Rd +++ b/man/WHONET.Rd @@ -39,7 +39,7 @@ A \link[tibble:tibble]{tibble} with 500 observations and 53 variables: WHONET } \description{ -This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our \link{example_isolates} data set. All patient names are created using online surname generators and are only in place for practice purposes. +This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our \link{example_isolates} data set. All patient names were created using online surname generators and are only in place for practice purposes. } \details{ Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd index 5f4b296c..a18be744 100644 --- a/man/antibiogram.Rd +++ b/man/antibiogram.Rd @@ -46,7 +46,7 @@ antibiogram( \arguments{ \item{x}{a \link{data.frame} containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})} -\item{antibiotics}{vector of column names, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be column names separated with \code{"+"}, such as "TZP+TOB" given that the data set contains columns "TZP" and "TOB". See \emph{Examples}.} +\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.} \item{mo_transform}{a character to transform microorganism input - must be "name", "shortname", "gramstain", or one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.} @@ -194,8 +194,9 @@ antibiogram(example_isolates, mo_transform = "gramstain" ) +# names of antibiotics do not need to resemble columns exactly: antibiogram(example_isolates, - antibiotics = c("TZP", "TZP+TOB"), + antibiotics = c("Cipro", "cipro + genta"), mo_transform = "gramstain", ab_transform = "name", sep = " & "