AMR/man/antibiotic_class_selectors.Rd

168 lines
7.5 KiB
Plaintext
Raw Normal View History

2020-06-17 01:39:30 +02:00
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ab_class_selectors.R
\name{antibiotic_class_selectors}
\alias{antibiotic_class_selectors}
2020-06-17 15:14:37 +02:00
\alias{ab_class}
2020-06-17 01:39:30 +02:00
\alias{aminoglycosides}
2021-05-18 00:53:04 +02:00
\alias{betalactams}
2020-06-17 01:39:30 +02:00
\alias{carbapenems}
\alias{cephalosporins}
\alias{cephalosporins_1st}
\alias{cephalosporins_2nd}
\alias{cephalosporins_3rd}
\alias{cephalosporins_4th}
\alias{cephalosporins_5th}
\alias{fluoroquinolones}
\alias{glycopeptides}
\alias{macrolides}
\alias{oxazolidinones}
2020-06-17 01:39:30 +02:00
\alias{penicillins}
\alias{tetracyclines}
\title{Antibiotic Class Selectors}
2020-06-17 01:39:30 +02:00
\usage{
ab_class(ab_class, only_rsi_columns = FALSE)
2020-06-17 15:14:37 +02:00
aminoglycosides(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
2021-05-18 00:53:04 +02:00
betalactams(only_rsi_columns = FALSE)
carbapenems(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins_1st(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins_2nd(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins_3rd(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins_4th(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
cephalosporins_5th(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
fluoroquinolones(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
glycopeptides(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
macrolides(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
oxazolidinones(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
penicillins(only_rsi_columns = FALSE)
tetracyclines(only_rsi_columns = FALSE)
2020-06-17 01:39:30 +02:00
}
2020-06-17 15:14:37 +02:00
\arguments{
2021-05-23 23:11:16 +02:00
\item{ab_class}{an antimicrobial class, such as \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.}
2021-05-12 18:15:03 +02:00
\item{only_rsi_columns}{a \link{logical} to indicate whether only columns of class \verb{<rsi>} must be selected (defaults to \code{FALSE}), see \code{\link[=as.rsi]{as.rsi()}}}
2020-06-17 15:14:37 +02:00
}
2020-06-17 01:39:30 +02:00
\description{
2021-05-19 22:55:42 +02:00
These functions help to filter and select columns with antibiotic test results that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. \strong{\Sexpr{ifelse(as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.2, paste0("NOTE: THESE FUNCTIONS DO NOT WORK ON YOUR CURRENT R VERSION. These functions require R version 3.2 or later - you have ", R.version.string, "."), "")}}
2020-06-17 01:39:30 +02:00
}
\details{
2021-01-06 11:16:17 +01:00
\strong{\Sexpr{ifelse(as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.2, paste0("NOTE: THESE FUNCTIONS DO NOT WORK ON YOUR CURRENT R VERSION. These functions require R version 3.2 or later - you have ", R.version.string, "."), "")}}
2021-01-04 12:29:25 +01:00
2021-05-19 22:55:42 +02:00
These functions can be used in data set calls for selecting columns and filtering rows, see \emph{Examples}. They support base R, but work more convenient in dplyr functions such as \code{\link[dplyr:select]{select()}}, \code{\link[dplyr:filter]{filter()}} and \code{\link[dplyr:summarise]{summarise()}}.
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.) in the \link{antibiotics} data set. This means that a selector like e.g. \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
2021-05-18 00:53:04 +02:00
The group of betalactams consists of all carbapenems, cephalosporins and penicillins.
2020-06-17 01:39:30 +02:00
}
\section{Stable Lifecycle}{
\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr}
The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
}
\section{Reference Data Publicly Available}{
2020-08-26 16:13:40 +02:00
All reference data sets (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) in this \code{AMR} package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find \href{https://msberends.github.io/AMR/articles/datasets.html}{all download links on our website}, which is automatically updated with every code change.
}
\section{Read more on Our Website!}{
2020-08-21 11:40:13 +02:00
On our website \url{https://msberends.github.io/AMR/} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR data analysis, the \href{https://msberends.github.io/AMR/reference/}{complete documentation of all functions} and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. As we would like to better understand the backgrounds and needs of our users, please \href{https://msberends.github.io/AMR/survey.html}{participate in our survey}!
2020-08-21 11:40:13 +02:00
}
2020-06-17 01:39:30 +02:00
\examples{
# `example_isolates` is a data set available in the AMR package.
2020-12-27 20:32:40 +01:00
# See ?example_isolates.
2021-05-19 22:55:42 +02:00
# Base R ------------------------------------------------------------------
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
example_isolates[, carbapenems()]
2021-05-19 22:55:42 +02:00
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
2020-12-27 20:32:40 +01:00
example_isolates[, c("mo", aminoglycosides())]
2021-05-19 22:55:42 +02:00
# 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 carbapenems-resistant strains
example_isolates[any(carbapenems() == "R"), penicillins()]
# dplyr -------------------------------------------------------------------
if (require("dplyr")) {
2020-06-17 01:39:30 +02:00
# 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())
2021-05-19 22:55:42 +02:00
# 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")
#> i Assuming a filter on all 4 aminoglycosides.
2020-06-17 15:14:37 +02:00
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
example_isolates \%>\%
select(mo, ab_class("mycobact"))
# get bug/drug combinations for only macrolides in Gram-positives:
example_isolates \%>\%
filter(mo_is_gram_positive()) \%>\%
2020-06-17 15:14:37 +02:00
select(mo, macrolides()) \%>\%
bug_drug_combinations() \%>\%
format()
2020-06-17 01:39:30 +02:00
data.frame(some_column = "some_value",
2020-06-17 01:39:30 +02:00
J01CA01 = "S") \%>\% # ATC code of ampicillin
select(penicillins()) # only the 'J01CA01' column will be selected
2020-12-27 23:19:41 +01:00
2021-05-19 22:55:42 +02:00
# with dplyr 1.0.0 and higher (that adds 'across()'), this is all equal:
2020-12-27 23:19:41 +01:00
# (though the row names on the first are more correct)
2021-05-19 22:55:42 +02:00
example_isolates[carbapenems() == "R", ]
example_isolates \%>\% filter(carbapenems() == "R")
example_isolates \%>\% filter(across(carbapenems(), ~.x == "R"))
2020-06-17 01:39:30 +02:00
}
}