knitr format

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-02-23 16:27:40 +01:00
parent a84101db08
commit e70f2cd32c
10 changed files with 236 additions and 257 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

View File

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

View File

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

View File

@ -11,7 +11,7 @@
<meta name="author" content="AMR package developers" />
<meta name="date" content="2023-02-18" />
<meta name="date" content="2023-02-23" />
<title>Generating antibiograms with the AMR package</title>
@ -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;
<h1 class="title toc-ignore">Generating antibiograms with the AMR
package</h1>
<h4 class="author">AMR package developers</h4>
<h4 class="date">2023-02-18</h4>
<h4 class="date">2023-02-23</h4>
</div>
@ -364,35 +370,34 @@ package</h1>
looks like:</p>
<pre class="r"><code>example_isolates</code></pre>
<pre><code>## # A tibble: 2,000 × 46
## date patient age gender ward mo PEN OXA FLC AMX
## &lt;date&gt; &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;mo&gt; &lt;sir&gt; &lt;sir&gt; &lt;sir&gt; &lt;sir&gt;
## 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 &lt;sir&gt;, AMP &lt;sir&gt;,
## # TZP &lt;sir&gt;, CZO &lt;sir&gt;, FEP &lt;sir&gt;, CXM &lt;sir&gt;, FOX &lt;sir&gt;, CTX &lt;sir&gt;,
## # CAZ &lt;sir&gt;, CRO &lt;sir&gt;, GEN &lt;sir&gt;, TOB &lt;sir&gt;, AMK &lt;sir&gt;, KAN &lt;sir&gt;,
## # TMP &lt;sir&gt;, SXT &lt;sir&gt;, NIT &lt;sir&gt;, FOS &lt;sir&gt;, LNZ &lt;sir&gt;, CIP &lt;sir&gt;,
## # MFX &lt;sir&gt;, VAN &lt;sir&gt;, TEC &lt;sir&gt;, TCY &lt;sir&gt;, TGC &lt;sir&gt;, DOX &lt;sir&gt;,
## # ERY &lt;sir&gt;, CLI &lt;sir&gt;, AZM &lt;sir&gt;, IPM &lt;sir&gt;, MEM &lt;sir&gt;, MTR &lt;sir&gt;,
## # CHL &lt;sir&gt;, COL &lt;sir&gt;, MUP &lt;sir&gt;, RIF &lt;sir&gt;</code></pre>
## date patient age gender ward mo PEN
## &lt;date&gt; &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt; &lt;mo&gt; &lt;sir&gt;
## 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 &lt;sir&gt;,
## # FLC &lt;sir&gt;, AMX &lt;sir&gt;, AMC &lt;sir&gt;, AMP &lt;sir&gt;, TZP &lt;sir&gt;,
## # CZO &lt;sir&gt;, FEP &lt;sir&gt;, CXM &lt;sir&gt;, FOX &lt;sir&gt;, CTX &lt;sir&gt;,
## # CAZ &lt;sir&gt;, CRO &lt;sir&gt;, GEN &lt;sir&gt;, TOB &lt;sir&gt;, AMK &lt;sir&gt;,
## # KAN &lt;sir&gt;, TMP &lt;sir&gt;, SXT &lt;sir&gt;, NIT &lt;sir&gt;, FOS &lt;sir&gt;,
## # LNZ &lt;sir&gt;, CIP &lt;sir&gt;, MFX &lt;sir&gt;, VAN &lt;sir&gt;, TEC &lt;sir&gt;,
## # TCY &lt;sir&gt;, TGC &lt;sir&gt;, DOX &lt;sir&gt;, ERY &lt;sir&gt;, …
## # Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names</code></pre>
<div id="traditional-antibiogram" class="section level3">
<h3>Traditional Antibiogram</h3>
<pre class="r"><code>print(
antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()))
)</code></pre>
<pre class="r"><code>antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()))</code></pre>
<table>
<thead>
<tr class="header">
<th align="left">Pathogen (N min-max)</th>
<th align="left">Pathogeen (N min-max)</th>
<th align="right">AMK</th>
<th align="right">GEN</th>
<th align="right">IPM</th>
@ -403,7 +408,7 @@ looks like:</p>
</thead>
<tbody>
<tr class="odd">
<td align="left">CoNS (43-309)</td>
<td align="left">CNS (43-309)</td>
<td align="right">0</td>
<td align="right">86</td>
<td align="right">52</td>
@ -416,7 +421,7 @@ looks like:</p>
<td align="right">100</td>
<td align="right">98</td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">97</td>
</tr>
@ -426,70 +431,70 @@ looks like:</p>
<td align="right">0</td>
<td align="right">100</td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
</tr>
<tr class="even">
<td align="left"><em>K. pneumoniae</em> (0-58)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">90</td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">90</td>
</tr>
<tr class="odd">
<td align="left"><em>P. aeruginosa</em> (17-30)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
</tr>
<tr class="even">
<td align="left"><em>P. mirabilis</em> (0-34)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">94</td>
<td align="right">94</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right">94</td>
</tr>
<tr class="odd">
<td align="left"><em>S. aureus</em> (2-233)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">99</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">98</td>
</tr>
<tr class="even">
<td align="left"><em>S. epidermidis</em> (8-163)</td>
<td align="right">0</td>
<td align="right">79</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">51</td>
</tr>
<tr class="odd">
<td align="left"><em>S. hominis</em> (3-80)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">92</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">85</td>
</tr>
<tr class="even">
<td align="left"><em>S. pneumoniae</em> (11-117)</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
</tr>
</tbody>
@ -497,14 +502,12 @@ looks like:</p>
</div>
<div id="combined-antibiogram" class="section level3">
<h3>Combined Antibiogram</h3>
<pre class="r"><code>print(
antibiogram(example_isolates,
antibiotics = c(&quot;TZP&quot;, &quot;TZP+TOB&quot;, &quot;TZP+GEN&quot;))
)</code></pre>
<pre class="r"><code>antibiogram(example_isolates,
antibiotics = c(&quot;TZP&quot;, &quot;TZP+TOB&quot;, &quot;TZP+GEN&quot;))</code></pre>
<table>
<thead>
<tr class="header">
<th align="left">Pathogen (N min-max)</th>
<th align="left">Pathogeen (N min-max)</th>
<th align="right">TZP</th>
<th align="right">TZP + GEN</th>
<th align="right">TZP + TOB</th>
@ -512,10 +515,10 @@ looks like:</p>
</thead>
<tbody>
<tr class="odd">
<td align="left">CoNS (29-274)</td>
<td align="left">CNS (29-274)</td>
<td align="right">30</td>
<td align="right">97</td>
<td align="right">NA</td>
<td align="right"></td>
</tr>
<tr class="even">
<td align="left"><em>E. coli</em> (416-461)</td>
@ -531,31 +534,31 @@ looks like:</p>
</tr>
<tr class="even">
<td align="left"><em>P. aeruginosa</em> (27-30)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">100</td>
</tr>
<tr class="odd">
<td align="left"><em>P. mirabilis</em> (27-34)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">100</td>
</tr>
<tr class="even">
<td align="left"><em>S. aureus</em> (7-231)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">100</td>
</tr>
<tr class="odd">
<td align="left"><em>S. epidermidis</em> (5-128)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">100</td>
</tr>
<tr class="even">
<td align="left"><em>S. hominis</em> (0-74)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">100</td>
</tr>
@ -570,26 +573,14 @@ looks like:</p>
</div>
<div id="syndromic-antibiogram" class="section level3">
<h3>Syndromic Antibiogram</h3>
<pre class="r"><code>print(
antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()),
syndromic_group = &quot;ward&quot;)
)</code></pre>
<pre class="r"><code>antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()),
syndromic_group = &quot;ward&quot;)</code></pre>
<table>
<colgroup>
<col width="29%" />
<col width="33%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
<col width="6%" />
</colgroup>
<thead>
<tr class="header">
<th align="left">Syndromic Group</th>
<th align="left">Pathogen (N min-max)</th>
<th align="left">Syndroomgroep</th>
<th align="left">Pathogeen (N min-max)</th>
<th align="right">AMK</th>
<th align="right">GEN</th>
<th align="right">IPM</th>
@ -601,33 +592,33 @@ looks like:</p>
<tbody>
<tr class="odd">
<td align="left">Clinical</td>
<td align="left">CoNS (23-205)</td>
<td align="right">NA</td>
<td align="left">CNS (23-205)</td>
<td align="right"></td>
<td align="right">89</td>
<td align="right">57</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">57</td>
<td align="right">26</td>
</tr>
<tr class="even">
<td align="left">ICU</td>
<td align="left">CoNS (10-73)</td>
<td align="right">NA</td>
<td align="left">CNS (10-73)</td>
<td align="right"></td>
<td align="right">79</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
</tr>
<tr class="odd">
<td align="left">Outpatient</td>
<td align="left">CoNS (3-31)</td>
<td align="right">NA</td>
<td align="left">CNS (3-31)</td>
<td align="right"></td>
<td align="right">84</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
</tr>
<tr class="even">
<td align="left">Clinical</td>
@ -635,7 +626,7 @@ looks like:</p>
<td align="right">100</td>
<td align="right">98</td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">98</td>
</tr>
@ -645,78 +636,78 @@ looks like:</p>
<td align="right">100</td>
<td align="right">99</td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">96</td>
</tr>
<tr class="even">
<td align="left">Clinical</td>
<td align="left">K. <em>pneumoniae</em> (0-51)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">92</td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">92</td>
</tr>
<tr class="odd">
<td align="left">Clinical</td>
<td align="left">P. <em>mirabilis</em> (0-30)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">100</td>
</tr>
<tr class="even">
<td align="left">Clinical</td>
<td align="left">S. <em>aureus</em> (2-150)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">99</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">97</td>
</tr>
<tr class="odd">
<td align="left">ICU</td>
<td align="left">S. <em>aureus</em> (0-66)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">100</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
</tr>
<tr class="even">
<td align="left">Clinical</td>
<td align="left">S. <em>epidermidis</em> (4-79)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">82</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">55</td>
</tr>
<tr class="odd">
<td align="left">ICU</td>
<td align="left">S. <em>epidermidis</em> (4-75)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">72</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">41</td>
</tr>
<tr class="even">
<td align="left">Clinical</td>
<td align="left">S. <em>hominis</em> (1-45)</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">96</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right"></td>
<td align="right"></td>
<td align="right">94</td>
</tr>
<tr class="odd">
@ -724,9 +715,9 @@ looks like:</p>
<td align="left">S. <em>pneumoniae</em> (5-78)</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
</tr>
<tr class="even">
@ -734,9 +725,9 @@ looks like:</p>
<td align="left">S. <em>pneumoniae</em> (5-30)</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
<td align="right">NA</td>
<td align="right"></td>
<td align="right">0</td>
</tr>
</tbody>
@ -744,19 +735,17 @@ looks like:</p>
</div>
<div id="weighted-incidence-syndromic-combination-antibiogram-wisca" class="section level3">
<h3>Weighted-Incidence Syndromic Combination Antibiogram (WISCA)</h3>
<pre class="r"><code>print(
antibiogram(example_isolates,
antibiotics = c(&quot;AMC&quot;, &quot;AMC+CIP&quot;, &quot;TZP&quot;, &quot;TZP+TOB&quot;),
mo_transform = &quot;gramstain&quot;,
minimum = 10, # this should be &gt;= 30, but now just as example
syndromic_group = ifelse(example_isolates$age &gt;= 65 &amp;
example_isolates$gender == &quot;M&quot;,
&quot;WISCA Group 1&quot;, &quot;WISCA Group 2&quot;))
)</code></pre>
<table>
<pre class="r"><code>antibiogram(example_isolates,
antibiotics = c(&quot;AMC&quot;, &quot;AMC+CIP&quot;, &quot;TZP&quot;, &quot;TZP+TOB&quot;),
mo_transform = &quot;gramstain&quot;,
minimum = 10, # this should be &gt;= 30, but now just as example
syndromic_group = ifelse(example_isolates$age &gt;= 65 &amp;
example_isolates$gender == &quot;M&quot;,
&quot;WISCA Group 1&quot;, &quot;WISCA Group 2&quot;))</code></pre>
<table style="width:100%;">
<colgroup>
<col width="24%" />
<col width="34%" />
<col width="22%" />
<col width="35%" />
<col width="5%" />
<col width="14%" />
<col width="5%" />
@ -764,8 +753,8 @@ looks like:</p>
</colgroup>
<thead>
<tr class="header">
<th align="left">Syndromic Group</th>
<th align="left">Pathogen (N min-max)</th>
<th align="left">Syndroomgroep</th>
<th align="left">Pathogeen (N min-max)</th>
<th align="right">AMC</th>
<th align="right">AMC + CIP</th>
<th align="right">TZP</th>
@ -775,7 +764,7 @@ looks like:</p>
<tbody>
<tr class="odd">
<td align="left">WISCA Group 1</td>
<td align="left">Gram-negative (261-285)</td>
<td align="left">Gram-negatief (261-285)</td>
<td align="right">76</td>
<td align="right">95</td>
<td align="right">89</td>
@ -783,7 +772,7 @@ looks like:</p>
</tr>
<tr class="even">
<td align="left">WISCA Group 2</td>
<td align="left">Gram-negative (380-442)</td>
<td align="left">Gram-negatief (380-442)</td>
<td align="right">76</td>
<td align="right">98</td>
<td align="right">88</td>
@ -791,7 +780,7 @@ looks like:</p>
</tr>
<tr class="odd">
<td align="left">WISCA Group 1</td>
<td align="left">Gram-positive (123-406)</td>
<td align="left">Gram-positief (123-406)</td>
<td align="right">76</td>
<td align="right">89</td>
<td align="right">81</td>
@ -799,7 +788,7 @@ looks like:</p>
</tr>
<tr class="even">
<td align="left">WISCA Group 2</td>
<td align="left">Gram-positive (222-732)</td>
<td align="left">Gram-positief (222-732)</td>
<td align="right">76</td>
<td align="right">89</td>
<td align="right">88</td>

View File

@ -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{</div>}}
}
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
<NA> <NA> - - - -
--------------------------------------------------------------------
}\if{html}{\out{</div>}}
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 --------------------------------