1
0
mirror of https://github.com/msberends/AMR.git synced 2025-01-23 21:44:35 +01:00

(v2.1.1.9125) replace 'antibiotic selectors' with 'antimicrobial selectors'

This commit is contained in:
dr. M.S. (Matthijs) Berends 2025-01-17 12:09:39 +01:00
parent 1697ad37ce
commit 92c4fc0f94
No known key found for this signature in database
33 changed files with 1029 additions and 807 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 2.1.1.9123
Date: 2025-01-15
Version: 2.1.1.9125
Date: 2025-01-17
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,8 +1,8 @@
# Generated by roxygen2: do not edit by hand
S3method("!=",ab_selector)
S3method("&",ab_selector)
S3method("==",ab_selector)
S3method("!=",amr_selector)
S3method("&",amr_selector)
S3method("==",amr_selector)
S3method("[",ab)
S3method("[",av)
S3method("[",disk)
@ -25,15 +25,15 @@ S3method("[[<-",disk)
S3method("[[<-",mic)
S3method("[[<-",mo)
S3method("[[<-",sir)
S3method("|",ab_selector)
S3method("|",amr_selector)
S3method(Complex,mic)
S3method(Math,mic)
S3method(Ops,mic)
S3method(Summary,mic)
S3method(all,ab_selector)
S3method(all,ab_selector_any_all)
S3method(any,ab_selector)
S3method(any,ab_selector_any_all)
S3method(all,amr_selector)
S3method(all,amr_selector_any_all)
S3method(any,amr_selector)
S3method(any,amr_selector_any_all)
S3method(as.data.frame,ab)
S3method(as.data.frame,av)
S3method(as.data.frame,mic)
@ -55,7 +55,7 @@ S3method(barplot,disk)
S3method(barplot,mic)
S3method(barplot,sir)
S3method(c,ab)
S3method(c,ab_selector)
S3method(c,amr_selector)
S3method(c,av)
S3method(c,custom_eucast_rules)
S3method(c,custom_mdro_guideline)
@ -84,7 +84,7 @@ S3method(plot,mic)
S3method(plot,resistance_predict)
S3method(plot,sir)
S3method(print,ab)
S3method(print,ab_selector)
S3method(print,amr_selector)
S3method(print,av)
S3method(print,bug_drug_combinations)
S3method(print,custom_eucast_rules)
@ -151,7 +151,9 @@ export(age_groups)
export(all_antimicrobials)
export(aminoglycosides)
export(aminopenicillins)
export(amr_class)
export(amr_distance_from_row)
export(amr_selector)
export(anti_join_microorganisms)
export(antibiogram)
export(antifungals)

16
NEWS.md
View File

@ -1,4 +1,4 @@
# AMR 2.1.1.9123
# AMR 2.1.1.9125
*(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)*
@ -31,7 +31,7 @@ This package now supports not only tools for AMR data analysis in clinical setti
* **Support for Python**
* While using R for the heavy lifting, [our 'AMR' Python Package](https://pypi.org/project/AMR/) was developed to run the AMR R package natively in Python. The Python package will always have the same version number as the R package, as it is built automatically with every code change.
* **Support for `tidymodels`**
* All antimicrobial selectors (such as `aminoglycosides()` and `betalactams()`) are now supported in `tidymodels` packages such as `recipe` and `parsnip`. See for more info [our tutorial](https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html) on using AMR function for predictive modelling.
* All antimicrobial selectors (such as `aminoglycosides()` and `betalactams()`) are now supported in `tidymodels` packages such as `recipe` and `parsnip`. See for more info [our tutorial](https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html) on using these AMR functions for predictive modelling.
* **Other**
* New function `mo_group_members()` to retrieve the member microorganisms of a microorganism group. For example, `mo_group_members("Strep group C")` returns a vector of all microorganisms that belong to that group.
@ -44,14 +44,16 @@ This package now supports not only tools for AMR data analysis in clinical setti
* New argument `formatting_type` to set any of the 12 options for the formatting of all 'cells'. This defaults to `10`, changing the output of antibiograms to cells with `5% (15/300)` instead of the previous standard of just `5`.
* For this reason, `add_total_n` is now `FALSE` at default since the denominators are added to the cells
* The `ab_transform` argument now defaults to `"name"`, displaying antibiotic column names instead of codes
* Antimicrobial selectors (previously: *antibiotic selectors*)
* 'Antibiotic selectors' are now called 'antimicrobial selectors' since their scope is broader than just antibiotics. All documentation have been updated, and `ab_class()` and `ab_selector()` have been replaced with `amr_class()` and `amr_selector()`. The old functions are now deprecated and will be removed in a future version.
* Added selectors `nitrofurans()`, `phenicols()`, and `rifamycins()`
* When using antimicrobial selectors (such as `aminoglycosides()`) that exclude non-treatable drugs (such as gentamicin-high), the function now always returns a warning that these can be included using `only_treatable = FALSE`
* Added a new argument `return_all` to all selectors, which defaults to `TRUE` to include any match. With `FALSE`, the old behaviour, only the first hit for each unique antimicrobial is returned.
* All selectors can now be run as a separate command to retrieve a vector of all possible antimicrobials that the selector can select
* `antibiotics` data set
* Added "clindamycin inducible screening" as `CLI1`. Since clindamycin is a lincosamide, the antibiotic selector `lincosamides()` now contains the argument `only_treatable = TRUE` (similar to other antibiotic selectors that contain non-treatable drugs)
* Added "clindamycin inducible screening" as `CLI1`. Since clindamycin is a lincosamide, the antimicrobial selector `lincosamides()` now contains the argument `only_treatable = TRUE` (similar to other antibiotic selectors that contain non-treatable drugs)
* Added Amorolfine (`AMO`, D01AE16), which is now also part of the `antifungals()` selector
* Added Efflux (`EFF`), to allow mapping to AMRFinderPlus
* Antibiotic selectors
* Added selectors `nitrofurans()`, `phenicols()`, and `rifamycins()`
* When using antibiotic selectors (such as `aminoglycosides()`) that exclude non-treatable drugs (such as gentamicin-high), the function now always returns a warning that these can be included using `only_treatable = FALSE`
* All selectors can now be run as a separate command to retrieve a vector of all possible antimicrobials that the selector can select
* MICs
* Added as valid levels: 4096, 6 powers of 0.0625, and 5 powers of 192 (192, 384, 576, 768, 960)
* Added new argument `keep_operators` to `as.mic()`. This can be `"all"` (default), `"none"`, or `"edges"`. This argument is also available in the new `rescale_mic()` and `scale_*_mic()` functions.

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.2
Name: AMR
Version: 2.1.1.9123
Version: 2.1.1.9125
Summary: A Python wrapper for the AMR R package
Home-page: https://github.com/msberends/AMR
Author: Matthijs Berends

View File

@ -2,6 +2,8 @@ from .datasets import example_isolates
from .datasets import microorganisms
from .datasets import antibiotics
from .datasets import clinical_breakpoints
from .functions import ab_class
from .functions import ab_selector
from .functions import ab_from_text
from .functions import ab_name
from .functions import ab_cid
@ -24,8 +26,8 @@ from .functions import clear_custom_microorganisms
from .functions import age
from .functions import age_groups
from .functions import antibiogram
from .functions import ab_class
from .functions import ab_selector
from .functions import amr_class
from .functions import amr_selector
from .functions import aminoglycosides
from .functions import aminopenicillins
from .functions import antifungals

View File

@ -36,6 +36,12 @@ def convert_to_python(r_output):
# Fall-back
return r_output
def ab_class(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_class(*args, **kwargs))
def ab_selector(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_selector(*args, **kwargs))
def ab_from_text(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_from_text(*args, **kwargs))
@ -102,15 +108,15 @@ def age_groups(x, *args, **kwargs):
def antibiogram(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.antibiogram(*args, **kwargs))
def ab_class(ab_class, *args, **kwargs):
def amr_class(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_class(ab_class, *args, **kwargs))
def ab_selector(filter, *args, **kwargs):
return convert_to_python(amr_r.amr_class(*args, **kwargs))
def amr_selector(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_selector(filter, *args, **kwargs))
def aminoglycosides(only_sir_columns = False, *args, **kwargs):
return convert_to_python(amr_r.amr_selector(*args, **kwargs))
def aminoglycosides(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.aminoglycosides(only_sir_columns = False, *args, **kwargs))
return convert_to_python(amr_r.aminoglycosides(*args, **kwargs))
def aminopenicillins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.aminopenicillins(only_sir_columns = False, *args, **kwargs))
@ -120,15 +126,15 @@ def antifungals(only_sir_columns = False, *args, **kwargs):
def antimycobacterials(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.antimycobacterials(only_sir_columns = False, *args, **kwargs))
def betalactams(only_sir_columns = False, *args, **kwargs):
def betalactams(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.betalactams(only_sir_columns = False, *args, **kwargs))
return convert_to_python(amr_r.betalactams(*args, **kwargs))
def betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs))
def carbapenems(only_sir_columns = False, *args, **kwargs):
def carbapenems(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.carbapenems(only_sir_columns = False, *args, **kwargs))
return convert_to_python(amr_r.carbapenems(*args, **kwargs))
def cephalosporins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.cephalosporins(only_sir_columns = False, *args, **kwargs))
@ -153,9 +159,9 @@ def fluoroquinolones(only_sir_columns = False, *args, **kwargs):
def glycopeptides(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.glycopeptides(only_sir_columns = False, *args, **kwargs))
def lincosamides(only_sir_columns = False, *args, **kwargs):
def lincosamides(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.lincosamides(only_sir_columns = False, *args, **kwargs))
return convert_to_python(amr_r.lincosamides(*args, **kwargs))
def lipoglycopeptides(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.lipoglycopeptides(only_sir_columns = False, *args, **kwargs))
@ -174,9 +180,9 @@ def penicillins(only_sir_columns = False, *args, **kwargs):
def phenicols(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.phenicols(only_sir_columns = False, *args, **kwargs))
def polymyxins(only_sir_columns = False, *args, **kwargs):
def polymyxins(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.polymyxins(only_sir_columns = False, *args, **kwargs))
return convert_to_python(amr_r.polymyxins(*args, **kwargs))
def quinolones(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.quinolones(only_sir_columns = False, *args, **kwargs))

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='AMR',
version='2.1.1.9123',
version='2.1.1.9125',
packages=find_packages(),
install_requires=[
'rpy2',

View File

@ -27,28 +27,37 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#' Antibiotic Selectors
#' Antimicrobial Selectors
#'
#' @description These functions allow for filtering rows and selecting columns based on antibiotic test results that are of a specific antibiotic class or group (according to the [antibiotics] data set), without the need to define the columns or antibiotic abbreviations.
#' @description These functions allow for filtering rows and selecting columns based on antimicrobial test results that are of a specific antimicrobial class or group, without the need to define the columns or antimicrobial abbreviations.
#'
#' In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up by [cephalosporins()].
#' @param ab_class an antimicrobial class or a part of it, such as `"carba"` and `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value.
#' In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up using:
#'
#' ```r
#' library(dplyr)
#' my_data_with_all_these_columns %>%
#' select(cephalosporins())
#' ```
#' @param amr_class an antimicrobial class or a part of it, such as `"carba"` and `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value.
#' @param filter an [expression] to be evaluated in the [antibiotics] data set, such as `name %like% "trim"`
#' @param only_sir_columns a [logical] to indicate whether only columns of class `sir` must be selected (default is `FALSE`), see [as.sir()]
#' @param only_treatable a [logical] to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (default is `TRUE`), such as gentamicin-high (`GEH`) and imipenem/EDTA (`IPE`)
#' @param return_all a [logical] to indicate whether all matched columns must be returned (default is `TRUE`). With `FALSE`, only the first of each unique antimicrobial will be returned, e.g. if both columns `"genta"` and `"gentamicin"` exist in the data, only the first hit for gentamicin will be returned.
#' @param ... ignored, only in place to allow future extensions
#' @details
#' These functions can be used in data set calls for selecting columns and filtering rows. They work with base \R, the Tidyverse, and `data.table`. They are heavily inspired by the [Tidyverse selection helpers][tidyselect::language] such as [`everything()`][tidyselect::everything()], but are not limited to `dplyr` verbs. Nonetheless, they are very convenient to use with `dplyr` functions such as [`select()`][dplyr::select()], [`filter()`][dplyr::filter()] and [`summarise()`][dplyr::summarise()], see *Examples*.
#'
#' All selectors can also be used in `tidymodels` packages such as `recipe` and `parsnip`. See for more info [our tutorial](https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html) on using these AMR functions for predictive modelling.
#'
#' All columns in the data in which these functions are called will be searched for known antibiotic names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the [antibiotics] data set. This means that a selector such as [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
#' All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the [antibiotics] data set. This means that a selector such as [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
#'
#' The [ab_class()] function can be used to filter/select on a manually defined antibiotic class. It searches for results in the [antibiotics] data set within the columns `group`, `atc_group1` and `atc_group2`.
#' @section Full list of supported (antibiotic) classes:
#' The [amr_class()] function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the [antibiotics] data set within the columns `group`, `atc_group1` and `atc_group2`.
#' @section Full list of supported (antimicrobial) classes:
#'
#' `r paste0(" * ", na.omit(sapply(DEFINED_AB_GROUPS, function(ab) ifelse(tolower(gsub("^AB_", "", ab)) %in% ls(envir = asNamespace("AMR")), paste0("[", tolower(gsub("^AB_", "", ab)), "()] can select: \\cr ", vector_and(paste0(ab_name(eval(parse(text = ab), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), " (", eval(parse(text = ab), envir = asNamespace("AMR")), ")"), quotes = FALSE, sort = TRUE)), character(0)), USE.NAMES = FALSE)), "\n", collapse = "")`
#' @rdname antibiotic_class_selectors
#' @name antibiotic_class_selectors
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"ab_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobials that the function would be able to select or filter.
#' @rdname antimicrobial_class_selectors
#' @name antimicrobial_class_selectors
#' @return When used inside selecting or filtering, this returns a [character] vector of column names, with additional class `"amr_selector"`. When used individually, this returns an ['ab' vector][as.ab()] with all possible antimicrobials that the function would be able to select or filter.
#' @export
#' @inheritSection AMR Reference Data Publicly Available
#' @examples
@ -79,7 +88,7 @@
#' # e.g., for betalactams, but not the ones with an enzyme inhibitor:
#' example_isolates %>% select(betalactams(), -betalactams_with_inhibitor())
#'
#' # select only antibiotic columns with DDDs for oral treatment
#' # select only antimicrobials with DDDs for oral treatment
#' example_isolates %>% select(administrable_per_os())
#'
#' # get AMR for all aminoglycosides e.g., per ward:
@ -99,11 +108,11 @@
#' summarise_at(not_intrinsic_resistant(),
#' resistance)
#'
#' # get susceptibility for antibiotics whose name contains "trim":
#' # get susceptibility for antimicrobials whose name contains "trim":
#' example_isolates %>%
#' filter(first_isolate()) %>%
#' group_by(ward) %>%
#' summarise(across(ab_selector(name %like% "trim"), susceptibility))
#' summarise(across(amr_selector(name %like% "trim"), susceptibility))
#'
#' # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
#' example_isolates %>%
@ -130,7 +139,7 @@
#'
#' # this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
#' example_isolates %>%
#' select(mo, ab_class("mycobact"))
#' select(mo, amr_class("mycobact"))
#'
#' # get bug/drug combinations for only glycopeptides in Gram-positives:
#' example_isolates %>%
@ -160,7 +169,7 @@
#' # select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
#' example_isolates[, c("mo", aminoglycosides())]
#'
#' # select only antibiotic columns with DDDs for oral treatment
#' # select only antimicrobials with DDDs for oral treatment
#' example_isolates[, administrable_per_os()]
#'
#' # filter using any() or all()
@ -171,7 +180,7 @@
#' example_isolates[any(carbapenems()), ]
#' example_isolates[all(carbapenems()), ]
#'
#' # filter with multiple antibiotic selectors using c()
#' # filter with multiple antimicrobial selectors using c()
#' example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
#'
#' # filter + select in one go: get penicillins in carbapenem-resistant strains
@ -184,10 +193,10 @@
#' # and erythromycin is not a penicillin:
#' example_isolates[, penicillins() & administrable_per_os()]
#'
#' # ab_selector() applies a filter in the `antibiotics` data set and is thus
#' # very flexible. For instance, to select antibiotic columns with an oral DDD
#' # amr_selector() applies a filter in the `antibiotics` data set and is thus
#' # very flexible. For instance, to select antimicrobials with an oral DDD
#' # of at least 1 gram:
#' example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
#' example_isolates[, amr_selector(oral_ddd > 1 & oral_units == "g")]
#'
#'
#' # data.table --------------------------------------------------------------
@ -222,271 +231,305 @@
#' dt[any(carbapenems() == "S"), penicillins(), with = FALSE]
#' }
#' }
ab_class <- function(ab_class,
only_sir_columns = FALSE,
only_treatable = TRUE,
...) {
meet_criteria(ab_class, allow_class = "character", has_length = 1, allow_NULL = TRUE)
amr_class <- function(amr_class,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...) {
meet_criteria(amr_class, allow_class = "character", has_length = 1, allow_NULL = TRUE)
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec(NULL, only_sir_columns = only_sir_columns, ab_class_args = ab_class, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec(NULL, only_sir_columns = only_sir_columns, amr_class_args = amr_class, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @details The [ab_selector()] function can be used to internally filter the [antibiotics] data set on any results, see *Examples*. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
#' @rdname antimicrobial_class_selectors
#' @details The [amr_selector()] function can be used to internally filter the [antibiotics] data set on any results, see *Examples*. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
#' @export
ab_selector <- function(filter,
only_sir_columns = FALSE,
only_treatable = TRUE,
...) {
amr_selector <- function(filter,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
# get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call
# but it only takes a couple of milliseconds
vars_df <- get_current_data(arg_name = NA, call = -2)
# to improve speed, get_column_abx() will only run once when e.g. in a select or group call
ab_in_data <- get_column_abx(vars_df,
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "ab_selector"
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "amr_selector", return_all = return_all
)
call <- substitute(filter)
agents <- tryCatch(AMR_env$AB_lookup[which(eval(call, envir = AMR_env$AB_lookup)), "ab", drop = TRUE],
error = function(e) stop_(e$message, call = -5)
error = function(e) stop_(e$message, call = -5)
)
agents <- ab_in_data[ab_in_data %in% agents]
message_agent_names(
function_name = "ab_selector",
function_name = "amr_selector",
agents = agents,
ab_group = NULL,
examples = "",
call = call
)
structure(unname(agents),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
aminoglycosides <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
aminoglycosides <- function(only_sir_columns = FALSE, only_treatable = TRUE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec("aminoglycosides", only_sir_columns = only_sir_columns, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("aminoglycosides", only_sir_columns = only_sir_columns, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
aminopenicillins <- function(only_sir_columns = FALSE, ...) {
aminopenicillins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("aminopenicillins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("aminopenicillins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
antifungals <- function(only_sir_columns = FALSE, ...) {
antifungals <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("antifungals", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("antifungals", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
antimycobacterials <- function(only_sir_columns = FALSE, ...) {
antimycobacterials <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("antimycobacterials", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("antimycobacterials", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
betalactams <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
betalactams <- function(only_sir_columns = FALSE, only_treatable = TRUE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec("betalactams", only_sir_columns = only_sir_columns, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("betalactams", only_sir_columns = only_sir_columns, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
betalactams_with_inhibitor <- function(only_sir_columns = FALSE, ...) {
betalactams_with_inhibitor <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("betalactams_with_inhibitor", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("betalactams_with_inhibitor", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
carbapenems <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
carbapenems <- function(only_sir_columns = FALSE, only_treatable = TRUE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec("carbapenems", only_sir_columns = only_sir_columns, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("carbapenems", only_sir_columns = only_sir_columns, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins <- function(only_sir_columns = FALSE, ...) {
cephalosporins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins_1st <- function(only_sir_columns = FALSE, ...) {
cephalosporins_1st <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins_1st", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins_1st", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins_2nd <- function(only_sir_columns = FALSE, ...) {
cephalosporins_2nd <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins_2nd", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins_2nd", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins_3rd <- function(only_sir_columns = FALSE, ...) {
cephalosporins_3rd <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins_3rd", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins_3rd", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins_4th <- function(only_sir_columns = FALSE, ...) {
cephalosporins_4th <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins_4th", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins_4th", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
cephalosporins_5th <- function(only_sir_columns = FALSE, ...) {
cephalosporins_5th <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("cephalosporins_5th", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("cephalosporins_5th", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
fluoroquinolones <- function(only_sir_columns = FALSE, ...) {
fluoroquinolones <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("fluoroquinolones", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("fluoroquinolones", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
glycopeptides <- function(only_sir_columns = FALSE, ...) {
glycopeptides <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("glycopeptides", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("glycopeptides", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
lincosamides <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
lincosamides <- function(only_sir_columns = FALSE, only_treatable = TRUE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec("lincosamides", only_sir_columns = only_sir_columns, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("lincosamides", only_sir_columns = only_sir_columns, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
lipoglycopeptides <- function(only_sir_columns = FALSE, ...) {
lipoglycopeptides <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("lipoglycopeptides", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("lipoglycopeptides", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
macrolides <- function(only_sir_columns = FALSE, ...) {
macrolides <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("macrolides", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("macrolides", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
nitrofurans <- function(only_sir_columns = FALSE, ...) {
nitrofurans <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("nitrofurans", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("nitrofurans", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
oxazolidinones <- function(only_sir_columns = FALSE, ...) {
oxazolidinones <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("oxazolidinones", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("oxazolidinones", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
penicillins <- function(only_sir_columns = FALSE, ...) {
penicillins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("penicillins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("penicillins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
phenicols <- function(only_sir_columns = FALSE, ...) {
phenicols <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("phenicols", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("phenicols", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
polymyxins <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) {
polymyxins <- function(only_sir_columns = FALSE, only_treatable = TRUE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(only_treatable, allow_class = "logical", has_length = 1)
ab_select_exec("polymyxins", only_sir_columns = only_sir_columns, only_treatable = only_treatable)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("polymyxins", only_sir_columns = only_sir_columns, only_treatable = only_treatable, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
quinolones <- function(only_sir_columns = FALSE, ...) {
quinolones <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("quinolones", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("quinolones", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
rifamycins <- function(only_sir_columns = FALSE, ...) {
rifamycins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("rifamycins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("rifamycins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
streptogramins <- function(only_sir_columns = FALSE, ...) {
streptogramins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("streptogramins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("streptogramins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
tetracyclines <- function(only_sir_columns = FALSE, ...) {
tetracyclines <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("tetracyclines", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("tetracyclines", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
trimethoprims <- function(only_sir_columns = FALSE, ...) {
trimethoprims <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("trimethoprims", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("trimethoprims", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
ureidopenicillins <- function(only_sir_columns = FALSE, ...) {
ureidopenicillins <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
ab_select_exec("ureidopenicillins", only_sir_columns = only_sir_columns)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
amr_select_exec("ureidopenicillins", only_sir_columns = only_sir_columns, return_all = return_all)
}
#' @rdname antibiotic_class_selectors
#' @details The [administrable_per_os()] and [administrable_iv()] functions also rely on the [antibiotics] data set - antibiotic columns will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the [antibiotics] data set.
#' @rdname antimicrobial_class_selectors
#' @details The [administrable_per_os()] and [administrable_iv()] functions also rely on the [antibiotics] data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the [antibiotics] data set.
#' @export
administrable_per_os <- function(only_sir_columns = FALSE, ...) {
administrable_per_os <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
# get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call
# but it only takes a couple of milliseconds
vars_df <- get_current_data(arg_name = NA, call = -2)
# to improve speed, get_column_abx() will only run once when e.g. in a select or group call
ab_in_data <- get_column_abx(vars_df,
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "administrable_per_os"
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "administrable_per_os", return_all = return_all
)
agents_all <- AMR_env$AB_lookup[which(!is.na(AMR_env$AB_lookup$oral_ddd)), "ab", drop = TRUE]
agents <- AMR_env$AB_lookup[which(AMR_env$AB_lookup$ab %in% ab_in_data & !is.na(AMR_env$AB_lookup$oral_ddd)), "ab", drop = TRUE]
@ -500,8 +543,8 @@ administrable_per_os <- function(only_sir_columns = FALSE, ...) {
vector_or(
ab_name(
sample(agents_all,
size = min(5, length(agents_all)),
replace = FALSE
size = min(5, length(agents_all)),
replace = FALSE
),
tolower = TRUE,
language = NULL
@ -512,21 +555,22 @@ administrable_per_os <- function(only_sir_columns = FALSE, ...) {
)
)
structure(unname(agents),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @export
administrable_iv <- function(only_sir_columns = FALSE, ...) {
administrable_iv <- function(only_sir_columns = FALSE, return_all = TRUE, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
meet_criteria(return_all, allow_class = "logical", has_length = 1)
# get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call
# but it only takes a couple of milliseconds
vars_df <- get_current_data(arg_name = NA, call = -2)
# to improve speed, get_column_abx() will only run once when e.g. in a select or group call
ab_in_data <- get_column_abx(vars_df,
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "administrable_iv"
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "administrable_iv", return_all = return_all
)
agents_all <- AMR_env$AB_lookup[which(!is.na(AMR_env$AB_lookup$iv_ddd)), "ab", drop = TRUE]
agents <- AMR_env$AB_lookup[which(AMR_env$AB_lookup$ab %in% ab_in_data & !is.na(AMR_env$AB_lookup$iv_ddd)), "ab", drop = TRUE]
@ -538,13 +582,13 @@ administrable_iv <- function(only_sir_columns = FALSE, ...) {
examples = ""
)
structure(unname(agents),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
#' @rdname antibiotic_class_selectors
#' @rdname antimicrobial_class_selectors
#' @inheritParams eucast_rules
#' @details The [not_intrinsic_resistant()] function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of *E. coli* and *K. pneumoniae* and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies `r format_eucast_version_nr(names(EUCAST_VERSION_EXPERT_RULES[1]))` to determine intrinsic resistance, using the [eucast_rules()] function internally. Because of this determination, this function is quite slow in terms of performance.
#' @details The [not_intrinsic_resistant()] function can be used to only select antimicrobials that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of *E. coli* and *K. pneumoniae* and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies `r format_eucast_version_nr(names(EUCAST_VERSION_EXPERT_RULES[1]))` to determine intrinsic resistance, using the [eucast_rules()] function internally. Because of this determination, this function is quite slow in terms of performance.
#' @export
not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ...) {
meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1)
@ -553,21 +597,21 @@ not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, ver
vars_df <- get_current_data(arg_name = NA, call = -2)
# to improve speed, get_column_abx() will only run once when e.g. in a select or group call
ab_in_data <- get_column_abx(vars_df,
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "not_intrinsic_resistant"
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = "not_intrinsic_resistant", return_all = TRUE
)
# intrinsic vars
vars_df_R <- tryCatch(
sapply(
eucast_rules(vars_df,
col_mo = col_mo,
version_expertrules = version_expertrules,
rules = "expert",
info = FALSE
col_mo = col_mo,
version_expertrules = version_expertrules,
rules = "expert",
info = FALSE
),
function(col) {
tryCatch(!any(is.na(col)) && all(col == "R"),
error = function(e) FALSE
error = function(e) FALSE
)
}
),
@ -592,35 +636,39 @@ not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, ver
# find columns that are abx, but also intrinsic R
out <- unname(intersect(ab_in_data, vars_df_R))
structure(out,
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
ab_select_exec <- function(function_name,
only_sir_columns = FALSE,
only_treatable = FALSE,
ab_class_args = NULL) {
amr_select_exec <- function(function_name,
only_sir_columns = FALSE,
only_treatable = FALSE,
amr_class_args = NULL,
return_all = TRUE) {
# get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call
# it only takes a couple of milliseconds, so no problem
vars_df <- tryCatch(get_current_data(arg_name = NA, call = -3), error = function(e) NULL)
# to improve speed, get_column_abx() will only run once when e.g. in a select or group call
if (!is.null(vars_df)) {
ab_in_data <- get_column_abx(vars_df,
info = FALSE, only_sir_columns = only_sir_columns,
sort = FALSE, fn = function_name)
info = FALSE,
only_sir_columns = only_sir_columns,
sort = FALSE,
fn = function_name,
return_all = return_all)
}
# untreatable drugs
if (!is.null(vars_df) && only_treatable == TRUE) {
untreatable <- AMR_env$AB_lookup[which(AMR_env$AB_lookup$name %like% "(-high|EDTA|polysorbate|macromethod|screening|nacubactam)"), "ab", drop = TRUE]
if (any(untreatable %in% names(ab_in_data))) {
if (message_not_thrown_before(function_name, "ab_class", "untreatable")) {
if (message_not_thrown_before(function_name, "amr_class", "untreatable")) {
warning_(
"in `", function_name, "()`: some drugs were ignored since they cannot be used for treating patients: ",
vector_and(
ab_name(names(ab_in_data)[names(ab_in_data) %in% untreatable],
language = NULL,
tolower = TRUE
language = NULL,
tolower = TRUE
),
quotes = FALSE,
sort = TRUE
@ -630,13 +678,13 @@ ab_select_exec <- function(function_name,
ab_in_data <- ab_in_data[!names(ab_in_data) %in% untreatable]
}
}
if (!is.null(vars_df) && length(ab_in_data) == 0) {
message_("No antimicrobial drugs found in the data.")
return(NULL)
}
if (is.null(ab_class_args) || isTRUE(function_name %in% c("antifungals", "antimycobacterials"))) {
if (is.null(amr_class_args) || isTRUE(function_name %in% c("antifungals", "antimycobacterials"))) {
ab_group <- NULL
if (isTRUE(function_name == "antifungals")) {
abx <- AMR_env$AB_lookup$ab[which(AMR_env$AB_lookup$group == "Antifungals")]
@ -663,22 +711,22 @@ ab_select_exec <- function(function_name,
}
examples <- paste0(" (such as ", vector_or(
ab_name(sample(abx, size = min(2, length(abx)), replace = FALSE),
tolower = TRUE,
language = NULL
tolower = TRUE,
language = NULL
),
quotes = FALSE
), ")")
} else {
# this for the 'manual' ab_class() function
# this for the 'manual' amr_class() function
abx <- subset(
AMR_env$AB_lookup,
group %like% ab_class_args |
atc_group1 %like% ab_class_args |
atc_group2 %like% ab_class_args
group %like% amr_class_args |
atc_group1 %like% amr_class_args |
atc_group2 %like% amr_class_args
)$ab
ab_group <- find_ab_group(ab_class_args)
function_name <- "ab_class"
examples <- paste0(" (such as ", find_ab_names(ab_class_args, 2), ")")
ab_group <- find_ab_group(amr_class_args)
function_name <- "amr_class"
examples <- paste0(" (such as ", find_ab_names(amr_class_args, 2), ")")
}
if (is.null(vars_df)) {
@ -694,43 +742,43 @@ ab_select_exec <- function(function_name,
"\n\nNow returning a vector of all possible antimicrobials that `" , function_name, "()` can select.")
return(sort(abx))
}
# get the columns with a group names in the chosen ab class
agents <- ab_in_data[names(ab_in_data) %in% abx]
message_agent_names(
function_name = function_name,
agents = agents,
ab_group = ab_group,
examples = examples,
ab_class_args = ab_class_args
amr_class_args = amr_class_args
)
structure(unname(agents),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
#' @method print ab_selector
#' @method print amr_selector
#' @export
#' @noRd
print.ab_selector <- function(x, ...) {
warning_("It should never be needed to print an antibiotic selector class. Are you using data.table? Then add the argument `with = FALSE`, see our examples at `?ab_selector`.",
print.amr_selector <- function(x, ...) {
warning_("It should never be needed to print an antimicrobial selector class. Are you using data.table? Then add the argument `with = FALSE`, see our examples at `?amr_selector`.",
immediate = TRUE)
cat("Class 'ab_selector'\n")
cat("Class 'amr_selector'\n")
print(as.character(x), quote = FALSE)
}
#' @method c ab_selector
#' @method c amr_selector
#' @export
#' @noRd
c.ab_selector <- function(...) {
c.amr_selector <- function(...) {
structure(unlist(lapply(list(...), as.character)),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
all_any_ab_selector <- function(type, ..., na.rm = TRUE) {
all_any_amr_selector <- function(type, ..., na.rm = TRUE) {
cols_ab <- c(...)
result <- cols_ab[toupper(cols_ab) %in% c("S", "SDD", "I", "R", "NI")]
if (length(result) == 0) {
@ -739,13 +787,13 @@ all_any_ab_selector <- function(type, ..., na.rm = TRUE) {
}
cols_ab <- cols_ab[!cols_ab %in% result]
df <- get_current_data(arg_name = NA, call = -3)
if (type == "all") {
scope_fn <- all
} else {
scope_fn <- any
}
x_transposed <- as.list(as.data.frame(t(df[, cols_ab, drop = FALSE]), stringsAsFactors = FALSE))
vapply(
FUN.VALUE = logical(1),
@ -755,26 +803,26 @@ all_any_ab_selector <- function(type, ..., na.rm = TRUE) {
)
}
#' @method all ab_selector
#' @method all amr_selector
#' @export
#' @noRd
all.ab_selector <- function(..., na.rm = FALSE) {
all_any_ab_selector("all", ..., na.rm = na.rm)
all.amr_selector <- function(..., na.rm = FALSE) {
all_any_amr_selector("all", ..., na.rm = na.rm)
}
#' @method any ab_selector
#' @method any amr_selector
#' @export
#' @noRd
any.ab_selector <- function(..., na.rm = FALSE) {
all_any_ab_selector("any", ..., na.rm = na.rm)
any.amr_selector <- function(..., na.rm = FALSE) {
all_any_amr_selector("any", ..., na.rm = na.rm)
}
#' @method all ab_selector_any_all
#' @method all amr_selector_any_all
#' @export
#' @noRd
all.ab_selector_any_all <- function(..., na.rm = FALSE) {
# this is all() on a logical vector from `==.ab_selector` or `!=.ab_selector`
all.amr_selector_any_all <- function(..., na.rm = FALSE) {
# this is all() on a logical vector from `==.amr_selector` or `!=.amr_selector`
# e.g., example_isolates %>% filter(all(carbapenems() == "R"))
# so just return the vector as is, only correcting for na.rm
out <- unclass(c(...))
@ -784,11 +832,11 @@ all.ab_selector_any_all <- function(..., na.rm = FALSE) {
out
}
#' @method any ab_selector_any_all
#' @method any amr_selector_any_all
#' @export
#' @noRd
any.ab_selector_any_all <- function(..., na.rm = FALSE) {
# this is any() on a logical vector from `==.ab_selector` or `!=.ab_selector`
any.amr_selector_any_all <- function(..., na.rm = FALSE) {
# this is any() on a logical vector from `==.amr_selector` or `!=.amr_selector`
# e.g., example_isolates %>% filter(any(carbapenems() == "R"))
# so just return the vector as is, only correcting for na.rm
out <- unclass(c(...))
@ -798,10 +846,10 @@ any.ab_selector_any_all <- function(..., na.rm = FALSE) {
out
}
#' @method == ab_selector
#' @method == amr_selector
#' @export
#' @noRd
`==.ab_selector` <- function(e1, e2) {
`==.amr_selector` <- function(e1, e2) {
calls <- as.character(match.call())
fn_name <- calls[2]
fn_name <- gsub("^(c\\()(.*)(\\))$", "\\2", fn_name)
@ -818,15 +866,15 @@ any.ab_selector_any_all <- function(..., na.rm = FALSE) {
)
}
}
structure(all_any_ab_selector(type = type, e1, e2),
class = c("ab_selector_any_all", "logical")
structure(all_any_amr_selector(type = type, e1, e2),
class = c("amr_selector_any_all", "logical")
)
}
#' @method != ab_selector
#' @method != amr_selector
#' @export
#' @noRd
`!=.ab_selector` <- function(e1, e2) {
`!=.amr_selector` <- function(e1, e2) {
calls <- as.character(match.call())
fn_name <- calls[2]
fn_name <- gsub("^(c\\()(.*)(\\))$", "\\2", fn_name)
@ -846,29 +894,29 @@ any.ab_selector_any_all <- function(..., na.rm = FALSE) {
# this is `!=`, so turn around the values
sir <- c("S", "SDD", "I", "R", "NI")
e2 <- sir[sir != e2]
structure(all_any_ab_selector(type = type, e1, e2),
class = c("ab_selector_any_all", "logical")
structure(all_any_amr_selector(type = type, e1, e2),
class = c("amr_selector_any_all", "logical")
)
}
#' @method & ab_selector
#' @method & amr_selector
#' @export
#' @noRd
`&.ab_selector` <- function(e1, e2) {
`&.amr_selector` <- function(e1, e2) {
# this is only required for base R, since tidyselect has already implemented this
# e.g., for: example_isolates[, penicillins() & administrable_per_os()]
structure(intersect(unclass(e1), unclass(e2)),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
#' @method | ab_selector
#' @method | amr_selector
#' @export
#' @noRd
`|.ab_selector` <- function(e1, e2) {
`|.amr_selector` <- function(e1, e2) {
# this is only required for base R, since tidyselect has already implemented this
# e.g., for: example_isolates[, penicillins() | administrable_per_os()]
structure(union(unclass(e1), unclass(e2)),
class = c("ab_selector", "character")
class = c("amr_selector", "character")
)
}
@ -883,12 +931,12 @@ is_all <- function(el1) {
syscalls %like% paste0("[^_a-zA-Z0-9]all\\(", "(c\\()?", el1)
}
find_ab_group <- function(ab_class_args) {
ab_class_args <- gsub("[^a-zA-Z0-9]", ".*", ab_class_args)
find_ab_group <- function(amr_class_args) {
amr_class_args <- gsub("[^a-zA-Z0-9]", ".*", amr_class_args)
AMR_env$AB_lookup %pm>%
subset(group %like% ab_class_args |
atc_group1 %like% ab_class_args |
atc_group2 %like% ab_class_args) %pm>%
subset(group %like% amr_class_args |
atc_group1 %like% amr_class_args |
atc_group2 %like% amr_class_args) %pm>%
pm_pull(group) %pm>%
unique() %pm>%
tolower() %pm>%
@ -898,32 +946,32 @@ find_ab_group <- function(ab_class_args) {
find_ab_names <- function(ab_group, n = 3) {
ab_group <- gsub("[^a-zA-Z|0-9]", ".*", ab_group)
# try popular first, they have DDDs
drugs <- AMR_env$AB_lookup[which((!is.na(AMR_env$AB_lookup$iv_ddd) | !is.na(AMR_env$AB_lookup$oral_ddd)) &
AMR_env$AB_lookup$name %unlike% " " &
AMR_env$AB_lookup$group %like% ab_group &
AMR_env$AB_lookup$ab %unlike% "[0-9]$"), ]$name
AMR_env$AB_lookup$name %unlike% " " &
AMR_env$AB_lookup$group %like% ab_group &
AMR_env$AB_lookup$ab %unlike% "[0-9]$"), ]$name
if (length(drugs) < n) {
# now try it all
drugs <- AMR_env$AB_lookup[which((AMR_env$AB_lookup$group %like% ab_group |
AMR_env$AB_lookup$atc_group1 %like% ab_group |
AMR_env$AB_lookup$atc_group2 %like% ab_group) &
AMR_env$AB_lookup$ab %unlike% "[0-9]$"), ]$name
AMR_env$AB_lookup$atc_group1 %like% ab_group |
AMR_env$AB_lookup$atc_group2 %like% ab_group) &
AMR_env$AB_lookup$ab %unlike% "[0-9]$"), ]$name
}
if (length(drugs) == 0) {
return("??")
}
vector_or(
ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE),
tolower = TRUE,
language = NULL
tolower = TRUE,
language = NULL
),
quotes = FALSE
)
}
message_agent_names <- function(function_name, agents, ab_group = NULL, examples = "", ab_class_args = NULL, call = NULL) {
message_agent_names <- function(function_name, agents, ab_group = NULL, examples = "", amr_class_args = NULL, call = NULL) {
if (message_not_thrown_before(function_name, sort(agents))) {
if (length(agents) == 0) {
if (is.null(ab_group)) {
@ -942,12 +990,12 @@ message_agent_names <- function(function_name, agents, ab_group = NULL, examples
agents_formatted[need_name] <- paste0(agents_formatted[need_name], " (", agents_names[need_name], ")")
message_(
"For `", function_name, "(",
ifelse(function_name == "ab_class",
paste0("\"", ab_class_args, "\""),
ifelse(!is.null(call),
paste0(deparse(call), collapse = " "),
""
)
ifelse(function_name == "amr_class",
paste0("\"", amr_class_args, "\""),
ifelse(!is.null(call),
paste0(deparse(call), collapse = " "),
""
)
),
")` using ",
ifelse(length(agents) == 1, "column ", "columns "),

View File

@ -31,7 +31,7 @@
#'
#' Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods. Based on the approaches of Klinker *et al.*, Barbieri *et al.*, and the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki *et al.*, this function provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
#' @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 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 antibiotics vector of any antibiotic name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antimicrobial selectors][antimicrobial_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"` (default), `"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 (defaults to `"name"`): `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*.

View File

@ -108,7 +108,7 @@
#' ab_atc("Co-fluampicil")
#' ab_name("J01CR50")
#'
#' # even antibiotic selectors work
#' # even antimicrobial selectors work
#' x <- data.frame(
#' random_column = "some value",
#' coflu = as.sir("S"),

View File

@ -105,7 +105,8 @@ get_column_abx <- function(x,
only_sir_columns = FALSE,
sort = TRUE,
reuse_previous_result = TRUE,
fn = NULL) {
fn = NULL,
return_all = FALSE) {
# check if retrieved before, then get it from package environment
if (isTRUE(reuse_previous_result) && identical(
unique_call_id(
@ -253,47 +254,50 @@ get_column_abx <- function(x,
if (sort == TRUE) {
out <- out[order(names(out), out)]
}
# only keep the first hits, no duplicates
duplicates <- c(out[duplicated(names(out))], out[duplicated(unname(out))])
if (length(duplicates) > 0) {
all_okay <- FALSE
}
if (isTRUE(info)) {
if (all_okay == TRUE) {
message_(" OK.", add_fn = list(font_green, font_bold), as_note = FALSE)
} else {
message_(" WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE)
if (return_all == FALSE) {
# only keep the first hits, no duplicates
duplicates <- c(out[duplicated(names(out))], out[duplicated(unname(out))])
if (length(duplicates) > 0) {
all_okay <- FALSE
}
for (i in seq_len(length(out))) {
if (isTRUE(verbose) && !names(out[i]) %in% names(duplicates)) {
message_(
"Using column '", font_bold(out[i]), "' as input for ", names(out)[i],
" (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")."
)
if (isTRUE(info)) {
if (all_okay == TRUE) {
message_(" OK.", add_fn = list(font_green, font_bold), as_note = FALSE)
} else {
message_(" WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE)
}
if (names(out[i]) %in% names(duplicates)) {
already_set_as <- out[unname(out) == unname(out[i])][1L]
if (names(out)[i] != names(already_set_as)) {
warning_(
paste0(
"Column '", font_bold(out[i]), "' will not be used for ",
names(out)[i], " (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")",
", as it is already set for ",
names(already_set_as), " (", ab_name(names(already_set_as), tolower = TRUE, language = NULL), ")"
),
add_fn = font_red,
immediate = verbose
for (i in seq_len(length(out))) {
if (isTRUE(verbose) && !names(out[i]) %in% names(duplicates)) {
message_(
"Using column '", font_bold(out[i]), "' as input for ", names(out)[i],
" (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")."
)
}
if (names(out[i]) %in% names(duplicates)) {
already_set_as <- out[unname(out) == unname(out[i])][1L]
if (names(out)[i] != names(already_set_as)) {
warning_(
paste0(
"Column '", font_bold(out[i]), "' will not be used for ",
names(out)[i], " (", ab_name(names(out)[i], tolower = TRUE, language = NULL), ")",
", as it is already set for ",
names(already_set_as), " (", ab_name(names(already_set_as), tolower = TRUE, language = NULL), ")"
),
add_fn = font_red,
immediate = verbose
)
}
}
}
}
}
out <- out[!duplicated(names(out))]
out <- out[!duplicated(unname(out))]
if (sort == TRUE) {
out <- out[order(names(out), out)]
out <- out[!duplicated(names(out))]
out <- out[!duplicated(unname(out))]
if (sort == TRUE) {
out <- out[order(names(out), out)]
}
}
if (!is.null(hard_dependencies)) {

View File

@ -31,7 +31,7 @@
#'
#' Calculates a normalised mean for antimicrobial resistance between multiple observations, to help to identify similar isolates without comparing antibiograms by hand.
#' @param x a vector of class [sir][as.sir()], [mic][as.mic()] or [disk][as.disk()], or a [data.frame] containing columns of any of these classes
#' @param ... variables to select (supports [tidyselect language][tidyselect::language] such as `column1:column4` and `where(is.mic)`, and can thus also be [antibiotic selectors][ab_selector()]
#' @param ... variables to select (supports [tidyselect language][tidyselect::language] such as `column1:column4` and `where(is.mic)`, and can thus also be [antimicrobial selectors][amr_selector()]
#' @param combine_SI a [logical] to indicate whether all values of S, SDD, and I must be merged into one, so the input only consists of S+I vs. R (susceptible vs. resistant) - the default is `TRUE`
#' @details The mean AMR distance is effectively [the Z-score](https://en.wikipedia.org/wiki/Standard_score); a normalised numeric value to compare AMR test results which can help to identify similar isolates, without comparing antibiograms by hand.
#'

View File

@ -60,10 +60,10 @@
#' 4 | | |
#' ```
#'
#' We save it as `"home/me/ourcodes.xlsx"`. Now we have to set it as a source:
#' We save it as `"/Users/me/Documents/ourcodes.xlsx"`. Now we have to set it as a source:
#'
#' ```
#' set_mo_source("home/me/ourcodes.xlsx")
#' set_mo_source("/Users/me/Documents/ourcodes.xlsx")
#' #> NOTE: Created mo_source file '/Users/me/mo_source.rds' (0.3 kB) from
#' #> '/Users/me/Documents/ourcodes.xlsx' (9 kB), columns
#' #> "Organisation XYZ" and "mo"

View File

@ -151,7 +151,7 @@
#' )
#' }
#' if (require("dplyr")) {
#' # scoped dplyr verbs with antibiotic selectors
#' # scoped dplyr verbs with antimicrobial selectors
#' # (you could also use across() of course)
#' example_isolates %>%
#' group_by(ward) %>%

View File

@ -34,27 +34,27 @@
# see https://github.com/tidyverse/dplyr/issues/5955 why this is required
# S3: ab_selector ----
# S3: amr_selector ----
# this does not need a .default method since it's used internally only
vec_ptype2.character.ab_selector <- function(x, y, ...) {
vec_ptype2.character.amr_selector <- function(x, y, ...) {
x
}
vec_ptype2.ab_selector.character <- function(x, y, ...) {
vec_ptype2.amr_selector.character <- function(x, y, ...) {
y
}
vec_cast.character.ab_selector <- function(x, to, ...) {
vec_cast.character.amr_selector <- function(x, to, ...) {
unclass(x)
}
# S3: ab_selector_any_all ----
# S3: amr_selector_any_all ----
# this does not need a .default method since it's used internally only
vec_ptype2.logical.ab_selector_any_all <- function(x, y, ...) {
vec_ptype2.logical.amr_selector_any_all <- function(x, y, ...) {
x
}
vec_ptype2.ab_selector_any_all.logical <- function(x, y, ...) {
vec_ptype2.amr_selector_any_all.logical <- function(x, y, ...) {
y
}
vec_cast.logical.ab_selector_any_all <- function(x, to, ...) {
vec_cast.logical.amr_selector_any_all <- function(x, to, ...) {
unclass(x)
}

View File

@ -27,14 +27,28 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
# #' Deprecated Functions
# #'
# #' These functions are so-called '[Deprecated]'. **They will be removed in a future release.** Using the functions will give a warning with the name of the function it has been replaced by (if there is one).
# #' @keywords internal
# #' @name AMR-deprecated
# #' @rdname AMR-deprecated
# #' @export
# NULL
#' Deprecated Functions
#'
#' These functions are so-called '[Deprecated]'. **They will be removed in a future version of this package.** Using these functions will give a warning with the name of the function it has been replaced by (if there is one).
#' @keywords internal
#' @name AMR-deprecated
#' @rdname AMR-deprecated
NULL
#' @rdname AMR-deprecated
#' @export
ab_class <- function(...) {
deprecation_warning("ab_class", "amr_class")
amr_class(...)
}
#' @rdname AMR-deprecated
#' @export
ab_selector <- function(...) {
deprecation_warning("ab_selector", "amr_selector")
amr_selector(...)
}
deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL, is_function = TRUE) {
if (is.null(old)) {
@ -53,7 +67,7 @@ deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL, is_fun
warning_(
ifelse(is.null(new),
paste0("The `", old, "` ", type, " is no longer in use"),
paste0("The `", old, "` ", type, " has been replaced with `", new, "`")
paste0("The `", old, "` ", type, " has been replaced with `", new, "` and will be removed in a future version")
),
ifelse(type == "argument",
". While the old argument still works, it will be removed in a future version, so please update your code.",

16
R/zzz.R
View File

@ -135,14 +135,14 @@ AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE)
s3_register("knitr::knit_print", "formatted_bug_drug_combinations")
# Support vctrs package for use in e.g. dplyr verbs
# NOTE 2024-02-22 this is the right way - it should be 2 S3 classes in the second argument
# S3: ab_selector
s3_register("vctrs::vec_ptype2", "character.ab_selector")
s3_register("vctrs::vec_ptype2", "ab_selector.character")
s3_register("vctrs::vec_cast", "character.ab_selector")
# S3: ab_selector_any_all
s3_register("vctrs::vec_ptype2", "logical.ab_selector_any_all")
s3_register("vctrs::vec_ptype2", "ab_selector_any_all.logical")
s3_register("vctrs::vec_cast", "logical.ab_selector_any_all")
# S3: amr_selector
s3_register("vctrs::vec_ptype2", "character.amr_selector")
s3_register("vctrs::vec_ptype2", "amr_selector.character")
s3_register("vctrs::vec_cast", "character.amr_selector")
# S3: amr_selector_any_all
s3_register("vctrs::vec_ptype2", "logical.amr_selector_any_all")
s3_register("vctrs::vec_ptype2", "amr_selector_any_all.logical")
s3_register("vctrs::vec_cast", "logical.amr_selector_any_all")
# S3: ab
s3_register("vctrs::vec_ptype2", "ab.default")
s3_register("vctrs::vec_ptype2", "ab.ab")

View File

@ -1,29 +1,37 @@
# `AMR` (for R)
<a target="_blank" href="https://chatgpt.com/g/g-M4UNLwFi5-amr-for-r-assistant"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/assets/AMRforRGPT.svg" style="width: 400px;"></a>
# The `AMR` Package for R
----
`AMR` is a free, open-source and independent R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. It is currently being used in over 175 countries. This work was published in the Journal of Statistical Software (2022, Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)).
After installing this package, R knows ~52,000 distinct microbial species and all ~600 antibiotic, antimycotic, and antiviral drugs by name and code (including ATC, WHONET/EARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. It supports any data format, including WHONET/EARS-Net data. Antimicrobial names and group names are available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish, and Ukrainian.
The `AMR` package is a free and open-source R package with zero dependencies to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting.
This package is fully independent of any other R package and works on Windows, macOS and Linux with all versions of R since R-3.0.0 (April 2013). It was designed to work in any setting, including those with very limited resources. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the University of Groningen, in collaboration with non-profit organisations Certe Medical Diagnostics and Advice Foundation and University Medical Center Groningen. This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation.
Overview:
This is the development source of the `AMR` package for R. Not a developer? Then please visit our website [https://msberends.github.io/AMR/](https://msberends.github.io/AMR/) to read more about this package.
* Provides an **all-in-one solution** for antimicrobial resistance (AMR) data analysis in a One Health approach
* Used in over 175 countries, available in 20 languages
* Generates **antibiograms** - traditional, combined, syndromic, and even WISCA
* Provides the **full microbiological taxonomy** and extensive info on **all antimicrobial drugs**
* Applies all recent **CLSI** and **EUCAST** clinical and veterinary breakpoints for MICs, disk zones and ECOFFs
* Corrects for duplicate isolates, **calculates** and **predicts** AMR per antimicrobial class
* Integrates with **WHONET**, ATC, **EARS-Net**, PubChem, **LOINC**, **SNOMED CT**, and **NCBI**
* 100% free of costs and dependencies, highly suitable for places with **limited resources**
*NOTE: this source code is on GitHub (https://github.com/msberends/AMR), but also automatically mirrored to our university's Gitea server (https://git.web.rug.nl/P281424/AMR) and to GitLab (https://gitlab.com/msberends/AMR).*
----
Please visit our extensive website [https://msberends.github.io/AMR/](https://msberends.github.io/AMR/) to read more about this package, including many examples and tutorials.
### How to get this package
Please see [our website](https://msberends.github.io/AMR/#get-this-package).
You can install or update the `AMR` package from CRAN using:
To install the latest 'release' version from CRAN:
```r
install.packages("AMR")
```
It will be downloaded and installed automatically. For RStudio, click on the menu *Tools* > *Install Packages...* and then type in "AMR" and press <kbd>Install</kbd>.
To install the latest 'beta' version from GitHub:
```r
remotes::install_github("msberends/AMR")
```
----

View File

@ -139,7 +139,7 @@ reference:
These functions are meant to get taxonomically valid properties of microorganisms from any input, but
also properties derived from taxonomy, such as the Gram stain (`mo_gramstain()`) , or `mo_is_yeast()`.
Use `mo_source()` to teach this package how to translate your own codes to valid microorganisms, and
use `add_custom_microorganisms() to add your own custom microorganisms to this package.
use `add_custom_microorganisms()` to add your own custom microorganisms to this package.
contents:
- "`as.mo`"
- "`mo_property`"
@ -186,7 +186,7 @@ reference:
- "`mdro`"
- "`count`"
- "`bug_drug_combinations`"
- "`antibiotic_class_selectors`"
- "`antimicrobial_class_selectors`"
- "`mean_amr_distance`"
- "`resistance_predict`"
- "`guess_ab_col`"

View File

@ -1,5 +1,5 @@
This files contains all context you must know about the AMR package for R.
First and foremost, you are trained on version 2.1.1.9123. Remember this whenever someone asks which AMR package version youre at.
First and foremost, you are trained on version 2.1.1.9125. Remember this whenever someone asks which AMR package version youre at.
--------------------------------
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE':
@ -7,9 +7,9 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE':
# Generated by roxygen2: do not edit by hand
S3method("!=",ab_selector)
S3method("&",ab_selector)
S3method("==",ab_selector)
S3method("!=",amr_selector)
S3method("&",amr_selector)
S3method("==",amr_selector)
S3method("[",ab)
S3method("[",av)
S3method("[",disk)
@ -32,15 +32,15 @@ S3method("[[<-",disk)
S3method("[[<-",mic)
S3method("[[<-",mo)
S3method("[[<-",sir)
S3method("|",ab_selector)
S3method("|",amr_selector)
S3method(Complex,mic)
S3method(Math,mic)
S3method(Ops,mic)
S3method(Summary,mic)
S3method(all,ab_selector)
S3method(all,ab_selector_any_all)
S3method(any,ab_selector)
S3method(any,ab_selector_any_all)
S3method(all,amr_selector)
S3method(all,amr_selector_any_all)
S3method(any,amr_selector)
S3method(any,amr_selector_any_all)
S3method(as.data.frame,ab)
S3method(as.data.frame,av)
S3method(as.data.frame,mic)
@ -62,7 +62,7 @@ S3method(barplot,disk)
S3method(barplot,mic)
S3method(barplot,sir)
S3method(c,ab)
S3method(c,ab_selector)
S3method(c,amr_selector)
S3method(c,av)
S3method(c,custom_eucast_rules)
S3method(c,custom_mdro_guideline)
@ -91,7 +91,7 @@ S3method(plot,mic)
S3method(plot,resistance_predict)
S3method(plot,sir)
S3method(print,ab)
S3method(print,ab_selector)
S3method(print,amr_selector)
S3method(print,av)
S3method(print,bug_drug_combinations)
S3method(print,custom_eucast_rules)
@ -158,7 +158,9 @@ export(age_groups)
export(all_antimicrobials)
export(aminoglycosides)
export(aminopenicillins)
export(amr_class)
export(amr_distance_from_row)
export(amr_selector)
export(anti_join_microorganisms)
export(antibiogram)
export(antifungals)
@ -375,7 +377,7 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'index.md':
* Generates **antibiograms** - traditional, combined, syndromic, and even WISCA
* Provides the **full microbiological taxonomy** and extensive info on **all antimicrobial drugs**
* Applies all recent **CLSI** and **EUCAST** clinical and veterinary breakpoints for MICs, disk zones and ECOFFs
* Corrects for duplicate isolates, **calculates** and **predicts** AMR per antibiotic class
* Corrects for duplicate isolates, **calculates** and **predicts** AMR per antimicrobial class
* Integrates with **WHONET**, ATC, **EARS-Net**, PubChem, **LOINC**, **SNOMED CT**, and **NCBI**
* 100% free of costs and dependencies, highly suitable for places with **limited resources**
@ -410,7 +412,7 @@ With the help of contributors from all corners of the world, the `AMR` package i
#### Filtering and selecting data
One of the most powerful functions of this package, aside from calculating and plotting AMR, is selecting and filtering based on antibiotic columns. This can be done using the so-called [antibiotic class selectors](https://msberends.github.io/AMR/reference/antibiotic_class_selectors.html) that work in base R, `dplyr` and `data.table`:
One of the most powerful functions of this package, aside from calculating and plotting AMR, is selecting and filtering based on antimicrobial columns. This can be done using the so-called [antimicrobial class selectors](https://msberends.github.io/AMR/reference/antimicrobial_class_selectors.html), which work in base R, `dplyr` and `data.table`:
```r
# AMR works great with dplyr, but it's not required or neccesary
@ -422,7 +424,7 @@ example_isolates %>%
# filtering functions for microorganisms:
filter(mo_is_gram_negative(),
mo_is_intrinsic_resistant(ab = "cefotax")) %>%
# antibiotic selectors:
# antimicrobial selectors:
select(bacteria,
aminoglycosides(),
carbapenems())
@ -532,7 +534,7 @@ example_isolates %>%
|ICU | 0.290 |0.253-0.330 | 0.400 |0.353-0.449 |
|Outpatient | 0.200 |0.131-0.285 | 0.368 |0.254-0.493 |
Or use [antibiotic class selectors](https://msberends.github.io/AMR/reference/antibiotic_class_selectors.html) to select a series of antibiotic columns:
Or use [antimicrobial class selectors](https://msberends.github.io/AMR/reference/antimicrobial_class_selectors.html) to select a series of antibiotic columns:
```r
library(AMR)
@ -588,7 +590,7 @@ This package was intended as a comprehensive toolbox for integrated AMR data ana
* Calculating (empirical) susceptibility of both mono therapy and combination therapies ([tutorial](./articles/AMR.html))
* Predicting future antimicrobial resistance using regression models ([tutorial](./articles/resistance_predict.html))
* Getting properties for any microorganism (like Gram stain, species, genus or family) ([manual](./reference/mo_property.html))
* Getting properties for any antibiotic (like name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) ([manual](./reference/ab_property.html))
* Getting properties for any antimicrobial (like name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) ([manual](./reference/ab_property.html))
* Plotting antimicrobial resistance ([tutorial](./articles/AMR.html))
* Applying EUCAST expert rules ([manual](./reference/eucast_rules.html))
* Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code ([manual](./reference/mo_property.html))
@ -682,6 +684,28 @@ This R package is free, open-source software and licensed under the [GNU General
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/AMR-deprecated.Rd':
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zz_deprecated.R
\name{AMR-deprecated}
\alias{AMR-deprecated}
\alias{ab_class}
\alias{ab_selector}
\title{Deprecated Functions}
\usage{
ab_class(...)
ab_selector(...)
}
\description{
These functions are so-called '\link{Deprecated}'. \strong{They will be removed in a future version of this package.} Using these functions will give a warning with the name of the function it has been replaced by (if there is one).
}
\keyword{internal}
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/AMR-options.Rd':
@ -1312,7 +1336,7 @@ add_custom_antimicrobials(
ab_atc("Co-fluampicil")
ab_name("J01CR50")
# even antibiotic selectors work
# even antimicrobial selectors work
x <- data.frame(
random_column = "some value",
coflu = as.sir("S"),
@ -1635,7 +1659,7 @@ antibiogram(
\arguments{
\item{x}{a \link{data.frame} containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})}
\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
\item{mo_transform}{a character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.}
@ -1923,373 +1947,6 @@ plot(ab2)
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antibiotic_class_selectors.Rd':
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ab_selectors.R
\name{antibiotic_class_selectors}
\alias{antibiotic_class_selectors}
\alias{ab_class}
\alias{ab_selector}
\alias{aminoglycosides}
\alias{aminopenicillins}
\alias{antifungals}
\alias{antimycobacterials}
\alias{betalactams}
\alias{betalactams_with_inhibitor}
\alias{carbapenems}
\alias{cephalosporins}
\alias{cephalosporins_1st}
\alias{cephalosporins_2nd}
\alias{cephalosporins_3rd}
\alias{cephalosporins_4th}
\alias{cephalosporins_5th}
\alias{fluoroquinolones}
\alias{glycopeptides}
\alias{lincosamides}
\alias{lipoglycopeptides}
\alias{macrolides}
\alias{nitrofurans}
\alias{oxazolidinones}
\alias{penicillins}
\alias{phenicols}
\alias{polymyxins}
\alias{quinolones}
\alias{rifamycins}
\alias{streptogramins}
\alias{tetracyclines}
\alias{trimethoprims}
\alias{ureidopenicillins}
\alias{administrable_per_os}
\alias{administrable_iv}
\alias{not_intrinsic_resistant}
\title{Antibiotic Selectors}
\usage{
ab_class(ab_class, only_sir_columns = FALSE, only_treatable = TRUE, ...)
ab_selector(filter, only_sir_columns = FALSE, only_treatable = TRUE, ...)
aminoglycosides(only_sir_columns = FALSE, only_treatable = TRUE, ...)
aminopenicillins(only_sir_columns = FALSE, ...)
antifungals(only_sir_columns = FALSE, ...)
antimycobacterials(only_sir_columns = FALSE, ...)
betalactams(only_sir_columns = FALSE, only_treatable = TRUE, ...)
betalactams_with_inhibitor(only_sir_columns = FALSE, ...)
carbapenems(only_sir_columns = FALSE, only_treatable = TRUE, ...)
cephalosporins(only_sir_columns = FALSE, ...)
cephalosporins_1st(only_sir_columns = FALSE, ...)
cephalosporins_2nd(only_sir_columns = FALSE, ...)
cephalosporins_3rd(only_sir_columns = FALSE, ...)
cephalosporins_4th(only_sir_columns = FALSE, ...)
cephalosporins_5th(only_sir_columns = FALSE, ...)
fluoroquinolones(only_sir_columns = FALSE, ...)
glycopeptides(only_sir_columns = FALSE, ...)
lincosamides(only_sir_columns = FALSE, only_treatable = TRUE, ...)
lipoglycopeptides(only_sir_columns = FALSE, ...)
macrolides(only_sir_columns = FALSE, ...)
nitrofurans(only_sir_columns = FALSE, ...)
oxazolidinones(only_sir_columns = FALSE, ...)
penicillins(only_sir_columns = FALSE, ...)
phenicols(only_sir_columns = FALSE, ...)
polymyxins(only_sir_columns = FALSE, only_treatable = TRUE, ...)
quinolones(only_sir_columns = FALSE, ...)
rifamycins(only_sir_columns = FALSE, ...)
streptogramins(only_sir_columns = FALSE, ...)
tetracyclines(only_sir_columns = FALSE, ...)
trimethoprims(only_sir_columns = FALSE, ...)
ureidopenicillins(only_sir_columns = FALSE, ...)
administrable_per_os(only_sir_columns = FALSE, ...)
administrable_iv(only_sir_columns = FALSE, ...)
not_intrinsic_resistant(
only_sir_columns = FALSE,
col_mo = NULL,
version_expertrules = 3.3,
...
)
}
\arguments{
\item{ab_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
\item{only_sir_columns}{a \link{logical} to indicate whether only columns of class \code{sir} must be selected (default is \code{FALSE}), see \code{\link[=as.sir]{as.sir()}}}
\item{only_treatable}{a \link{logical} to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (default is \code{TRUE}), such as gentamicin-high (\code{GEH}) and imipenem/EDTA (\code{IPE})}
\item{...}{ignored, only in place to allow future extensions}
\item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{version_expertrules}{the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be "3.3", "3.2", or "3.1".}
}
\value{
When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"ab_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter.
}
\description{
These functions allow for filtering rows and selecting columns based on antibiotic test results that are of a specific antibiotic class or group (according to the \link{antibiotics} data set), without the need to define the columns or antibiotic abbreviations.
In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up by \code{\link[=cephalosporins]{cephalosporins()}}.
}
\details{
These functions can be used in data set calls for selecting columns and filtering rows. They work with base \R, the Tidyverse, and \code{data.table}. They are heavily inspired by the \link[tidyselect:language]{Tidyverse selection helpers} such as \code{\link[tidyselect:everything]{everything()}}, but are not limited to \code{dplyr} verbs. Nonetheless, they are very convenient to use with \code{dplyr} functions such as \code{\link[dplyr:select]{select()}}, \code{\link[dplyr:filter]{filter()}} and \code{\link[dplyr:summarise]{summarise()}}, see \emph{Examples}.
All columns in the data in which these functions are called will be searched for known antibiotic names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antibiotics} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
The \code{\link[=ab_class]{ab_class()}} function can be used to filter/select on a manually defined antibiotic class. It searches for results in the \link{antibiotics} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
The \code{\link[=ab_selector]{ab_selector()}} function can be used to internally filter the \link{antibiotics} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antibiotics} data set - antibiotic columns will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antibiotics} data set.
The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of \emph{E. coli} and \emph{K. pneumoniae} and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021) to determine intrinsic resistance, using the \code{\link[=eucast_rules]{eucast_rules()}} function internally. Because of this determination, this function is quite slow in terms of performance.
}
\section{Full list of supported (antibiotic) classes}{
\itemize{
\item \code{\link[=aminoglycosides]{aminoglycosides()}} can select: \cr amikacin (AMK), amikacin/fosfomycin (AKF), apramycin (APR), arbekacin (ARB), astromicin (AST), bekanamycin (BEK), dibekacin (DKB), framycetin (FRM), gentamicin (GEN), gentamicin-high (GEH), habekacin (HAB), hygromycin (HYG), isepamicin (ISE), kanamycin (KAN), kanamycin-high (KAH), kanamycin/cephalexin (KAC), micronomicin (MCR), neomycin (NEO), netilmicin (NET), pentisomicin (PIM), plazomicin (PLZ), propikacin (PKA), ribostamycin (RST), sisomicin (SIS), streptoduocin (STR), streptomycin (STR1), streptomycin-high (STH), tobramycin (TOB), and tobramycin-high (TOH)
\item \code{\link[=aminopenicillins]{aminopenicillins()}} can select: \cr amoxicillin (AMX) and ampicillin (AMP)
\item \code{\link[=antifungals]{antifungals()}} can select: \cr amorolfine (AMO), amphotericin B (AMB), amphotericin B-high (AMH), anidulafungin (ANI), butoconazole (BUT), caspofungin (CAS), ciclopirox (CIX), clotrimazole (CTR), econazole (ECO), fluconazole (FLU), flucytosine (FCT), fosfluconazole (FFL), griseofulvin (GRI), hachimycin (HCH), ibrexafungerp (IBX), isavuconazole (ISV), isoconazole (ISO), itraconazole (ITR), ketoconazole (KET), manogepix (MGX), micafungin (MIF), miconazole (MCZ), nystatin (NYS), oteseconazole (OTE), pimaricin (PMR), posaconazole (POS), rezafungin (RZF), ribociclib (RBC), sulconazole (SUC), terbinafine (TRB), terconazole (TRC), and voriconazole (VOR)
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid (AMA), calcium aminosalicylate (CLA), capreomycin (CAP), clofazimine (CLF), delamanid (DLM), enviomycin (ENV), ethambutol (ETH), ethambutol/isoniazid (ETI), ethionamide (ETI1), isoniazid (INH), isoniazid/sulfamethoxazole/trimethoprim/pyridoxine (IST), morinamide (MRN), p-aminosalicylic acid (PAS), pretomanid (PMD), protionamide (PTH), pyrazinamide (PZA), rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), rifapentine (RFP), simvastatin/fenofibrate (SMF), sodium aminosalicylate (SDA), streptomycin/isoniazid (STI), terizidone (TRZ), thioacetazone (TAT), thioacetazone/isoniazid (THI1), tiocarlide (TCR), and viomycin (VIO)
\item \code{\link[=betalactams]{betalactams()}} can select: \cr amoxicillin (AMX), amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin (AMP), ampicillin/sulbactam (SAM), apalcillin (APL), aspoxicillin (APX), avibactam (AVB), azidocillin (AZD), azlocillin (AZL), aztreonam (ATM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), bacampicillin (BAM), benzathine benzylpenicillin (BNB), benzathine phenoxymethylpenicillin (BNP), benzylpenicillin (PEN), biapenem (BIA), carbenicillin (CRB), carindacillin (CRN), cefacetrile (CAC), cefaclor (CEC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefamandole (MAN), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefetamet (CAT), cefetamet pivoxil (CPI), cefetecol (CCL), cefetrizole (CZL), cefiderocol (FDC), cefixime (CFM), cefmenoxime (CMX), cefmetazole (CMZ), cefodizime (DIZ), cefonicid (CID), cefoperazone (CFP), cefoperazone/sulbactam (CSL), ceforanide (CND), cefoselis (CSE), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotetan (CTT), cefotiam (CTF), cefotiam hexetil (CHE), cefovecin (FOV), cefoxitin (FOX), cefoxitin screening (FOX1), cefozopran (ZOP), cefpimizole (CFZ), cefpiramide (CPM), cefpirome (CPO), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefprozil (CPR), cefquinome (CEQ), cefroxadine (CRD), cefsulodin (CFS), cefsumide (CSU), ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftezole (CTL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), ceftolozane/tazobactam (CZT), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), cefuroxime (CXM), cefuroxime axetil (CXA), cephradine (CED), ciclacillin (CIC), clometocillin (CLM), cloxacillin (CLO), dicloxacillin (DIC), doripenem (DOR), epicillin (EPC), ertapenem (ETP), flucloxacillin (FLC), hetacillin (HET), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), latamoxef (LTM), lenampicillin (LEN), loracarbef (LOR), mecillinam (MEC), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), metampicillin (MTM), meticillin (MET), mezlocillin (MEZ), mezlocillin/sulbactam (MSU), nacubactam (NAC), nafcillin (NAF), oxacillin (OXA), panipenem (PAN), penamecillin (PNM), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), pheneticillin (PHE), phenoxymethylpenicillin (PHN), piperacillin (PIP), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), piridicillin (PRC), pivampicillin (PVM), pivmecillinam (PME), procaine benzylpenicillin (PRB), propicillin (PRP), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), sarmoxicillin (SRX), sulbactam (SUL), sulbenicillin (SBC), sultamicillin (SLT6), talampicillin (TAL), tazobactam (TAZ), tebipenem (TBP), temocillin (TEM), ticarcillin (TIC), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=betalactams_with_inhibitor]{betalactams_with_inhibitor()}} can select: \cr amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin/sulbactam (SAM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), cefepime/clavulanic acid (CPC), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefoperazone/sulbactam (CSL), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefpodoxime/clavulanic acid (CDC), ceftaroline/avibactam (CPA), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), ceftolozane/tazobactam (CZT), ceftriaxone/beta-lactamase inhibitor (CEB), imipenem/relebactam (IMR), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), mezlocillin/sulbactam (MSU), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=carbapenems]{carbapenems()}} can select: \cr biapenem (BIA), doripenem (DOR), ertapenem (ETP), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), panipenem (PAN), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), and tebipenem (TBP)
\item \code{\link[=cephalosporins]{cephalosporins()}} can select: \cr cefacetrile (CAC), cefaclor (CEC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefamandole (MAN), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/tazobactam (FPT), cefetamet (CAT), cefetamet pivoxil (CPI), cefetecol (CCL), cefetrizole (CZL), cefiderocol (FDC), cefixime (CFM), cefmenoxime (CMX), cefmetazole (CMZ), cefodizime (DIZ), cefonicid (CID), cefoperazone (CFP), cefoperazone/sulbactam (CSL), ceforanide (CND), cefoselis (CSE), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotetan (CTT), cefotiam (CTF), cefotiam hexetil (CHE), cefovecin (FOV), cefoxitin (FOX), cefoxitin screening (FOX1), cefozopran (ZOP), cefpimizole (CFZ), cefpiramide (CPM), cefpirome (CPO), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefprozil (CPR), cefquinome (CEQ), cefroxadine (CRD), cefsulodin (CFS), cefsumide (CSU), ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftezole (CTL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), ceftolozane/tazobactam (CZT), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), cefuroxime (CXM), cefuroxime axetil (CXA), cephradine (CED), latamoxef (LTM), and loracarbef (LOR)
\item \code{\link[=cephalosporins_1st]{cephalosporins_1st()}} can select: \cr cefacetrile (CAC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefroxadine (CRD), ceftezole (CTL), and cephradine (CED)
\item \code{\link[=cephalosporins_2nd]{cephalosporins_2nd()}} can select: \cr cefaclor (CEC), cefamandole (MAN), cefmetazole (CMZ), cefonicid (CID), ceforanide (CND), cefotetan (CTT), cefotiam (CTF), cefoxitin (FOX), cefoxitin screening (FOX1), cefprozil (CPR), cefuroxime (CXM), cefuroxime axetil (CXA), and loracarbef (LOR)
\item \code{\link[=cephalosporins_3rd]{cephalosporins_3rd()}} can select: \cr cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefetamet (CAT), cefetamet pivoxil (CPI), cefixime (CFM), cefmenoxime (CMX), cefodizime (DIZ), cefoperazone (CFP), cefoperazone/sulbactam (CSL), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotiam hexetil (CHE), cefovecin (FOV), cefpimizole (CFZ), cefpiramide (CPM), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefsulodin (CFS), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), and latamoxef (LTM)
\item \code{\link[=cephalosporins_4th]{cephalosporins_4th()}} can select: \cr cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/tazobactam (FPT), cefetecol (CCL), cefoselis (CSE), cefozopran (ZOP), cefpirome (CPO), and cefquinome (CEQ)
\item \code{\link[=cephalosporins_5th]{cephalosporins_5th()}} can select: \cr ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), and ceftolozane/tazobactam (CZT)
\item \code{\link[=fluoroquinolones]{fluoroquinolones()}} can select: \cr besifloxacin (BES), ciprofloxacin (CIP), clinafloxacin (CLX), danofloxacin (DAN), delafloxacin (DFX), difloxacin (DIF), enoxacin (ENX), enrofloxacin (ENR), finafloxacin (FIN), fleroxacin (FLE), garenoxacin (GRN), gatifloxacin (GAT), gemifloxacin (GEM), grepafloxacin (GRX), lascufloxacin (LSC), levofloxacin (LVX), levonadifloxacin (LND), lomefloxacin (LOM), marbofloxacin (MAR), metioxate (MXT), miloxacin (MIL), moxifloxacin (MFX), nadifloxacin (NAD), nifuroquine (NIF), norfloxacin (NOR), ofloxacin (OFX), orbifloxacin (ORB), pazufloxacin (PAZ), pefloxacin (PEF), pradofloxacin (PRA), premafloxacin (PRX), prulifloxacin (PRU), rufloxacin (RFL), sarafloxacin (SAR), sitafloxacin (SIT), sparfloxacin (SPX), temafloxacin (TMX), tilbroquinol (TBQ), tioxacin (TXC), tosufloxacin (TFX), and trovafloxacin (TVA)
\item \code{\link[=glycopeptides]{glycopeptides()}} can select: \cr avoparcin (AVO), dalbavancin (DAL), norvancomycin (NVA), oritavancin (ORI), ramoplanin (RAM), teicoplanin (TEC), teicoplanin-macromethod (TCM), telavancin (TLV), vancomycin (VAN), and vancomycin-macromethod (VAM)
\item \code{\link[=lincosamides]{lincosamides()}} can select: \cr acetylmidecamycin (ACM), acetylspiramycin (ASP), clindamycin (CLI), clindamycin inducible screening (CLI1), gamithromycin (GAM), kitasamycin (KIT), lincomycin (LIN), meleumycin (MEL), nafithromycin (ZWK), pirlimycin (PRL), primycin (PRM), solithromycin (SOL), tildipirosin (TIP), tilmicosin (TIL), tulathromycin (TUL), tylosin (TYL), and tylvalosin (TYL1)
\item \code{\link[=lipoglycopeptides]{lipoglycopeptides()}} can select: \cr dalbavancin (DAL), oritavancin (ORI), and telavancin (TLV)
\item \code{\link[=macrolides]{macrolides()}} can select: \cr acetylmidecamycin (ACM), acetylspiramycin (ASP), azithromycin (AZM), clarithromycin (CLR), dirithromycin (DIR), erythromycin (ERY), flurithromycin (FLR1), gamithromycin (GAM), josamycin (JOS), kitasamycin (KIT), meleumycin (MEL), midecamycin (MID), miocamycin (MCM), nafithromycin (ZWK), oleandomycin (OLE), pirlimycin (PRL), primycin (PRM), rokitamycin (ROK), roxithromycin (RXT), solithromycin (SOL), spiramycin (SPI), telithromycin (TLT), tildipirosin (TIP), tilmicosin (TIL), troleandomycin (TRL), tulathromycin (TUL), tylosin (TYL), and tylvalosin (TYL1)
\item \code{\link[=nitrofurans]{nitrofurans()}} can select: \cr furazidin (FUR), furazolidone (FRZ), nifurtoinol (NFR), nitrofurantoin (NIT), and nitrofurazone (NIZ)
\item \code{\link[=oxazolidinones]{oxazolidinones()}} can select: \cr cadazolid (CDZ), cycloserine (CYC), linezolid (LNZ), tedizolid (TZD), and thiacetazone (THA)
\item \code{\link[=penicillins]{penicillins()}} can select: \cr amoxicillin (AMX), amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin (AMP), ampicillin/sulbactam (SAM), apalcillin (APL), aspoxicillin (APX), avibactam (AVB), azidocillin (AZD), azlocillin (AZL), aztreonam (ATM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), bacampicillin (BAM), benzathine benzylpenicillin (BNB), benzathine phenoxymethylpenicillin (BNP), benzylpenicillin (PEN), carbenicillin (CRB), carindacillin (CRN), cefepime/nacubactam (FNC), ciclacillin (CIC), clometocillin (CLM), cloxacillin (CLO), dicloxacillin (DIC), epicillin (EPC), flucloxacillin (FLC), hetacillin (HET), lenampicillin (LEN), mecillinam (MEC), metampicillin (MTM), meticillin (MET), mezlocillin (MEZ), mezlocillin/sulbactam (MSU), nacubactam (NAC), nafcillin (NAF), oxacillin (OXA), penamecillin (PNM), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), pheneticillin (PHE), phenoxymethylpenicillin (PHN), piperacillin (PIP), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), piridicillin (PRC), pivampicillin (PVM), pivmecillinam (PME), procaine benzylpenicillin (PRB), propicillin (PRP), sarmoxicillin (SRX), sulbactam (SUL), sulbenicillin (SBC), sultamicillin (SLT6), talampicillin (TAL), tazobactam (TAZ), temocillin (TEM), ticarcillin (TIC), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=phenicols]{phenicols()}} can select: \cr chloramphenicol (CHL), florfenicol (FLR), and thiamphenicol (THI)
\item \code{\link[=polymyxins]{polymyxins()}} can select: \cr colistin (COL), polymyxin B (PLB), and polymyxin B/polysorbate 80 (POP)
\item \code{\link[=quinolones]{quinolones()}} can select: \cr besifloxacin (BES), cinoxacin (CIN), ciprofloxacin (CIP), ciprofloxacin/metronidazole (CIM), ciprofloxacin/ornidazole (CIO), ciprofloxacin/tinidazole (CIT), clinafloxacin (CLX), danofloxacin (DAN), delafloxacin (DFX), difloxacin (DIF), enoxacin (ENX), enrofloxacin (ENR), finafloxacin (FIN), fleroxacin (FLE), flumequine (FLM), garenoxacin (GRN), gatifloxacin (GAT), gemifloxacin (GEM), grepafloxacin (GRX), lascufloxacin (LSC), levofloxacin (LVX), levonadifloxacin (LND), lomefloxacin (LOM), marbofloxacin (MAR), metioxate (MXT), miloxacin (MIL), moxifloxacin (MFX), nadifloxacin (NAD), nalidixic acid (NAL), nemonoxacin (NEM), nifuroquine (NIF), nitroxoline (NTR), norfloxacin (NOR), ofloxacin (OFX), orbifloxacin (ORB), oxolinic acid (OXO), pazufloxacin (PAZ), pefloxacin (PEF), pipemidic acid (PPA), piromidic acid (PIR), pradofloxacin (PRA), premafloxacin (PRX), prulifloxacin (PRU), rosoxacin (ROS), rufloxacin (RFL), sarafloxacin (SAR), sitafloxacin (SIT), sparfloxacin (SPX), temafloxacin (TMX), tilbroquinol (TBQ), tioxacin (TXC), tosufloxacin (TFX), and trovafloxacin (TVA)
\item \code{\link[=rifamycins]{rifamycins()}} can select: \cr rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), and rifapentine (RFP)
\item \code{\link[=streptogramins]{streptogramins()}} can select: \cr pristinamycin (PRI) and quinupristin/dalfopristin (QDA)
\item \code{\link[=tetracyclines]{tetracyclines()}} can select: \cr cetocycline (CTO), chlortetracycline (CTE), clomocycline (CLM1), demeclocycline (DEM), doxycycline (DOX), eravacycline (ERV), lymecycline (LYM), metacycline (MTC), minocycline (MNO), omadacycline (OMC), oxytetracycline (OXY), penimepicycline (PNM1), rolitetracycline (RLT), sarecycline (SRC), tetracycline (TCY), and tigecycline (TGC)
\item \code{\link[=trimethoprims]{trimethoprims()}} can select: \cr brodimoprim (BDP), sulfadiazine (SDI), sulfadiazine/tetroxoprim (SLT), sulfadiazine/trimethoprim (SLT1), sulfadimethoxine (SUD), sulfadimidine (SDM), sulfadimidine/trimethoprim (SLT2), sulfafurazole (SLF), sulfaisodimidine (SLF1), sulfalene (SLF2), sulfamazone (SZO), sulfamerazine (SLF3), sulfamerazine/trimethoprim (SLT3), sulfamethizole (SLF4), sulfamethoxazole (SMX), sulfamethoxypyridazine (SLF5), sulfametomidine (SLF6), sulfametoxydiazine (SLF7), sulfametrole/trimethoprim (SLT4), sulfamoxole (SLF8), sulfamoxole/trimethoprim (SLT5), sulfanilamide (SLF9), sulfaperin (SLF10), sulfaphenazole (SLF11), sulfapyridine (SLF12), sulfathiazole (SUT), sulfathiourea (SLF13), trimethoprim (TMP), and trimethoprim/sulfamethoxazole (SXT)
\item \code{\link[=ureidopenicillins]{ureidopenicillins()}} can select: \cr azlocillin (AZL), mezlocillin (MEZ), piperacillin (PIP), and piperacillin/tazobactam (TZP)
}
}
\section{Reference Data Publicly Available}{
All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{
# `example_isolates` is a data set available in the AMR package.
# See ?example_isolates.
example_isolates
# you can use the selectors separately to retrieve all possible antimicrobials:
carbapenems()
# Though they are primarily intended to use for selections and filters.
# Examples sections below are split into 'dplyr', 'base R', and 'data.table':
\donttest{
\dontrun{
# dplyr -------------------------------------------------------------------
library(dplyr, warn.conflicts = FALSE)
example_isolates \%>\% select(carbapenems())
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates \%>\% select(mo, aminoglycosides())
# you can combine selectors like you are used with tidyverse
# e.g., for betalactams, but not the ones with an enzyme inhibitor:
example_isolates \%>\% select(betalactams(), -betalactams_with_inhibitor())
# select only antibiotic columns with DDDs for oral treatment
example_isolates \%>\% select(administrable_per_os())
# get AMR for all aminoglycosides e.g., per ward:
example_isolates \%>\%
group_by(ward) \%>\%
summarise(across(aminoglycosides(),
resistance))
# You can combine selectors with '&' to be more specific:
example_isolates \%>\%
select(penicillins() & administrable_per_os())
# get AMR for only drugs that matter - no intrinsic resistance:
example_isolates \%>\%
filter(mo_genus() \%in\% c("Escherichia", "Klebsiella")) \%>\%
group_by(ward) \%>\%
summarise_at(not_intrinsic_resistant(),
resistance)
# get susceptibility for antibiotics whose name contains "trim":
example_isolates \%>\%
filter(first_isolate()) \%>\%
group_by(ward) \%>\%
summarise(across(ab_selector(name \%like\% "trim"), susceptibility))
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
example_isolates \%>\%
select(carbapenems())
# this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
example_isolates \%>\%
select(mo, aminoglycosides())
# any() and all() work in dplyr's filter() too:
example_isolates \%>\%
filter(
any(aminoglycosides() == "R"),
all(cephalosporins_2nd() == "R")
)
# also works with c():
example_isolates \%>\%
filter(any(c(carbapenems(), aminoglycosides()) == "R"))
# not setting any/all will automatically apply all():
example_isolates \%>\%
filter(aminoglycosides() == "R")
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
example_isolates \%>\%
select(mo, ab_class("mycobact"))
# get bug/drug combinations for only glycopeptides in Gram-positives:
example_isolates \%>\%
filter(mo_is_gram_positive()) \%>\%
select(mo, glycopeptides()) \%>\%
bug_drug_combinations() \%>\%
format()
data.frame(
some_column = "some_value",
J01CA01 = "S"
) \%>\% # ATC code of ampicillin
select(penicillins()) # only the 'J01CA01' column will be selected
# with recent versions of dplyr, this is all equal:
x <- example_isolates[carbapenems() == "R", ]
y <- example_isolates \%>\% filter(carbapenems() == "R")
z <- example_isolates \%>\% filter(if_all(carbapenems(), ~ .x == "R"))
identical(x, y) && identical(y, z)
}
# base R ------------------------------------------------------------------
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
example_isolates[, carbapenems()]
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates[, c("mo", aminoglycosides())]
# select only antibiotic columns with DDDs for oral treatment
example_isolates[, administrable_per_os()]
# filter using any() or all()
example_isolates[any(carbapenems() == "R"), ]
subset(example_isolates, any(carbapenems() == "R"))
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
example_isolates[any(carbapenems()), ]
example_isolates[all(carbapenems()), ]
# filter with multiple antibiotic selectors using c()
example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
# filter + select in one go: get penicillins in carbapenem-resistant strains
example_isolates[any(carbapenems() == "R"), penicillins()]
# You can combine selectors with '&' to be more specific. For example,
# penicillins() would select benzylpenicillin ('peni G') and
# administrable_per_os() would select erythromycin. Yet, when combined these
# drugs are both omitted since benzylpenicillin is not administrable per os
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# ab_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antibiotic columns with an oral DDD
# of at least 1 gram:
example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
# data.table --------------------------------------------------------------
# data.table is supported as well, just use it in the same way as with
# base R, but add `with = FALSE` if using a single AB selector.
if (require("data.table")) {
dt <- as.data.table(example_isolates)
# this does not work, it returns column *names*
dt[, carbapenems()]
}
if (require("data.table")) {
# so `with = FALSE` is required
dt[, carbapenems(), with = FALSE]
}
# for multiple selections or AB selectors, `with = FALSE` is not needed:
if (require("data.table")) {
dt[, c("mo", aminoglycosides())]
}
if (require("data.table")) {
dt[, c(carbapenems(), aminoglycosides())]
}
# row filters are also supported:
if (require("data.table")) {
dt[any(carbapenems() == "S"), ]
}
if (require("data.table")) {
dt[any(carbapenems() == "S"), penicillins(), with = FALSE]
}
}
}
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antibiotics.Rd':
@ -2384,6 +2041,419 @@ antivirals
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antimicrobial_class_selectors.Rd':
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/amr_selectors.R
\name{antimicrobial_class_selectors}
\alias{antimicrobial_class_selectors}
\alias{amr_class}
\alias{amr_selector}
\alias{aminoglycosides}
\alias{aminopenicillins}
\alias{antifungals}
\alias{antimycobacterials}
\alias{betalactams}
\alias{betalactams_with_inhibitor}
\alias{carbapenems}
\alias{cephalosporins}
\alias{cephalosporins_1st}
\alias{cephalosporins_2nd}
\alias{cephalosporins_3rd}
\alias{cephalosporins_4th}
\alias{cephalosporins_5th}
\alias{fluoroquinolones}
\alias{glycopeptides}
\alias{lincosamides}
\alias{lipoglycopeptides}
\alias{macrolides}
\alias{nitrofurans}
\alias{oxazolidinones}
\alias{penicillins}
\alias{phenicols}
\alias{polymyxins}
\alias{quinolones}
\alias{rifamycins}
\alias{streptogramins}
\alias{tetracyclines}
\alias{trimethoprims}
\alias{ureidopenicillins}
\alias{administrable_per_os}
\alias{administrable_iv}
\alias{not_intrinsic_resistant}
\title{Antimicrobial Selectors}
\usage{
amr_class(
amr_class,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
amr_selector(
filter,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
aminoglycosides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
aminopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
antifungals(only_sir_columns = FALSE, return_all = TRUE, ...)
antimycobacterials(only_sir_columns = FALSE, return_all = TRUE, ...)
betalactams(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
betalactams_with_inhibitor(only_sir_columns = FALSE, return_all = TRUE, ...)
carbapenems(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
cephalosporins(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_1st(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_2nd(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_3rd(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_4th(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_5th(only_sir_columns = FALSE, return_all = TRUE, ...)
fluoroquinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
glycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
lincosamides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
lipoglycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
macrolides(only_sir_columns = FALSE, return_all = TRUE, ...)
nitrofurans(only_sir_columns = FALSE, return_all = TRUE, ...)
oxazolidinones(only_sir_columns = FALSE, return_all = TRUE, ...)
penicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
phenicols(only_sir_columns = FALSE, return_all = TRUE, ...)
polymyxins(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
quinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
rifamycins(only_sir_columns = FALSE, return_all = TRUE, ...)
streptogramins(only_sir_columns = FALSE, return_all = TRUE, ...)
tetracyclines(only_sir_columns = FALSE, return_all = TRUE, ...)
trimethoprims(only_sir_columns = FALSE, return_all = TRUE, ...)
ureidopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
administrable_per_os(only_sir_columns = FALSE, return_all = TRUE, ...)
administrable_iv(only_sir_columns = FALSE, return_all = TRUE, ...)
not_intrinsic_resistant(
only_sir_columns = FALSE,
col_mo = NULL,
version_expertrules = 3.3,
...
)
}
\arguments{
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
\item{only_sir_columns}{a \link{logical} to indicate whether only columns of class \code{sir} must be selected (default is \code{FALSE}), see \code{\link[=as.sir]{as.sir()}}}
\item{only_treatable}{a \link{logical} to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (default is \code{TRUE}), such as gentamicin-high (\code{GEH}) and imipenem/EDTA (\code{IPE})}
\item{return_all}{a \link{logical} to indicate whether all matched columns must be returned (default is \code{TRUE}). With \code{FALSE}, only the first of each unique antimicrobial will be returned, e.g. if both columns \code{"genta"} and \code{"gentamicin"} exist in the data, only the first hit for gentamicin will be returned.}
\item{...}{ignored, only in place to allow future extensions}
\item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{version_expertrules}{the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be "3.3", "3.2", or "3.1".}
}
\value{
When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"amr_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter.
}
\description{
These functions allow for filtering rows and selecting columns based on antimicrobial test results that are of a specific antimicrobial class or group, without the need to define the columns or antimicrobial abbreviations.
In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up using:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{library(dplyr)
my_data_with_all_these_columns \%>\%
select(cephalosporins())
}\if{html}{\out{</div>}}
}
\details{
These functions can be used in data set calls for selecting columns and filtering rows. They work with base \R, the Tidyverse, and \code{data.table}. They are heavily inspired by the \link[tidyselect:language]{Tidyverse selection helpers} such as \code{\link[tidyselect:everything]{everything()}}, but are not limited to \code{dplyr} verbs. Nonetheless, they are very convenient to use with \code{dplyr} functions such as \code{\link[dplyr:select]{select()}}, \code{\link[dplyr:filter]{filter()}} and \code{\link[dplyr:summarise]{summarise()}}, see \emph{Examples}.
All selectors can also be used in \code{tidymodels} packages such as \code{recipe} and \code{parsnip}. See for more info \href{https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html}{our tutorial} on using these AMR functions for predictive modelling.
All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antibiotics} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
The \code{\link[=amr_class]{amr_class()}} function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the \link{antibiotics} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
The \code{\link[=amr_selector]{amr_selector()}} function can be used to internally filter the \link{antibiotics} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antibiotics} data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antibiotics} data set.
The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function can be used to only select antimicrobials that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of \emph{E. coli} and \emph{K. pneumoniae} and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021) to determine intrinsic resistance, using the \code{\link[=eucast_rules]{eucast_rules()}} function internally. Because of this determination, this function is quite slow in terms of performance.
}
\section{Full list of supported (antimicrobial) classes}{
\itemize{
\item \code{\link[=aminoglycosides]{aminoglycosides()}} can select: \cr amikacin (AMK), amikacin/fosfomycin (AKF), apramycin (APR), arbekacin (ARB), astromicin (AST), bekanamycin (BEK), dibekacin (DKB), framycetin (FRM), gentamicin (GEN), gentamicin-high (GEH), habekacin (HAB), hygromycin (HYG), isepamicin (ISE), kanamycin (KAN), kanamycin-high (KAH), kanamycin/cephalexin (KAC), micronomicin (MCR), neomycin (NEO), netilmicin (NET), pentisomicin (PIM), plazomicin (PLZ), propikacin (PKA), ribostamycin (RST), sisomicin (SIS), streptoduocin (STR), streptomycin (STR1), streptomycin-high (STH), tobramycin (TOB), and tobramycin-high (TOH)
\item \code{\link[=aminopenicillins]{aminopenicillins()}} can select: \cr amoxicillin (AMX) and ampicillin (AMP)
\item \code{\link[=antifungals]{antifungals()}} can select: \cr amorolfine (AMO), amphotericin B (AMB), amphotericin B-high (AMH), anidulafungin (ANI), butoconazole (BUT), caspofungin (CAS), ciclopirox (CIX), clotrimazole (CTR), econazole (ECO), fluconazole (FLU), flucytosine (FCT), fosfluconazole (FFL), griseofulvin (GRI), hachimycin (HCH), ibrexafungerp (IBX), isavuconazole (ISV), isoconazole (ISO), itraconazole (ITR), ketoconazole (KET), manogepix (MGX), micafungin (MIF), miconazole (MCZ), nystatin (NYS), oteseconazole (OTE), pimaricin (PMR), posaconazole (POS), rezafungin (RZF), ribociclib (RBC), sulconazole (SUC), terbinafine (TRB), terconazole (TRC), and voriconazole (VOR)
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid (AMA), calcium aminosalicylate (CLA), capreomycin (CAP), clofazimine (CLF), delamanid (DLM), enviomycin (ENV), ethambutol (ETH), ethambutol/isoniazid (ETI), ethionamide (ETI1), isoniazid (INH), isoniazid/sulfamethoxazole/trimethoprim/pyridoxine (IST), morinamide (MRN), p-aminosalicylic acid (PAS), pretomanid (PMD), protionamide (PTH), pyrazinamide (PZA), rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), rifapentine (RFP), simvastatin/fenofibrate (SMF), sodium aminosalicylate (SDA), streptomycin/isoniazid (STI), terizidone (TRZ), thioacetazone (TAT), thioacetazone/isoniazid (THI1), tiocarlide (TCR), and viomycin (VIO)
\item \code{\link[=betalactams]{betalactams()}} can select: \cr amoxicillin (AMX), amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin (AMP), ampicillin/sulbactam (SAM), apalcillin (APL), aspoxicillin (APX), avibactam (AVB), azidocillin (AZD), azlocillin (AZL), aztreonam (ATM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), bacampicillin (BAM), benzathine benzylpenicillin (BNB), benzathine phenoxymethylpenicillin (BNP), benzylpenicillin (PEN), biapenem (BIA), carbenicillin (CRB), carindacillin (CRN), cefacetrile (CAC), cefaclor (CEC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefamandole (MAN), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefetamet (CAT), cefetamet pivoxil (CPI), cefetecol (CCL), cefetrizole (CZL), cefiderocol (FDC), cefixime (CFM), cefmenoxime (CMX), cefmetazole (CMZ), cefodizime (DIZ), cefonicid (CID), cefoperazone (CFP), cefoperazone/sulbactam (CSL), ceforanide (CND), cefoselis (CSE), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotetan (CTT), cefotiam (CTF), cefotiam hexetil (CHE), cefovecin (FOV), cefoxitin (FOX), cefoxitin screening (FOX1), cefozopran (ZOP), cefpimizole (CFZ), cefpiramide (CPM), cefpirome (CPO), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefprozil (CPR), cefquinome (CEQ), cefroxadine (CRD), cefsulodin (CFS), cefsumide (CSU), ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftezole (CTL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), ceftolozane/tazobactam (CZT), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), cefuroxime (CXM), cefuroxime axetil (CXA), cephradine (CED), ciclacillin (CIC), clometocillin (CLM), cloxacillin (CLO), dicloxacillin (DIC), doripenem (DOR), epicillin (EPC), ertapenem (ETP), flucloxacillin (FLC), hetacillin (HET), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), latamoxef (LTM), lenampicillin (LEN), loracarbef (LOR), mecillinam (MEC), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), metampicillin (MTM), meticillin (MET), mezlocillin (MEZ), mezlocillin/sulbactam (MSU), nacubactam (NAC), nafcillin (NAF), oxacillin (OXA), panipenem (PAN), penamecillin (PNM), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), pheneticillin (PHE), phenoxymethylpenicillin (PHN), piperacillin (PIP), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), piridicillin (PRC), pivampicillin (PVM), pivmecillinam (PME), procaine benzylpenicillin (PRB), propicillin (PRP), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), sarmoxicillin (SRX), sulbactam (SUL), sulbenicillin (SBC), sultamicillin (SLT6), talampicillin (TAL), tazobactam (TAZ), tebipenem (TBP), temocillin (TEM), ticarcillin (TIC), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=betalactams_with_inhibitor]{betalactams_with_inhibitor()}} can select: \cr amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin/sulbactam (SAM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), cefepime/clavulanic acid (CPC), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefoperazone/sulbactam (CSL), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefpodoxime/clavulanic acid (CDC), ceftaroline/avibactam (CPA), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), ceftolozane/tazobactam (CZT), ceftriaxone/beta-lactamase inhibitor (CEB), imipenem/relebactam (IMR), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), mezlocillin/sulbactam (MSU), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=carbapenems]{carbapenems()}} can select: \cr biapenem (BIA), doripenem (DOR), ertapenem (ETP), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), panipenem (PAN), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), and tebipenem (TBP)
\item \code{\link[=cephalosporins]{cephalosporins()}} can select: \cr cefacetrile (CAC), cefaclor (CEC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefamandole (MAN), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/tazobactam (FPT), cefetamet (CAT), cefetamet pivoxil (CPI), cefetecol (CCL), cefetrizole (CZL), cefiderocol (FDC), cefixime (CFM), cefmenoxime (CMX), cefmetazole (CMZ), cefodizime (DIZ), cefonicid (CID), cefoperazone (CFP), cefoperazone/sulbactam (CSL), ceforanide (CND), cefoselis (CSE), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotetan (CTT), cefotiam (CTF), cefotiam hexetil (CHE), cefovecin (FOV), cefoxitin (FOX), cefoxitin screening (FOX1), cefozopran (ZOP), cefpimizole (CFZ), cefpiramide (CPM), cefpirome (CPO), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefprozil (CPR), cefquinome (CEQ), cefroxadine (CRD), cefsulodin (CFS), cefsumide (CSU), ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftezole (CTL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), ceftolozane/tazobactam (CZT), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), cefuroxime (CXM), cefuroxime axetil (CXA), cephradine (CED), latamoxef (LTM), and loracarbef (LOR)
\item \code{\link[=cephalosporins_1st]{cephalosporins_1st()}} can select: \cr cefacetrile (CAC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefroxadine (CRD), ceftezole (CTL), and cephradine (CED)
\item \code{\link[=cephalosporins_2nd]{cephalosporins_2nd()}} can select: \cr cefaclor (CEC), cefamandole (MAN), cefmetazole (CMZ), cefonicid (CID), ceforanide (CND), cefotetan (CTT), cefotiam (CTF), cefoxitin (FOX), cefoxitin screening (FOX1), cefprozil (CPR), cefuroxime (CXM), cefuroxime axetil (CXA), and loracarbef (LOR)
\item \code{\link[=cephalosporins_3rd]{cephalosporins_3rd()}} can select: \cr cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefetamet (CAT), cefetamet pivoxil (CPI), cefixime (CFM), cefmenoxime (CMX), cefodizime (DIZ), cefoperazone (CFP), cefoperazone/sulbactam (CSL), cefotaxime (CTX), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotiam hexetil (CHE), cefovecin (FOV), cefpimizole (CFZ), cefpiramide (CPM), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefsulodin (CFS), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), and latamoxef (LTM)
\item \code{\link[=cephalosporins_4th]{cephalosporins_4th()}} can select: \cr cefepime (FEP), cefepime/clavulanic acid (CPC), cefepime/tazobactam (FPT), cefetecol (CCL), cefoselis (CSE), cefozopran (ZOP), cefpirome (CPO), and cefquinome (CEQ)
\item \code{\link[=cephalosporins_5th]{cephalosporins_5th()}} can select: \cr ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), and ceftolozane/tazobactam (CZT)
\item \code{\link[=fluoroquinolones]{fluoroquinolones()}} can select: \cr besifloxacin (BES), ciprofloxacin (CIP), clinafloxacin (CLX), danofloxacin (DAN), delafloxacin (DFX), difloxacin (DIF), enoxacin (ENX), enrofloxacin (ENR), finafloxacin (FIN), fleroxacin (FLE), garenoxacin (GRN), gatifloxacin (GAT), gemifloxacin (GEM), grepafloxacin (GRX), lascufloxacin (LSC), levofloxacin (LVX), levonadifloxacin (LND), lomefloxacin (LOM), marbofloxacin (MAR), metioxate (MXT), miloxacin (MIL), moxifloxacin (MFX), nadifloxacin (NAD), nifuroquine (NIF), norfloxacin (NOR), ofloxacin (OFX), orbifloxacin (ORB), pazufloxacin (PAZ), pefloxacin (PEF), pradofloxacin (PRA), premafloxacin (PRX), prulifloxacin (PRU), rufloxacin (RFL), sarafloxacin (SAR), sitafloxacin (SIT), sparfloxacin (SPX), temafloxacin (TMX), tilbroquinol (TBQ), tioxacin (TXC), tosufloxacin (TFX), and trovafloxacin (TVA)
\item \code{\link[=glycopeptides]{glycopeptides()}} can select: \cr avoparcin (AVO), dalbavancin (DAL), norvancomycin (NVA), oritavancin (ORI), ramoplanin (RAM), teicoplanin (TEC), teicoplanin-macromethod (TCM), telavancin (TLV), vancomycin (VAN), and vancomycin-macromethod (VAM)
\item \code{\link[=lincosamides]{lincosamides()}} can select: \cr acetylmidecamycin (ACM), acetylspiramycin (ASP), clindamycin (CLI), clindamycin inducible screening (CLI1), gamithromycin (GAM), kitasamycin (KIT), lincomycin (LIN), meleumycin (MEL), nafithromycin (ZWK), pirlimycin (PRL), primycin (PRM), solithromycin (SOL), tildipirosin (TIP), tilmicosin (TIL), tulathromycin (TUL), tylosin (TYL), and tylvalosin (TYL1)
\item \code{\link[=lipoglycopeptides]{lipoglycopeptides()}} can select: \cr dalbavancin (DAL), oritavancin (ORI), and telavancin (TLV)
\item \code{\link[=macrolides]{macrolides()}} can select: \cr acetylmidecamycin (ACM), acetylspiramycin (ASP), azithromycin (AZM), clarithromycin (CLR), dirithromycin (DIR), erythromycin (ERY), flurithromycin (FLR1), gamithromycin (GAM), josamycin (JOS), kitasamycin (KIT), meleumycin (MEL), midecamycin (MID), miocamycin (MCM), nafithromycin (ZWK), oleandomycin (OLE), pirlimycin (PRL), primycin (PRM), rokitamycin (ROK), roxithromycin (RXT), solithromycin (SOL), spiramycin (SPI), telithromycin (TLT), tildipirosin (TIP), tilmicosin (TIL), troleandomycin (TRL), tulathromycin (TUL), tylosin (TYL), and tylvalosin (TYL1)
\item \code{\link[=nitrofurans]{nitrofurans()}} can select: \cr furazidin (FUR), furazolidone (FRZ), nifurtoinol (NFR), nitrofurantoin (NIT), and nitrofurazone (NIZ)
\item \code{\link[=oxazolidinones]{oxazolidinones()}} can select: \cr cadazolid (CDZ), cycloserine (CYC), linezolid (LNZ), tedizolid (TZD), and thiacetazone (THA)
\item \code{\link[=penicillins]{penicillins()}} can select: \cr amoxicillin (AMX), amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin (AMP), ampicillin/sulbactam (SAM), apalcillin (APL), aspoxicillin (APX), avibactam (AVB), azidocillin (AZD), azlocillin (AZL), aztreonam (ATM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), bacampicillin (BAM), benzathine benzylpenicillin (BNB), benzathine phenoxymethylpenicillin (BNP), benzylpenicillin (PEN), carbenicillin (CRB), carindacillin (CRN), cefepime/nacubactam (FNC), ciclacillin (CIC), clometocillin (CLM), cloxacillin (CLO), dicloxacillin (DIC), epicillin (EPC), flucloxacillin (FLC), hetacillin (HET), lenampicillin (LEN), mecillinam (MEC), metampicillin (MTM), meticillin (MET), mezlocillin (MEZ), mezlocillin/sulbactam (MSU), nacubactam (NAC), nafcillin (NAF), oxacillin (OXA), penamecillin (PNM), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), pheneticillin (PHE), phenoxymethylpenicillin (PHN), piperacillin (PIP), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), piridicillin (PRC), pivampicillin (PVM), pivmecillinam (PME), procaine benzylpenicillin (PRB), propicillin (PRP), sarmoxicillin (SRX), sulbactam (SUL), sulbenicillin (SBC), sultamicillin (SLT6), talampicillin (TAL), tazobactam (TAZ), temocillin (TEM), ticarcillin (TIC), and ticarcillin/clavulanic acid (TCC)
\item \code{\link[=phenicols]{phenicols()}} can select: \cr chloramphenicol (CHL), florfenicol (FLR), and thiamphenicol (THI)
\item \code{\link[=polymyxins]{polymyxins()}} can select: \cr colistin (COL), polymyxin B (PLB), and polymyxin B/polysorbate 80 (POP)
\item \code{\link[=quinolones]{quinolones()}} can select: \cr besifloxacin (BES), cinoxacin (CIN), ciprofloxacin (CIP), ciprofloxacin/metronidazole (CIM), ciprofloxacin/ornidazole (CIO), ciprofloxacin/tinidazole (CIT), clinafloxacin (CLX), danofloxacin (DAN), delafloxacin (DFX), difloxacin (DIF), enoxacin (ENX), enrofloxacin (ENR), finafloxacin (FIN), fleroxacin (FLE), flumequine (FLM), garenoxacin (GRN), gatifloxacin (GAT), gemifloxacin (GEM), grepafloxacin (GRX), lascufloxacin (LSC), levofloxacin (LVX), levonadifloxacin (LND), lomefloxacin (LOM), marbofloxacin (MAR), metioxate (MXT), miloxacin (MIL), moxifloxacin (MFX), nadifloxacin (NAD), nalidixic acid (NAL), nemonoxacin (NEM), nifuroquine (NIF), nitroxoline (NTR), norfloxacin (NOR), ofloxacin (OFX), orbifloxacin (ORB), oxolinic acid (OXO), pazufloxacin (PAZ), pefloxacin (PEF), pipemidic acid (PPA), piromidic acid (PIR), pradofloxacin (PRA), premafloxacin (PRX), prulifloxacin (PRU), rosoxacin (ROS), rufloxacin (RFL), sarafloxacin (SAR), sitafloxacin (SIT), sparfloxacin (SPX), temafloxacin (TMX), tilbroquinol (TBQ), tioxacin (TXC), tosufloxacin (TFX), and trovafloxacin (TVA)
\item \code{\link[=rifamycins]{rifamycins()}} can select: \cr rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), and rifapentine (RFP)
\item \code{\link[=streptogramins]{streptogramins()}} can select: \cr pristinamycin (PRI) and quinupristin/dalfopristin (QDA)
\item \code{\link[=tetracyclines]{tetracyclines()}} can select: \cr cetocycline (CTO), chlortetracycline (CTE), clomocycline (CLM1), demeclocycline (DEM), doxycycline (DOX), eravacycline (ERV), lymecycline (LYM), metacycline (MTC), minocycline (MNO), omadacycline (OMC), oxytetracycline (OXY), penimepicycline (PNM1), rolitetracycline (RLT), sarecycline (SRC), tetracycline (TCY), and tigecycline (TGC)
\item \code{\link[=trimethoprims]{trimethoprims()}} can select: \cr brodimoprim (BDP), sulfadiazine (SDI), sulfadiazine/tetroxoprim (SLT), sulfadiazine/trimethoprim (SLT1), sulfadimethoxine (SUD), sulfadimidine (SDM), sulfadimidine/trimethoprim (SLT2), sulfafurazole (SLF), sulfaisodimidine (SLF1), sulfalene (SLF2), sulfamazone (SZO), sulfamerazine (SLF3), sulfamerazine/trimethoprim (SLT3), sulfamethizole (SLF4), sulfamethoxazole (SMX), sulfamethoxypyridazine (SLF5), sulfametomidine (SLF6), sulfametoxydiazine (SLF7), sulfametrole/trimethoprim (SLT4), sulfamoxole (SLF8), sulfamoxole/trimethoprim (SLT5), sulfanilamide (SLF9), sulfaperin (SLF10), sulfaphenazole (SLF11), sulfapyridine (SLF12), sulfathiazole (SUT), sulfathiourea (SLF13), trimethoprim (TMP), and trimethoprim/sulfamethoxazole (SXT)
\item \code{\link[=ureidopenicillins]{ureidopenicillins()}} can select: \cr azlocillin (AZL), mezlocillin (MEZ), piperacillin (PIP), and piperacillin/tazobactam (TZP)
}
}
\section{Reference Data Publicly Available}{
All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{
# `example_isolates` is a data set available in the AMR package.
# See ?example_isolates.
example_isolates
# you can use the selectors separately to retrieve all possible antimicrobials:
carbapenems()
# Though they are primarily intended to use for selections and filters.
# Examples sections below are split into 'dplyr', 'base R', and 'data.table':
\donttest{
\dontrun{
# dplyr -------------------------------------------------------------------
library(dplyr, warn.conflicts = FALSE)
example_isolates \%>\% select(carbapenems())
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates \%>\% select(mo, aminoglycosides())
# you can combine selectors like you are used with tidyverse
# e.g., for betalactams, but not the ones with an enzyme inhibitor:
example_isolates \%>\% select(betalactams(), -betalactams_with_inhibitor())
# select only antimicrobials with DDDs for oral treatment
example_isolates \%>\% select(administrable_per_os())
# get AMR for all aminoglycosides e.g., per ward:
example_isolates \%>\%
group_by(ward) \%>\%
summarise(across(aminoglycosides(),
resistance))
# You can combine selectors with '&' to be more specific:
example_isolates \%>\%
select(penicillins() & administrable_per_os())
# get AMR for only drugs that matter - no intrinsic resistance:
example_isolates \%>\%
filter(mo_genus() \%in\% c("Escherichia", "Klebsiella")) \%>\%
group_by(ward) \%>\%
summarise_at(not_intrinsic_resistant(),
resistance)
# get susceptibility for antimicrobials whose name contains "trim":
example_isolates \%>\%
filter(first_isolate()) \%>\%
group_by(ward) \%>\%
summarise(across(amr_selector(name \%like\% "trim"), susceptibility))
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
example_isolates \%>\%
select(carbapenems())
# this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
example_isolates \%>\%
select(mo, aminoglycosides())
# any() and all() work in dplyr's filter() too:
example_isolates \%>\%
filter(
any(aminoglycosides() == "R"),
all(cephalosporins_2nd() == "R")
)
# also works with c():
example_isolates \%>\%
filter(any(c(carbapenems(), aminoglycosides()) == "R"))
# not setting any/all will automatically apply all():
example_isolates \%>\%
filter(aminoglycosides() == "R")
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
example_isolates \%>\%
select(mo, amr_class("mycobact"))
# get bug/drug combinations for only glycopeptides in Gram-positives:
example_isolates \%>\%
filter(mo_is_gram_positive()) \%>\%
select(mo, glycopeptides()) \%>\%
bug_drug_combinations() \%>\%
format()
data.frame(
some_column = "some_value",
J01CA01 = "S"
) \%>\% # ATC code of ampicillin
select(penicillins()) # only the 'J01CA01' column will be selected
# with recent versions of dplyr, this is all equal:
x <- example_isolates[carbapenems() == "R", ]
y <- example_isolates \%>\% filter(carbapenems() == "R")
z <- example_isolates \%>\% filter(if_all(carbapenems(), ~ .x == "R"))
identical(x, y) && identical(y, z)
}
# base R ------------------------------------------------------------------
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
example_isolates[, carbapenems()]
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates[, c("mo", aminoglycosides())]
# select only antimicrobials with DDDs for oral treatment
example_isolates[, administrable_per_os()]
# filter using any() or all()
example_isolates[any(carbapenems() == "R"), ]
subset(example_isolates, any(carbapenems() == "R"))
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
example_isolates[any(carbapenems()), ]
example_isolates[all(carbapenems()), ]
# filter with multiple antimicrobial selectors using c()
example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
# filter + select in one go: get penicillins in carbapenem-resistant strains
example_isolates[any(carbapenems() == "R"), penicillins()]
# You can combine selectors with '&' to be more specific. For example,
# penicillins() would select benzylpenicillin ('peni G') and
# administrable_per_os() would select erythromycin. Yet, when combined these
# drugs are both omitted since benzylpenicillin is not administrable per os
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# amr_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antimicrobials with an oral DDD
# of at least 1 gram:
example_isolates[, amr_selector(oral_ddd > 1 & oral_units == "g")]
# data.table --------------------------------------------------------------
# data.table is supported as well, just use it in the same way as with
# base R, but add `with = FALSE` if using a single AB selector.
if (require("data.table")) {
dt <- as.data.table(example_isolates)
# this does not work, it returns column *names*
dt[, carbapenems()]
}
if (require("data.table")) {
# so `with = FALSE` is required
dt[, carbapenems(), with = FALSE]
}
# for multiple selections or AB selectors, `with = FALSE` is not needed:
if (require("data.table")) {
dt[, c("mo", aminoglycosides())]
}
if (require("data.table")) {
dt[, c(carbapenems(), aminoglycosides())]
}
# row filters are also supported:
if (require("data.table")) {
dt[any(carbapenems() == "S"), ]
}
if (require("data.table")) {
dt[any(carbapenems() == "S"), penicillins(), with = FALSE]
}
}
}
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/as.ab.Rd':
@ -6340,7 +6410,7 @@ amr_distance_from_row(amr_distance, row)
\arguments{
\item{x}{a vector of class \link[=as.sir]{sir}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes}
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}}
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=amr_selector]{antimicrobial selectors}}
\item{combine_SI}{a \link{logical} to indicate whether all values of S, SDD, and I must be merged into one, so the input only consists of S+I vs. R (susceptible vs. resistant) - the default is \code{TRUE}}
@ -7256,9 +7326,9 @@ Imagine this data on a sheet of an Excel file. The first column contains the org
4 | | |
}\if{html}{\out{</div>}}
We save it as \code{"home/me/ourcodes.xlsx"}. Now we have to set it as a source:
We save it as \code{"/Users/me/Documents/ourcodes.xlsx"}. Now we have to set it as a source:
\if{html}{\out{<div class="sourceCode">}}\preformatted{set_mo_source("home/me/ourcodes.xlsx")
\if{html}{\out{<div class="sourceCode">}}\preformatted{set_mo_source("/Users/me/Documents/ourcodes.xlsx")
#> NOTE: Created mo_source file '/Users/me/mo_source.rds' (0.3 kB) from
#> '/Users/me/Documents/ourcodes.xlsx' (9 kB), columns
#> "Organisation XYZ" and "mo"
@ -7949,7 +8019,7 @@ if (require("dplyr")) {
)
}
if (require("dplyr")) {
# scoped dplyr verbs with antibiotic selectors
# scoped dplyr verbs with antimicrobial selectors
# (you could also use across() of course)
example_isolates \%>\%
group_by(ward) \%>\%

View File

@ -5,7 +5,7 @@
* Generates **antibiograms** - traditional, combined, syndromic, and even WISCA
* Provides the **full microbiological taxonomy** and extensive info on **all antimicrobial drugs**
* Applies all recent **CLSI** and **EUCAST** clinical and veterinary breakpoints for MICs, disk zones and ECOFFs
* Corrects for duplicate isolates, **calculates** and **predicts** AMR per antibiotic class
* Corrects for duplicate isolates, **calculates** and **predicts** AMR per antimicrobial class
* Integrates with **WHONET**, ATC, **EARS-Net**, PubChem, **LOINC**, **SNOMED CT**, and **NCBI**
* 100% free of costs and dependencies, highly suitable for places with **limited resources**
@ -40,7 +40,7 @@ With the help of contributors from all corners of the world, the `AMR` package i
#### Filtering and selecting data
One of the most powerful functions of this package, aside from calculating and plotting AMR, is selecting and filtering based on antibiotic columns. This can be done using the so-called [antibiotic class selectors](https://msberends.github.io/AMR/reference/antibiotic_class_selectors.html) that work in base R, `dplyr` and `data.table`:
One of the most powerful functions of this package, aside from calculating and plotting AMR, is selecting and filtering based on antimicrobial columns. This can be done using the so-called [antimicrobial class selectors](https://msberends.github.io/AMR/reference/antimicrobial_class_selectors.html), which work in base R, `dplyr` and `data.table`:
```r
# AMR works great with dplyr, but it's not required or neccesary
@ -52,7 +52,7 @@ example_isolates %>%
# filtering functions for microorganisms:
filter(mo_is_gram_negative(),
mo_is_intrinsic_resistant(ab = "cefotax")) %>%
# antibiotic selectors:
# antimicrobial selectors:
select(bacteria,
aminoglycosides(),
carbapenems())
@ -162,7 +162,7 @@ example_isolates %>%
|ICU | 0.290 |0.253-0.330 | 0.400 |0.353-0.449 |
|Outpatient | 0.200 |0.131-0.285 | 0.368 |0.254-0.493 |
Or use [antibiotic class selectors](https://msberends.github.io/AMR/reference/antibiotic_class_selectors.html) to select a series of antibiotic columns:
Or use [antimicrobial class selectors](https://msberends.github.io/AMR/reference/antimicrobial_class_selectors.html) to select a series of antibiotic columns:
```r
library(AMR)
@ -218,7 +218,7 @@ This package was intended as a comprehensive toolbox for integrated AMR data ana
* Calculating (empirical) susceptibility of both mono therapy and combination therapies ([tutorial](./articles/AMR.html))
* Predicting future antimicrobial resistance using regression models ([tutorial](./articles/resistance_predict.html))
* Getting properties for any microorganism (like Gram stain, species, genus or family) ([manual](./reference/mo_property.html))
* Getting properties for any antibiotic (like name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) ([manual](./reference/ab_property.html))
* Getting properties for any antimicrobial (like name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) ([manual](./reference/ab_property.html))
* Plotting antimicrobial resistance ([tutorial](./articles/AMR.html))
* Applying EUCAST expert rules ([manual](./reference/eucast_rules.html))
* Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code ([manual](./reference/mo_property.html))

View File

@ -97,9 +97,13 @@ x <- data.frame(
)
# should have the first hits
expect_identical(
colnames(x[, aminoglycosides()]),
colnames(x[, aminoglycosides(return_all = FALSE)]),
c("gen", "tobra")
)
expect_identical(
colnames(x[, aminoglycosides()]),
c("gen", "genta", "J01GB03", "tobra", "Tobracin")
)
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_equal(example_isolates %>% select(administrable_per_os() & penicillins()) %>% ncol(), 5, tolerance = 0.5)

16
man/AMR-deprecated.Rd Normal file
View File

@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zz_deprecated.R
\name{AMR-deprecated}
\alias{AMR-deprecated}
\alias{ab_class}
\alias{ab_selector}
\title{Deprecated Functions}
\usage{
ab_class(...)
ab_selector(...)
}
\description{
These functions are so-called '\link{Deprecated}'. \strong{They will be removed in a future version of this package.} Using these functions will give a warning with the name of the function it has been replaced by (if there is one).
}
\keyword{internal}

View File

@ -89,7 +89,7 @@ add_custom_antimicrobials(
ab_atc("Co-fluampicil")
ab_name("J01CR50")
# even antibiotic selectors work
# even antimicrobial selectors work
x <- data.frame(
random_column = "some value",
coflu = as.sir("S"),

View File

@ -47,7 +47,7 @@ antibiogram(
\arguments{
\item{x}{a \link{data.frame} containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})}
\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antibiotic_class_selectors]{antibiotic selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
\item{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
\item{mo_transform}{a character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.}

View File

@ -1,9 +1,9 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ab_selectors.R
\name{antibiotic_class_selectors}
\alias{antibiotic_class_selectors}
\alias{ab_class}
\alias{ab_selector}
% Please edit documentation in R/amr_selectors.R
\name{antimicrobial_class_selectors}
\alias{antimicrobial_class_selectors}
\alias{amr_class}
\alias{amr_selector}
\alias{aminoglycosides}
\alias{aminopenicillins}
\alias{antifungals}
@ -36,73 +36,110 @@
\alias{administrable_per_os}
\alias{administrable_iv}
\alias{not_intrinsic_resistant}
\title{Antibiotic Selectors}
\title{Antimicrobial Selectors}
\usage{
ab_class(ab_class, only_sir_columns = FALSE, only_treatable = TRUE, ...)
amr_class(
amr_class,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
ab_selector(filter, only_sir_columns = FALSE, only_treatable = TRUE, ...)
amr_selector(
filter,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
aminoglycosides(only_sir_columns = FALSE, only_treatable = TRUE, ...)
aminoglycosides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
aminopenicillins(only_sir_columns = FALSE, ...)
aminopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
antifungals(only_sir_columns = FALSE, ...)
antifungals(only_sir_columns = FALSE, return_all = TRUE, ...)
antimycobacterials(only_sir_columns = FALSE, ...)
antimycobacterials(only_sir_columns = FALSE, return_all = TRUE, ...)
betalactams(only_sir_columns = FALSE, only_treatable = TRUE, ...)
betalactams(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
betalactams_with_inhibitor(only_sir_columns = FALSE, ...)
betalactams_with_inhibitor(only_sir_columns = FALSE, return_all = TRUE, ...)
carbapenems(only_sir_columns = FALSE, only_treatable = TRUE, ...)
carbapenems(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
cephalosporins(only_sir_columns = FALSE, ...)
cephalosporins(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_1st(only_sir_columns = FALSE, ...)
cephalosporins_1st(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_2nd(only_sir_columns = FALSE, ...)
cephalosporins_2nd(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_3rd(only_sir_columns = FALSE, ...)
cephalosporins_3rd(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_4th(only_sir_columns = FALSE, ...)
cephalosporins_4th(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_5th(only_sir_columns = FALSE, ...)
cephalosporins_5th(only_sir_columns = FALSE, return_all = TRUE, ...)
fluoroquinolones(only_sir_columns = FALSE, ...)
fluoroquinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
glycopeptides(only_sir_columns = FALSE, ...)
glycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
lincosamides(only_sir_columns = FALSE, only_treatable = TRUE, ...)
lincosamides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
lipoglycopeptides(only_sir_columns = FALSE, ...)
lipoglycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
macrolides(only_sir_columns = FALSE, ...)
macrolides(only_sir_columns = FALSE, return_all = TRUE, ...)
nitrofurans(only_sir_columns = FALSE, ...)
nitrofurans(only_sir_columns = FALSE, return_all = TRUE, ...)
oxazolidinones(only_sir_columns = FALSE, ...)
oxazolidinones(only_sir_columns = FALSE, return_all = TRUE, ...)
penicillins(only_sir_columns = FALSE, ...)
penicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
phenicols(only_sir_columns = FALSE, ...)
phenicols(only_sir_columns = FALSE, return_all = TRUE, ...)
polymyxins(only_sir_columns = FALSE, only_treatable = TRUE, ...)
polymyxins(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
quinolones(only_sir_columns = FALSE, ...)
quinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
rifamycins(only_sir_columns = FALSE, ...)
rifamycins(only_sir_columns = FALSE, return_all = TRUE, ...)
streptogramins(only_sir_columns = FALSE, ...)
streptogramins(only_sir_columns = FALSE, return_all = TRUE, ...)
tetracyclines(only_sir_columns = FALSE, ...)
tetracyclines(only_sir_columns = FALSE, return_all = TRUE, ...)
trimethoprims(only_sir_columns = FALSE, ...)
trimethoprims(only_sir_columns = FALSE, return_all = TRUE, ...)
ureidopenicillins(only_sir_columns = FALSE, ...)
ureidopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
administrable_per_os(only_sir_columns = FALSE, ...)
administrable_per_os(only_sir_columns = FALSE, return_all = TRUE, ...)
administrable_iv(only_sir_columns = FALSE, ...)
administrable_iv(only_sir_columns = FALSE, return_all = TRUE, ...)
not_intrinsic_resistant(
only_sir_columns = FALSE,
@ -112,12 +149,14 @@ not_intrinsic_resistant(
)
}
\arguments{
\item{ab_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
\item{only_sir_columns}{a \link{logical} to indicate whether only columns of class \code{sir} must be selected (default is \code{FALSE}), see \code{\link[=as.sir]{as.sir()}}}
\item{only_treatable}{a \link{logical} to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (default is \code{TRUE}), such as gentamicin-high (\code{GEH}) and imipenem/EDTA (\code{IPE})}
\item{return_all}{a \link{logical} to indicate whether all matched columns must be returned (default is \code{TRUE}). With \code{FALSE}, only the first of each unique antimicrobial will be returned, e.g. if both columns \code{"genta"} and \code{"gentamicin"} exist in the data, only the first hit for gentamicin will be returned.}
\item{...}{ignored, only in place to allow future extensions}
\item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}}
@ -127,27 +166,34 @@ not_intrinsic_resistant(
\item{version_expertrules}{the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be "3.3", "3.2", or "3.1".}
}
\value{
When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"ab_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter.
When used inside selecting or filtering, this returns a \link{character} vector of column names, with additional class \code{"amr_selector"}. When used individually, this returns an \link[=as.ab]{'ab' vector} with all possible antimicrobials that the function would be able to select or filter.
}
\description{
These functions allow for filtering rows and selecting columns based on antibiotic test results that are of a specific antibiotic class or group (according to the \link{antibiotics} data set), without the need to define the columns or antibiotic abbreviations.
These functions allow for filtering rows and selecting columns based on antimicrobial test results that are of a specific antimicrobial class or group, without the need to define the columns or antimicrobial abbreviations.
In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up by \code{\link[=cephalosporins]{cephalosporins()}}.
In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "kefzol", "CZO" and "J01DB04" will all be picked up using:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{library(dplyr)
my_data_with_all_these_columns \%>\%
select(cephalosporins())
}\if{html}{\out{</div>}}
}
\details{
These functions can be used in data set calls for selecting columns and filtering rows. They work with base \R, the Tidyverse, and \code{data.table}. They are heavily inspired by the \link[tidyselect:language]{Tidyverse selection helpers} such as \code{\link[tidyselect:everything]{everything()}}, but are not limited to \code{dplyr} verbs. Nonetheless, they are very convenient to use with \code{dplyr} functions such as \code{\link[dplyr:select]{select()}}, \code{\link[dplyr:filter]{filter()}} and \code{\link[dplyr:summarise]{summarise()}}, see \emph{Examples}.
All columns in the data in which these functions are called will be searched for known antibiotic names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antibiotics} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
All selectors can also be used in \code{tidymodels} packages such as \code{recipe} and \code{parsnip}. See for more info \href{https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html}{our tutorial} on using these AMR functions for predictive modelling.
The \code{\link[=ab_class]{ab_class()}} function can be used to filter/select on a manually defined antibiotic class. It searches for results in the \link{antibiotics} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antibiotics} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
The \code{\link[=ab_selector]{ab_selector()}} function can be used to internally filter the \link{antibiotics} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=amr_class]{amr_class()}} function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the \link{antibiotics} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antibiotics} data set - antibiotic columns will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antibiotics} data set.
The \code{\link[=amr_selector]{amr_selector()}} function can be used to internally filter the \link{antibiotics} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of \emph{E. coli} and \emph{K. pneumoniae} and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021) to determine intrinsic resistance, using the \code{\link[=eucast_rules]{eucast_rules()}} function internally. Because of this determination, this function is quite slow in terms of performance.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antibiotics} data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antibiotics} data set.
The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function can be used to only select antimicrobials that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of \emph{E. coli} and \emph{K. pneumoniae} and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021) to determine intrinsic resistance, using the \code{\link[=eucast_rules]{eucast_rules()}} function internally. Because of this determination, this function is quite slow in terms of performance.
}
\section{Full list of supported (antibiotic) classes}{
\section{Full list of supported (antimicrobial) classes}{
\itemize{
\item \code{\link[=aminoglycosides]{aminoglycosides()}} can select: \cr amikacin (AMK), amikacin/fosfomycin (AKF), apramycin (APR), arbekacin (ARB), astromicin (AST), bekanamycin (BEK), dibekacin (DKB), framycetin (FRM), gentamicin (GEN), gentamicin-high (GEH), habekacin (HAB), hygromycin (HYG), isepamicin (ISE), kanamycin (KAN), kanamycin-high (KAH), kanamycin/cephalexin (KAC), micronomicin (MCR), neomycin (NEO), netilmicin (NET), pentisomicin (PIM), plazomicin (PLZ), propikacin (PKA), ribostamycin (RST), sisomicin (SIS), streptoduocin (STR), streptomycin (STR1), streptomycin-high (STH), tobramycin (TOB), and tobramycin-high (TOH)
@ -215,7 +261,7 @@ example_isolates \%>\% select(mo, aminoglycosides())
# e.g., for betalactams, but not the ones with an enzyme inhibitor:
example_isolates \%>\% select(betalactams(), -betalactams_with_inhibitor())
# select only antibiotic columns with DDDs for oral treatment
# select only antimicrobials with DDDs for oral treatment
example_isolates \%>\% select(administrable_per_os())
# get AMR for all aminoglycosides e.g., per ward:
@ -235,11 +281,11 @@ example_isolates \%>\%
summarise_at(not_intrinsic_resistant(),
resistance)
# get susceptibility for antibiotics whose name contains "trim":
# get susceptibility for antimicrobials whose name contains "trim":
example_isolates \%>\%
filter(first_isolate()) \%>\%
group_by(ward) \%>\%
summarise(across(ab_selector(name \%like\% "trim"), susceptibility))
summarise(across(amr_selector(name \%like\% "trim"), susceptibility))
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
example_isolates \%>\%
@ -266,7 +312,7 @@ example_isolates \%>\%
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
example_isolates \%>\%
select(mo, ab_class("mycobact"))
select(mo, amr_class("mycobact"))
# get bug/drug combinations for only glycopeptides in Gram-positives:
example_isolates \%>\%
@ -296,7 +342,7 @@ example_isolates[, carbapenems()]
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates[, c("mo", aminoglycosides())]
# select only antibiotic columns with DDDs for oral treatment
# select only antimicrobials with DDDs for oral treatment
example_isolates[, administrable_per_os()]
# filter using any() or all()
@ -307,7 +353,7 @@ subset(example_isolates, any(carbapenems() == "R"))
example_isolates[any(carbapenems()), ]
example_isolates[all(carbapenems()), ]
# filter with multiple antibiotic selectors using c()
# filter with multiple antimicrobial selectors using c()
example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
# filter + select in one go: get penicillins in carbapenem-resistant strains
@ -320,10 +366,10 @@ example_isolates[any(carbapenems() == "R"), penicillins()]
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# ab_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antibiotic columns with an oral DDD
# amr_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antimicrobials with an oral DDD
# of at least 1 gram:
example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
example_isolates[, amr_selector(oral_ddd > 1 & oral_units == "g")]
# data.table --------------------------------------------------------------

View File

@ -18,7 +18,7 @@ amr_distance_from_row(amr_distance, row)
\arguments{
\item{x}{a vector of class \link[=as.sir]{sir}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes}
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}}
\item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=amr_selector]{antimicrobial selectors}}
\item{combine_SI}{a \link{logical} to indicate whether all values of S, SDD, and I must be merged into one, so the input only consists of S+I vs. R (susceptible vs. resistant) - the default is \code{TRUE}}

View File

@ -47,9 +47,9 @@ Imagine this data on a sheet of an Excel file. The first column contains the org
4 | | |
}\if{html}{\out{</div>}}
We save it as \code{"home/me/ourcodes.xlsx"}. Now we have to set it as a source:
We save it as \code{"/Users/me/Documents/ourcodes.xlsx"}. Now we have to set it as a source:
\if{html}{\out{<div class="sourceCode">}}\preformatted{set_mo_source("home/me/ourcodes.xlsx")
\if{html}{\out{<div class="sourceCode">}}\preformatted{set_mo_source("/Users/me/Documents/ourcodes.xlsx")
#> NOTE: Created mo_source file '/Users/me/mo_source.rds' (0.3 kB) from
#> '/Users/me/Documents/ourcodes.xlsx' (9 kB), columns
#> "Organisation XYZ" and "mo"

View File

@ -213,7 +213,7 @@ if (require("dplyr")) {
)
}
if (require("dplyr")) {
# scoped dplyr verbs with antibiotic selectors
# scoped dplyr verbs with antimicrobial selectors
# (you could also use across() of course)
example_isolates \%>\%
group_by(ward) \%>\%