From a84101db08d28afa55787539490e4fd29261f39a Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Wed, 22 Feb 2023 16:26:13 +0100 Subject: [PATCH] N for only 1 AB in --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/antibiogram.R | 36 +++++++++++++++++++++--------------- man/antibiogram.Rd | 25 ++++++++++++------------- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f78e837c..f2afc73d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.2.9140 +Version: 1.8.2.9141 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 2efd3b2a..e341c871 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9140 +# AMR 1.8.2.9141 *(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 c599a24e..3090a844 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -188,12 +188,11 @@ #' # with a custom language, though this will be determined automatically #' # (i.e., this table will be in Spanish on Spanish systems) #' antibiogram(ex1, -#' antibiotics = aminoglycosides(), -#' ab_transform = "name", -#' syndromic_group = ifelse(ex1$ward == "ICU", -#' "UCI", "No UCI" -#' ), -#' language = "es" +#' antibiotics = aminoglycosides(), +#' ab_transform = "name", +#' syndromic_group = ifelse(ex1$ward == "ICU", +#' "UCI", "No UCI"), +#' language = "es" #' ) #' #' @@ -201,13 +200,13 @@ #' #' # the data set could contain a filter for e.g. respiratory specimens/ICU #' antibiogram(example_isolates, -#' antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), -#' mo_transform = "gramstain", -#' minimum = 10, # this should be >=30, but now just as example -#' syndromic_group = ifelse(example_isolates$age >= 65 & -#' example_isolates$gender == "M", -#' "WISCA Group 1", "WISCA Group 2" -#' ) +#' antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), +#' mo_transform = "gramstain", +#' minimum = 10, # this should be >=30, but now just as example +#' syndromic_group = ifelse(example_isolates$age >= 65 & +#' example_isolates$gender == "M", +#' "WISCA Group 1", "WISCA Group 2" +#' ) #' ) #' #' # Print the output for R Markdown / Quarto ----------------------------- @@ -488,8 +487,15 @@ antibiogram <- function(x, count_group <- n_per_mo$count[match(new_df[[1]], n_per_mo$mo)] edit_col <- 1 } - new_df[[edit_col]] <- paste0(new_df[[edit_col]], " (", count_group, ")") - colnames(new_df)[edit_col] <- paste(colnames(new_df)[edit_col], "(N min-max)") + if (NCOL(new_df) == edit_col + 1) { + # only 1 antibiotic + new_df[[edit_col]] <- paste0(new_df[[edit_col]], " (", unlist(lapply(strsplit(count_group, "-"), function(x) x[1])), ")") + colnames(new_df)[edit_col] <- paste(colnames(new_df)[edit_col], "(N)") + } else { + # more than 1 antibiotic + new_df[[edit_col]] <- paste0(new_df[[edit_col]], " (", count_group, ")") + colnames(new_df)[edit_col] <- paste(colnames(new_df)[edit_col], "(N min-max)") + } } out <- as_original_data_class(new_df, class(x), extra_class = "antibiogram") diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd index a18be744..a73d088b 100644 --- a/man/antibiogram.Rd +++ b/man/antibiogram.Rd @@ -217,12 +217,11 @@ ex1 <- example_isolates[which(mo_genus() == "Escherichia"), ] # with a custom language, though this will be determined automatically # (i.e., this table will be in Spanish on Spanish systems) antibiogram(ex1, - antibiotics = aminoglycosides(), - ab_transform = "name", - syndromic_group = ifelse(ex1$ward == "ICU", - "UCI", "No UCI" - ), - language = "es" + antibiotics = aminoglycosides(), + ab_transform = "name", + syndromic_group = ifelse(ex1$ward == "ICU", + "UCI", "No UCI"), + language = "es" ) @@ -230,13 +229,13 @@ antibiogram(ex1, # the data set could contain a filter for e.g. respiratory specimens/ICU antibiogram(example_isolates, - antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), - mo_transform = "gramstain", - minimum = 10, # this should be >=30, but now just as example - syndromic_group = ifelse(example_isolates$age >= 65 & - example_isolates$gender == "M", - "WISCA Group 1", "WISCA Group 2" - ) + antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), + mo_transform = "gramstain", + minimum = 10, # this should be >=30, but now just as example + syndromic_group = ifelse(example_isolates$age >= 65 & + example_isolates$gender == "M", + "WISCA Group 1", "WISCA Group 2" + ) ) # Print the output for R Markdown / Quarto -----------------------------