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

fix for antibiogram(), transform WHONET data set to sir

This commit is contained in:
2023-02-22 15:40:05 +01:00
parent dad25302f2
commit c2cfc5ef84
10 changed files with 20 additions and 30 deletions

2
R/ab.R
View File

@ -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))

View File

@ -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]]

View File

@ -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

View File

@ -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)
}

View File

@ -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