1
0
mirror of https://github.com/msberends/AMR.git synced 2025-01-15 07:21:38 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
ef716f6ee3 doc fix 2023-02-15 17:16:40 +01:00
d4ae174c28 docs 2023-02-15 17:03:34 +01:00
6016547f1f support for dplyr 1.1.0 2023-02-15 17:02:10 +01:00
11 changed files with 52 additions and 32 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 1.8.2.9126
Date: 2023-02-14
Version: 1.8.2.9129
Date: 2023-02-15
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

@ -1,4 +1,4 @@
# AMR 1.8.2.9126
# AMR 1.8.2.9129
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*

View File

@ -889,34 +889,36 @@ get_current_data <- function(arg_name, call) {
valid_df <- function(x) {
!is.null(x) && is.data.frame(x)
}
# try dplyr::cur_data_all() first to support dplyr groups
# only useful for e.g. dplyr::filter(), dplyr::mutate() and dplyr::summarise()
# not useful (throws error) with e.g. dplyr::select(), dplyr::across(), or dplyr::vars(),
# but that will be caught later on in this function
cur_data_all <- import_fn("cur_data_all", "dplyr", error_on_fail = FALSE)
if (!is.null(cur_data_all)) {
out <- tryCatch(cur_data_all(), error = function(e) NULL)
if (valid_df(out)) {
return(out)
}
}
# try a manual (base R) method, by going over all underlying environments with sys.frames()
for (env in sys.frames()) {
if (!is.null(env$`.Generic`)) {
# dplyr support ----
if (!is.null(env$mask) && is.function(env$mask$current_rows) && (valid_df(env$data) || valid_df(env$`.data`))) {
# an element `.data` or `data` (containing all data) and `mask` (containing functions) will be in the environment when using dplyr verbs
# we use their mask$current_rows() to get the group rows, since dplyr::cur_data_all() is deprecated and will be removed in the future
# e.g. for `example_isolates %>% group_by(ward) %>% mutate(first = first_isolate(.))`
if (valid_df(env$data)) {
# support for dplyr 1.1.x
return(env$data[env$mask$current_rows(), , drop = FALSE])
} else {
# support for dplyr 1.0.x
return(env$`.data`[env$mask$current_rows(), , drop = FALSE])
}
# base R support ----
} else if (!is.null(env$`.Generic`)) {
# don't check `".Generic" %in% names(env)`, because in R < 3.2, `names(env)` is always NULL
if (valid_df(env$`.data`)) {
# an element `.data` will be in the environment when using `dplyr::select()`
# (but not when using `dplyr::filter()`, `dplyr::mutate()` or `dplyr::summarise()`)
return(env$`.data`)
} else if (valid_df(env$xx)) {
# an element `xx` will be in the environment for rows + cols, e.g. `example_isolates[c(1:3), carbapenems()]`
if (valid_df(env$xx)) {
# an element `xx` will be in the environment for rows + cols in base R, e.g. `example_isolates[c(1:3), carbapenems()]`
return(env$xx)
} else if (valid_df(env$x)) {
# an element `x` will be in the environment for only cols, e.g. `example_isolates[, carbapenems()]`
# an element `x` will be in the environment for only cols in base R, e.g. `example_isolates[, carbapenems()]`
return(env$x)
}
# scoped dplyr support ----
} else if (!is.null(names(env)) && all(c(".tbl", ".vars", ".cols") %in% names(env), na.rm = TRUE) && valid_df(env$`.tbl`)) {
# an element `.tbl` will be in the environment when using scoped dplyr variants, with or without `dplyr::vars()`
# (e.g. `dplyr::summarise_at()` or `dplyr::mutate_at()`)

View File

@ -102,7 +102,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. 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 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()`.
#'
#' 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 (defaults to `FALSE`). See this example for two antibiotics, Drug A and Drug B, about how [antibiogram()] works to calculate the %SI:
#'

View File

@ -177,7 +177,7 @@ first_isolate <- function(x = NULL,
include_untested_sir = TRUE,
...) {
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# when `x` is left blank, auto determine it (get_current_data() searches underlying data within call)
# is also fix for using a grouped df as input (a dot as first argument)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}
@ -634,7 +634,7 @@ filter_first_isolate <- function(x = NULL,
method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"),
...) {
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# when `x` is left blank, auto determine it (get_current_data() searches underlying data within call)
# is also fix for using a grouped df as input (a dot as first argument)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}

View File

@ -138,7 +138,7 @@ key_antimicrobials <- function(x = NULL,
only_sir_columns = FALSE,
...) {
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# when `x` is left blank, auto determine it (get_current_data() searches underlying data within call)
# is also fix for using a grouped df as input (a dot as first argument)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}
@ -250,7 +250,7 @@ all_antimicrobials <- function(x = NULL,
only_sir_columns = FALSE,
...) {
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# when `x` is left blank, auto determine it (get_current_data() searches underlying data within call)
# is also fix for using a grouped df as input (a dot as first argument)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}

View File

@ -178,7 +178,7 @@ mdro <- function(x = NULL,
only_sir_columns = FALSE,
...) {
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# when `x` is left blank, auto determine it (get_current_data() searches underlying data within call)
# is also a fix for using a grouped df as input (i.e., a dot as first argument)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}

View File

@ -78,7 +78,7 @@ This base R snippet will work in any version of R since April 2013 (R-3.0).
The `AMR` package supports generating traditional, combined, syndromic, and even weighted-incidence syndromic combination antibiograms (WISCA).
If used inside R Markdown or Quarto, the table will be printed in the right output format automatically (such as markdown, LaTeX, HTML, etc.).
If used inside R Markdown or Quarto, the table will be printed in the right output format automatically (such as markdown, LaTeX, HTML, etc.) when using `print()` on an antibiogram object.
```r
antibiogram(example_isolates,
@ -111,6 +111,21 @@ antibiogram(example_isolates,
|Gram-negative (641-693) | 88| 99| 98|
|Gram-positive (345-1044) | 86| 98| 95|
Like many other functions in this package, `antibiograms()` comes with support for 20 languages that are often detected automatically based on system language:
```r
antibiogram(example_isolates,
antibiotics = c("CIP", "TOB", "GEN"),
mo_transform = "gramstain",
ab_transform = "name",
language = "uk") # Ukrainian
```
|Збудник (N min-max) | Гентаміцин| Тобраміцин| Ципрофлоксацин|
|:------------------------|----------:|----------:|--------------:|
|Грамнегативні (684-686) | 96| 96| 91|
|Грампозитивні (665-1170) | 63| 34| 77|
#### Calculating resistance per group

View File

@ -124,7 +124,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. 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 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()}.
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 (defaults to \code{FALSE}). See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI:

View File

@ -54,10 +54,13 @@ mark, .mark {
background: rgba(17, 143, 118, 0.25) !important;
}
/* smaller tables */
.table {
font-size: 0.9em !important;
}
/* SYNTAX */
/* These are simple changes for the syntax highlighting */
pre {
font-size: 0.8em !important;
}

View File

@ -52,7 +52,7 @@ $(document).ready(function() {
// add doctoral titles to authors
function doct_tit(x) {
if (typeof(x) != "undefined") {
x = x.replace(/Author, maintainer/g, "Principle developer");
x = x.replace(/Author, maintainer/g, "Principle maintainer");
x = x.replace(/Author, contributor/g, "Contributing maintainer");
x = x.replace(/Thesis advisor/g, "(former) Doctoral advisor");
// contributors