diff --git a/DESCRIPTION b/DESCRIPTION index f2afc73d..cf12e989 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.8.2.9141 -Date: 2023-02-22 +Version: 1.8.2.9142 +Date: 2023-02-23 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NAMESPACE b/NAMESPACE index 361eeb3a..c83ae973 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -131,7 +131,6 @@ S3method(plot,resistance_predict) S3method(plot,rsi) S3method(plot,sir) S3method(print,ab) -S3method(print,antibiogram) S3method(print,av) S3method(print,bug_drug_combinations) S3method(print,custom_eucast_rules) diff --git a/NEWS.md b/NEWS.md index e341c871..2633fd16 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9141 +# AMR 1.8.2.9142 *(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 3090a844..82e4c699 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -45,7 +45,7 @@ #' @param sep a separating character for antibiotic columns in combination antibiograms #' @param info a [logical] to indicate info should be printed - the default is `TRUE` only in interactive mode #' @param object an [antibiogram()] object -#' @param ... when used in [print()]: arguments passed on to [knitr::kable()] (otherwise, has no use) +#' @param ... when used in [R Markdown or Quarto][knitr::kable()]: arguments passed on to [knitr::kable()] (otherwise, has no use) #' @details This function returns a table with values between 0 and 100 for *susceptibility*, not resistance. #' #' **Remember that you should filter your data to let it contain only first isolates!** This is needed to exclude duplicates and to reduce selection bias. Use [first_isolate()] to determine them in your data set with one of the four available algorithms. @@ -103,7 +103,7 @@ #' "Study Group", "Control Group")) #' ``` #' -#' All types of antibiograms can be generated with the functions as described on this page, and can be plotted (using [ggplot2::autoplot()] or base \R [plot()]/[barplot()]) or printed into R Markdown / Quarto formats for reports using `print()`. Use functions from specific 'table reporting' packages to transform the output of [antibiogram()] to your needs, e.g. `flextable::as_flextable()` or `gt::gt()`. +#' All types of antibiograms can be generated with the functions as described on this page, and can be plotted (using [ggplot2::autoplot()] or base \R [plot()]/[barplot()]) or directly used into R Markdown / Quarto formats for reports (in the last case, [knitr::kable()] will be applied automatically). Use functions from specific 'table reporting' packages to transform the output of [antibiogram()] to your needs, e.g. `flextable::as_flextable()` or `gt::gt()`. #' #' Note that for combination antibiograms, it is important to realise that susceptibility can be calculated in two ways, which can be set with the `only_all_tested` argument (default is `FALSE`). See this example for two antibiotics, Drug A and Drug B, about how [antibiogram()] works to calculate the %SI: #' @@ -215,8 +215,11 @@ #' antibiotics = ureidopenicillins(), #' ab_transform = "name") #' -#' # in an Rmd file, you would just need print(ureido), but to be explicit: -#' print(ureido, as_kable = TRUE, format = "markdown", italicise = TRUE) +#' # in an Rmd file, you would just need to return `ureido` in a chunk, +#' # but to be explicit here: +#' if (requireNamespace("knitr")) { +#' knitr::knit_print(ureido) +#' } #' #' #' # Generate plots with ggplot2 or base R -------------------------------- @@ -489,7 +492,7 @@ antibiogram <- function(x, } 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])), ")") + new_df[[edit_col]] <- paste0(new_df[[edit_col]], " (", unlist(lapply(strsplit(x = count_group, split = "-", fixed = TRUE), function(x) x[1])), ")") colnames(new_df)[edit_col] <- paste(colnames(new_df)[edit_col], "(N)") } else { # more than 1 antibiotic @@ -574,48 +577,40 @@ autoplot.antibiogram <- function(object, ...) { ) } -#' @export -#' @param as_kable a [logical] to indicate whether the printing should be done using [knitr::kable()] (which is the default in non-interactive sessions) -#' @param italicise (only when `as_kable = TRUE`) a [logical] to indicate whether the microorganism names in the output table should be made italic, using [italicise_taxonomy()]. This only works when the output format is markdown, such as in HTML output. -#' @param na (only when `as_kable = TRUE`) character to use for showing `NA` values -#' @details Printing the antibiogram in non-interactive sessions will be done by [knitr::kable()], with support for [all their implemented formats][knitr::kable()], such as "markdown". The knitr format will be automatically determined if printed inside a knitr document (LaTeX, HTML, etc.). +# will be exported in zzz.R +#' @param italicise a [logical] to indicate whether the microorganism names in the [knitr][knitr::kable()] table should be made italic, using [italicise_taxonomy()]. This only works when the output format is markdown, such as in HTML output. +#' @param na character to use for showing `NA` values #' @rdname antibiogram -print.antibiogram <- function(x, as_kable = !interactive(), italicise = TRUE, na = getOption("knitr.kable.NA", default = ""), ...) { - meet_criteria(as_kable, allow_class = "logical", has_length = 1) +knit_print.antibiogram <- function(x, italicise = TRUE, na = getOption("knitr.kable.NA", default = ""), ...) { + stop_ifnot_installed("knitr") meet_criteria(italicise, allow_class = "logical", has_length = 1) meet_criteria(na, allow_class = "character", has_length = 1, allow_NA = TRUE) - - if (isTRUE(as_kable) && - pkg_is_available("knitr") && - # be sure not to run kable in pkgdown for our website generation - !(missing(as_kable) && identical(Sys.getenv("IN_PKGDOWN"), "true"))) { - old_option <- getOption("knitr.kable.NA") - options(knitr.kable.NA = na) - on.exit(options(knitr.kable.NA = old_option)) - out <- knitr::kable(x, ...) - format <- attributes(out)$format - if (!is.null(format) && format %in% c("markdown", "pipe")) { - # try to italicise the output - rows_with_txt <- which(out %like% "[a-z]") - rows_without_txt <- setdiff(seq_len(length(out)), rows_with_txt) - out[rows_with_txt] <- gsub("^[|]", "| ", out[rows_with_txt]) - # put hyphen directly after second character - out[rows_without_txt] <- gsub("^[|](.)", "|\\1-", out[rows_without_txt]) - out_ita <- italicise_taxonomy(as.character(out), type = "markdown") - if (length(unique(nchar(out_ita))) != 1) { - # so there has been alterations done by italicise_taxonomy() - to_fill <- which(nchar(out_ita) < max(nchar(out_ita))) - out_ita[intersect(to_fill, rows_with_txt)] <- gsub("(^[|].*?)([|])(.*)", "\\1 \\2\\3", out_ita[intersect(to_fill, rows_with_txt)], perl = TRUE) - out_ita[intersect(to_fill, rows_without_txt)] <- gsub("(^[|].*?)([|])(.*)", "\\1--\\2\\3", out_ita[intersect(to_fill, rows_without_txt)], perl = TRUE) - } - attributes(out_ita) <- attributes(out) - out <- out_ita + + old_option <- getOption("knitr.kable.NA") + options(knitr.kable.NA = na) + on.exit(options(knitr.kable.NA = old_option)) + out <- knitr::kable(x, ..., output = FALSE) + + format <- attributes(out)$format + if (isTRUE(italicise) && + !is.null(format) && + format %in% c("markdown", "pipe")) { + # try to italicise the output + rows_with_txt <- which(out %like% "[a-z]") + rows_without_txt <- setdiff(seq_len(length(out)), rows_with_txt) + out[rows_with_txt] <- gsub("^[|]", "| ", out[rows_with_txt]) + # put hyphen directly after second character + out[rows_without_txt] <- gsub("^[|](.)", "|\\1-", out[rows_without_txt]) + out_ita <- italicise_taxonomy(as.character(out), type = "markdown") + if (length(unique(nchar(out_ita))) != 1) { + # so there has been alterations done by italicise_taxonomy() + to_fill <- which(nchar(out_ita) < max(nchar(out_ita))) + out_ita[intersect(to_fill, rows_with_txt)] <- gsub("(^[|].*?)([|])(.*)", "\\1 \\2\\3", out_ita[intersect(to_fill, rows_with_txt)], perl = TRUE) + out_ita[intersect(to_fill, rows_without_txt)] <- gsub("(^[|].*?)([|])(.*)", "\\1--\\2\\3", out_ita[intersect(to_fill, rows_without_txt)], perl = TRUE) } - out - - } else { - # remove 'antibiogram' class and print with default method - class(x) <- class(x)[class(x) != "antibiogram"] - print(x, ...) + attributes(out_ita) <- attributes(out) + out <- out_ita } + res <- paste(c("", "", out), collapse = "\n") + knitr::asis_output(res) } diff --git a/R/plot.R b/R/plot.R index 9da602ca..b369b011 100755 --- a/R/plot.R +++ b/R/plot.R @@ -146,18 +146,18 @@ plot.mic <- function(x, legend_txt <- character(0) legend_col <- character(0) if (any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) { - legend_txt <- "Susceptible" + legend_txt <- c(legend_txt, "(S) Susceptible") legend_col <- colours_SIR[1] } if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) { - legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) + legend_txt <- c(legend_txt, paste("(I)", plot_name_of_I(cols_sub$guideline))) legend_col <- c(legend_col, colours_SIR[2]) } if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) { - legend_txt <- c(legend_txt, "Resistant") + legend_txt <- c(legend_txt, "(R) Resistant") legend_col <- c(legend_col, colours_SIR[3]) } - + legend("top", x.intersp = 0.5, legend = translate_into_language(legend_txt, language = language), @@ -272,23 +272,25 @@ autoplot.mic <- function(object, df <- as.data.frame(x, stringsAsFactors = TRUE) colnames(df) <- c("mic", "count") df$cols <- cols_sub$cols - df$cols[df$cols == colours_SIR[1]] <- "Susceptible" - df$cols[df$cols == colours_SIR[2]] <- plot_name_of_I(cols_sub$guideline) - df$cols[df$cols == colours_SIR[3]] <- "Resistant" + df$cols[df$cols == colours_SIR[1]] <- "(S) Susceptible" + df$cols[df$cols == colours_SIR[2]] <- paste("(I)", plot_name_of_I(cols_sub$guideline)) + df$cols[df$cols == colours_SIR[3]] <- "(R) Resistant" df$cols <- factor(translate_into_language(df$cols, language = language), - levels = translate_into_language(c("Susceptible", plot_name_of_I(cols_sub$guideline), "Resistant"), - language = language - ), - ordered = TRUE + levels = translate_into_language(c("(S) Susceptible", + paste("(I)", plot_name_of_I(cols_sub$guideline)), + "(R) Resistant"), + language = language + ), + ordered = TRUE ) p <- ggplot2::ggplot(df) if (any(colours_SIR %in% cols_sub$cols)) { vals <- c( - "Susceptible" = colours_SIR[1], - "Susceptible, incr. exp." = colours_SIR[2], - "Intermediate" = colours_SIR[2], - "Resistant" = colours_SIR[3] + "(S) Susceptible" = colours_SIR[1], + "(I) Susceptible, incr. exp." = colours_SIR[2], + "(I) Intermediate" = colours_SIR[2], + "(R) Resistant" = colours_SIR[3] ) names(vals) <- translate_into_language(names(vals), language = language) p <- p + @@ -386,15 +388,15 @@ plot.disk <- function(x, legend_txt <- character(0) legend_col <- character(0) if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) { - legend_txt <- "Resistant" + legend_txt <- "(R) Resistant" legend_col <- colours_SIR[3] } if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) { - legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) + legend_txt <- c(legend_txt, paste("(I)", plot_name_of_I(cols_sub$guideline))) legend_col <- c(legend_col, colours_SIR[2]) } if (any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) { - legend_txt <- c(legend_txt, "Susceptible") + legend_txt <- c(legend_txt, "(S) Susceptible") legend_col <- c(legend_col, colours_SIR[1]) } legend("top", @@ -512,11 +514,13 @@ autoplot.disk <- function(object, colnames(df) <- c("disk", "count") df$cols <- cols_sub$cols - df$cols[df$cols == colours_SIR[1]] <- "Susceptible" - df$cols[df$cols == colours_SIR[2]] <- plot_name_of_I(cols_sub$guideline) - df$cols[df$cols == colours_SIR[3]] <- "Resistant" + df$cols[df$cols == colours_SIR[1]] <- "(S) Susceptible" + df$cols[df$cols == colours_SIR[2]] <- paste("(I)", plot_name_of_I(cols_sub$guideline)) + df$cols[df$cols == colours_SIR[3]] <- "(R) Resistant" df$cols <- factor(translate_into_language(df$cols, language = language), - levels = translate_into_language(c("Susceptible", plot_name_of_I(cols_sub$guideline), "Resistant"), + levels = translate_into_language(c("(S) Susceptible", + paste("(I)", plot_name_of_I(cols_sub$guideline)), + "(R) Resistant"), language = language ), ordered = TRUE @@ -525,10 +529,10 @@ autoplot.disk <- function(object, if (any(colours_SIR %in% cols_sub$cols)) { vals <- c( - "Susceptible" = colours_SIR[1], - "Susceptible, incr. exp." = colours_SIR[2], - "Intermediate" = colours_SIR[2], - "Resistant" = colours_SIR[3] + "(S) Susceptible" = colours_SIR[1], + "(I) Susceptible, incr. exp." = colours_SIR[2], + "(I) Intermediate" = colours_SIR[2], + "(R) Resistant" = colours_SIR[3] ) names(vals) <- translate_into_language(names(vals), language = language) p <- p + diff --git a/R/sysdata.rda b/R/sysdata.rda index 11333965..3033c228 100755 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/zzz.R b/R/zzz.R index 4685e3ab..ced87f1f 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -128,6 +128,8 @@ if (utf8_supported && !is_latex) { s3_register("ggplot2::fortify", "sir") s3_register("ggplot2::fortify", "mic") s3_register("ggplot2::fortify", "disk") + # Support for knitr / R Markdown + s3_register("knitr::knit_print", "antibiogram") # Support vctrs package for use in e.g. dplyr verbs # S3: ab_selector s3_register("vctrs::vec_ptype2", "character.ab_selector") diff --git a/data-raw/antibiograms.Rmd b/data-raw/antibiograms.Rmd index db02966b..8be57b1c 100644 --- a/data-raw/antibiograms.Rmd +++ b/data-raw/antibiograms.Rmd @@ -22,41 +22,33 @@ example_isolates ### Traditional Antibiogram ```{r trad} -print( - antibiogram(example_isolates, - antibiotics = c(aminoglycosides(), carbapenems())) -) +antibiogram(example_isolates, + antibiotics = c(aminoglycosides(), carbapenems())) ``` ### Combined Antibiogram ```{r comb} -print( - antibiogram(example_isolates, - antibiotics = c("TZP", "TZP+TOB", "TZP+GEN")) -) +antibiogram(example_isolates, + antibiotics = c("TZP", "TZP+TOB", "TZP+GEN")) ``` ### Syndromic Antibiogram ```{r synd} -print( - antibiogram(example_isolates, - antibiotics = c(aminoglycosides(), carbapenems()), - syndromic_group = "ward") -) +antibiogram(example_isolates, + antibiotics = c(aminoglycosides(), carbapenems()), + syndromic_group = "ward") ``` ### Weighted-Incidence Syndromic Combination Antibiogram (WISCA) ```{r wisca} -print( - 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")) -) +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")) ``` diff --git a/data-raw/antibiograms.html b/data-raw/antibiograms.html index f63a5e87..b53df843 100644 --- a/data-raw/antibiograms.html +++ b/data-raw/antibiograms.html @@ -11,7 +11,7 @@ - + Generating antibiograms with the AMR package @@ -299,18 +299,24 @@ overflow-y: auto; border: 1px solid #ddd; border-radius: 4px; } -.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before { -content: "\e259"; +.tabset-dropdown > .nav-tabs > li.active:before { +content: ""; font-family: 'Glyphicons Halflings'; display: inline-block; padding: 10px; border-right: 1px solid #ddd; } .tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before { -content: "\e258"; -font-family: 'Glyphicons Halflings'; +content: ""; border: none; } +.tabset-dropdown > .nav-tabs.nav-tabs-open:before { +content: ""; +font-family: 'Glyphicons Halflings'; +display: inline-block; +padding: 10px; +border-right: 1px solid #ddd; +} .tabset-dropdown > .nav-tabs > li.active { display: block; } @@ -353,7 +359,7 @@ display: none;

Generating antibiograms with the AMR package

AMR package developers

-

2023-02-18

+

2023-02-23

@@ -364,35 +370,34 @@ package looks like:

example_isolates
## # A tibble: 2,000 × 46
-##    date       patient   age gender ward     mo           PEN   OXA   FLC   AMX  
-##    <date>     <chr>   <dbl> <chr>  <chr>    <mo>         <sir> <sir> <sir> <sir>
-##  1 2002-01-02 A77334     65 F      Clinical B_ESCHR_COLI R     NA    NA    NA   
-##  2 2002-01-03 A77334     65 F      Clinical B_ESCHR_COLI R     NA    NA    NA   
-##  3 2002-01-07 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  4 2002-01-07 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  5 2002-01-13 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  6 2002-01-13 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  7 2002-01-14 462729     78 M      Clinical B_STPHY_AURS R     NA    S     R    
-##  8 2002-01-14 462729     78 M      Clinical B_STPHY_AURS R     NA    S     R    
-##  9 2002-01-16 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-## 10 2002-01-17 858515     79 F      ICU      B_STPHY_EPDR R     NA    S     NA   
-## # … with 1,990 more rows, and 36 more variables: AMC <sir>, AMP <sir>,
-## #   TZP <sir>, CZO <sir>, FEP <sir>, CXM <sir>, FOX <sir>, CTX <sir>,
-## #   CAZ <sir>, CRO <sir>, GEN <sir>, TOB <sir>, AMK <sir>, KAN <sir>,
-## #   TMP <sir>, SXT <sir>, NIT <sir>, FOS <sir>, LNZ <sir>, CIP <sir>,
-## #   MFX <sir>, VAN <sir>, TEC <sir>, TCY <sir>, TGC <sir>, DOX <sir>,
-## #   ERY <sir>, CLI <sir>, AZM <sir>, IPM <sir>, MEM <sir>, MTR <sir>,
-## #   CHL <sir>, COL <sir>, MUP <sir>, RIF <sir>
+## date patient age gender ward mo PEN +## <date> <chr> <dbl> <chr> <chr> <mo> <sir> +## 1 2002-01-02 A77334 65 F Clini… B_ESCHR_COLI R +## 2 2002-01-03 A77334 65 F Clini… B_ESCHR_COLI R +## 3 2002-01-07 067927 45 F ICU B_STPHY_EPDR R +## 4 2002-01-07 067927 45 F ICU B_STPHY_EPDR R +## 5 2002-01-13 067927 45 F ICU B_STPHY_EPDR R +## 6 2002-01-13 067927 45 F ICU B_STPHY_EPDR R +## 7 2002-01-14 462729 78 M Clini… B_STPHY_AURS R +## 8 2002-01-14 462729 78 M Clini… B_STPHY_AURS R +## 9 2002-01-16 067927 45 F ICU B_STPHY_EPDR R +## 10 2002-01-17 858515 79 F ICU B_STPHY_EPDR R +## # … with 1,990 more rows, and 39 more variables: OXA <sir>, +## # FLC <sir>, AMX <sir>, AMC <sir>, AMP <sir>, TZP <sir>, +## # CZO <sir>, FEP <sir>, CXM <sir>, FOX <sir>, CTX <sir>, +## # CAZ <sir>, CRO <sir>, GEN <sir>, TOB <sir>, AMK <sir>, +## # KAN <sir>, TMP <sir>, SXT <sir>, NIT <sir>, FOS <sir>, +## # LNZ <sir>, CIP <sir>, MFX <sir>, VAN <sir>, TEC <sir>, +## # TCY <sir>, TGC <sir>, DOX <sir>, ERY <sir>, … +## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names

Traditional Antibiogram

-
print(
-  antibiogram(example_isolates,
-              antibiotics = c(aminoglycosides(), carbapenems()))
-)
+
antibiogram(example_isolates,
+            antibiotics = c(aminoglycosides(), carbapenems()))
- + @@ -403,7 +408,7 @@ looks like:

- + @@ -416,7 +421,7 @@ looks like:

- + @@ -426,70 +431,70 @@ looks like:

- + - + - + - + - + - + - + - - + + - + - - - + + + - + - + - + - - - + + + - + - + @@ -497,14 +502,12 @@ looks like:

Combined Antibiogram

-
print(
-  antibiogram(example_isolates,
-              antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
-)
+
antibiogram(example_isolates,
+            antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
Pathogen (N min-max)Pathogeen (N min-max) AMK GEN IPM
CoNS (43-309)CNS (43-309) 0 86 52 100 98 100NA 100 97
0 100 0NA 0
K. pneumoniae (0-58)NA 90 100NA 100 90
P. aeruginosa (17-30)NA 100NA 0NA 100
P. mirabilis (0-34)NA 94 94NANA 94
S. aureus (2-233)NA 99NANANA 98
S. epidermidis (8-163) 0 79NA 0NA 51
S. hominis (3-80)NA 92NANANA 85
S. pneumoniae (11-117) 0 0NA 0NA 0
- + @@ -512,10 +515,10 @@ looks like:

- + - + @@ -531,31 +534,31 @@ looks like:

- + - + - + - + - + @@ -570,26 +573,14 @@ looks like:

Syndromic Antibiogram

-
print(
-  antibiogram(example_isolates,
-              antibiotics = c(aminoglycosides(), carbapenems()),
-              syndromic_group = "ward")
-)
+
antibiogram(example_isolates,
+             antibiotics = c(aminoglycosides(), carbapenems()),
+             syndromic_group = "ward")
Pathogen (N min-max)Pathogeen (N min-max) TZP TZP + GEN TZP + TOB
CoNS (29-274)CNS (29-274) 30 97NA
E. coli (416-461)
P. aeruginosa (27-30)NA 100 100
P. mirabilis (27-34)NA 100 100
S. aureus (7-231)NA 100 100
S. epidermidis (5-128)NA 100 100
S. hominis (0-74)NA 100 100
---------- - - + + @@ -601,33 +592,33 @@ looks like:

- - + + - + - - + + - - - - + + + + - - + + - - - - + + + + @@ -635,7 +626,7 @@ looks like:

- + @@ -645,78 +636,78 @@ looks like:

- + - + - + - + - - - + + + - + - - - + + + - + - - - - + + + + - + - - - + + + - + - - - + + + - + - - - + + + @@ -724,9 +715,9 @@ looks like:

- + - + @@ -734,9 +725,9 @@ looks like:

- + - + @@ -744,19 +735,17 @@ looks like:

Weighted-Incidence Syndromic Combination Antibiogram (WISCA)

-
print(
-  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"))
-)
-
Syndromic GroupPathogen (N min-max)SyndroomgroepPathogeen (N min-max) AMK GEN IPM
ClinicalCoNS (23-205)NACNS (23-205) 89 57NA 57 26
ICUCoNS (10-73)NACNS (10-73) 79NANANANA
OutpatientCoNS (3-31)NACNS (3-31) 84NANANANA
Clinical 100 98 100NA 100 98
100 99 100NA 100 96
Clinical K. pneumoniae (0-51)NA 92 100NA 100 92
Clinical P. mirabilis (0-30)NA 100NANANA 100
Clinical S. aureus (2-150)NA 99NANANA 97
ICU S. aureus (0-66)NA 100NANANANA
Clinical S. epidermidis (4-79)NA 82NANANA 55
ICU S. epidermidis (4-75)NA 72NANANA 41
Clinical S. hominis (1-45)NA 96NANANA 94
S. pneumoniae (5-78) 0 0NA 0NA 0
S. pneumoniae (5-30) 0 0NA 0NA 0
+
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"))
+
--++@@ -764,8 +753,8 @@ looks like:

- - + + @@ -775,7 +764,7 @@ looks like:

- + @@ -783,7 +772,7 @@ looks like:

- + @@ -791,7 +780,7 @@ looks like:

- + @@ -799,7 +788,7 @@ looks like:

- + diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd index a73d088b..cb7798d0 100644 --- a/man/antibiogram.Rd +++ b/man/antibiogram.Rd @@ -4,7 +4,7 @@ \alias{antibiogram} \alias{plot.antibiogram} \alias{autoplot.antibiogram} -\alias{print.antibiogram} +\alias{knit_print.antibiogram} \title{Generate Antibiogram: Traditional, Combined, Syndromic, or Weighted-Incidence Syndromic Combination (WISCA)} \source{ \itemize{ @@ -35,9 +35,8 @@ antibiogram( \method{autoplot}{antibiogram}(object, ...) -\method{print}{antibiogram}( +knit_print.antibiogram( x, - as_kable = !interactive(), italicise = TRUE, na = getOption("knitr.kable.NA", default = ""), ... @@ -72,15 +71,13 @@ antibiogram( \item{info}{a \link{logical} to indicate info should be printed - the default is \code{TRUE} only in interactive mode} -\item{...}{when used in \code{\link[=print]{print()}}: arguments passed on to \code{\link[knitr:kable]{knitr::kable()}} (otherwise, has no use)} +\item{...}{when used in \link[knitr:kable]{R Markdown or Quarto}: arguments passed on to \code{\link[knitr:kable]{knitr::kable()}} (otherwise, has no use)} \item{object}{an \code{\link[=antibiogram]{antibiogram()}} object} -\item{as_kable}{a \link{logical} to indicate whether the printing should be done using \code{\link[knitr:kable]{knitr::kable()}} (which is the default in non-interactive sessions)} +\item{italicise}{a \link{logical} to indicate whether the microorganism names in the \link[knitr:kable]{knitr} table should be made italic, using \code{\link[=italicise_taxonomy]{italicise_taxonomy()}}. This only works when the output format is markdown, such as in HTML output.} -\item{italicise}{(only when \code{as_kable = TRUE}) a \link{logical} to indicate whether the microorganism names in the output table should be made italic, using \code{\link[=italicise_taxonomy]{italicise_taxonomy()}}. This only works when the output format is markdown, such as in HTML output.} - -\item{na}{(only when \code{as_kable = TRUE}) character to use for showing \code{NA} values} +\item{na}{character to use for showing \code{NA} values} } \description{ Generate an antibiogram, and communicate the results in plots or tables. These functions follow the logic of Klinker \emph{et al.} and Barbieri \emph{et al.} (see \emph{Source}), and allow reporting in e.g. R Markdown and Quarto as well. @@ -137,7 +134,7 @@ your_data \%>\% }\if{html}{\out{}} } -All types of antibiograms can be generated with the functions as described on this page, and can be plotted (using \code{\link[ggplot2:autoplot]{ggplot2::autoplot()}} or base \R \code{\link[=plot]{plot()}}/\code{\link[=barplot]{barplot()}}) or printed into R Markdown / Quarto formats for reports using \code{print()}. Use functions from specific 'table reporting' packages to transform the output of \code{\link[=antibiogram]{antibiogram()}} to your needs, e.g. \code{flextable::as_flextable()} or \code{gt::gt()}. +All types of antibiograms can be generated with the functions as described on this page, and can be plotted (using \code{\link[ggplot2:autoplot]{ggplot2::autoplot()}} or base \R \code{\link[=plot]{plot()}}/\code{\link[=barplot]{barplot()}}) or directly used into R Markdown / Quarto formats for reports (in the last case, \code{\link[knitr:kable]{knitr::kable()}} will be applied automatically). Use functions from specific 'table reporting' packages to transform the output of \code{\link[=antibiogram]{antibiogram()}} to your needs, e.g. \code{flextable::as_flextable()} or \code{gt::gt()}. Note that for combination antibiograms, it is important to realise that susceptibility can be calculated in two ways, which can be set with the \code{only_all_tested} argument (default is \code{FALSE}). See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI: @@ -158,8 +155,6 @@ Note that for combination antibiograms, it is important to realise that suscepti - - - - -------------------------------------------------------------------- }\if{html}{\out{}} - -Printing the antibiogram in non-interactive sessions will be done by \code{\link[knitr:kable]{knitr::kable()}}, with support for \link[knitr:kable]{all their implemented formats}, such as "markdown". The knitr format will be automatically determined if printed inside a knitr document (LaTeX, HTML, etc.). } \examples{ # example_isolates is a data set available in the AMR package. @@ -244,8 +239,11 @@ ureido <- antibiogram(example_isolates, antibiotics = ureidopenicillins(), ab_transform = "name") -# in an Rmd file, you would just need print(ureido), but to be explicit: -print(ureido, as_kable = TRUE, format = "markdown", italicise = TRUE) +# in an Rmd file, you would just need to return `ureido` in a chunk, +# but to be explicit here: +if (requireNamespace("knitr")) { + knitr::knit_print(ureido) +} # Generate plots with ggplot2 or base R --------------------------------
Syndromic GroupPathogen (N min-max)SyndroomgroepPathogeen (N min-max) AMC AMC + CIP TZP
WISCA Group 1Gram-negative (261-285)Gram-negatief (261-285) 76 95 89
WISCA Group 2Gram-negative (380-442)Gram-negatief (380-442) 76 98 88
WISCA Group 1Gram-positive (123-406)Gram-positief (123-406) 76 89 81
WISCA Group 2Gram-positive (222-732)Gram-positief (222-732) 76 89 88