mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 08:32:04 +02:00
(v1.6.0.9048) ab selectors overhaul
This commit is contained in:
@ -6,6 +6,22 @@
|
||||
\alias{filter_first_weighted_isolate}
|
||||
\alias{key_antibiotics}
|
||||
\alias{key_antibiotics_equal}
|
||||
\alias{filter_ab_class}
|
||||
\alias{filter_aminoglycosides}
|
||||
\alias{filter_betalactams}
|
||||
\alias{filter_carbapenems}
|
||||
\alias{filter_cephalosporins}
|
||||
\alias{filter_1st_cephalosporins}
|
||||
\alias{filter_2nd_cephalosporins}
|
||||
\alias{filter_3rd_cephalosporins}
|
||||
\alias{filter_4th_cephalosporins}
|
||||
\alias{filter_5th_cephalosporins}
|
||||
\alias{filter_fluoroquinolones}
|
||||
\alias{filter_glycopeptides}
|
||||
\alias{filter_macrolides}
|
||||
\alias{filter_oxazolidinones}
|
||||
\alias{filter_penicillins}
|
||||
\alias{filter_tetracyclines}
|
||||
\title{Deprecated Functions}
|
||||
\usage{
|
||||
p_symbol(p, emptychar = " ")
|
||||
@ -53,9 +69,141 @@ key_antibiotics_equal(
|
||||
na.rm = TRUE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_ab_class(
|
||||
x,
|
||||
ab_class,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_aminoglycosides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_betalactams(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_carbapenems(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_1st_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_2nd_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_3rd_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_4th_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_5th_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_fluoroquinolones(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_glycopeptides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_macrolides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_oxazolidinones(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_penicillins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_tetracyclines(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
}
|
||||
\description{
|
||||
These functions are so-called '\link{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).
|
||||
These functions are so-called '\link{Deprecated}'. \strong{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).
|
||||
}
|
||||
\details{
|
||||
All antibiotic class selectors (such as \code{\link[=carbapenems]{carbapenems()}}, \code{\link[=aminoglycosides]{aminoglycosides()}}) can now be used for filtering as well, making all their accompanying \verb{filter_*()} functions redundant (such as \code{\link[=filter_carbapenems]{filter_carbapenems()}}, \code{\link[=filter_aminoglycosides]{filter_aminoglycosides()}}).
|
||||
}
|
||||
\section{Retired Lifecycle}{
|
||||
|
||||
|
@ -58,12 +58,14 @@ tetracyclines(only_rsi_columns = FALSE)
|
||||
\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()}}}
|
||||
}
|
||||
\description{
|
||||
These functions help to select the columns of antibiotics 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, "."), "")}}
|
||||
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, "."), "")}}
|
||||
}
|
||||
\details{
|
||||
\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, "."), "")}}
|
||||
|
||||
All columns 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.
|
||||
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.
|
||||
|
||||
The group of betalactams consists of all carbapenems, cephalosporins and penicillins.
|
||||
}
|
||||
@ -89,11 +91,31 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
|
||||
# `example_isolates` is a data set available in the AMR package.
|
||||
# See ?example_isolates.
|
||||
|
||||
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
|
||||
# Base R ------------------------------------------------------------------
|
||||
|
||||
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
|
||||
example_isolates[, carbapenems()]
|
||||
# this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
|
||||
|
||||
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
|
||||
example_isolates[, c("mo", aminoglycosides())]
|
||||
|
||||
# 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")) {
|
||||
|
||||
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
|
||||
@ -104,6 +126,20 @@ if (require("dplyr")) {
|
||||
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")
|
||||
#> i Assuming a filter on all 4 aminoglycosides.
|
||||
|
||||
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
|
||||
example_isolates \%>\%
|
||||
select(mo, ab_class("mycobact"))
|
||||
@ -122,12 +158,10 @@ if (require("dplyr")) {
|
||||
select(penicillins()) # only the 'J01CA01' column will be selected
|
||||
|
||||
|
||||
# with dplyr 1.0.0 and higher (that adds 'across()'), this is equal:
|
||||
# with dplyr 1.0.0 and higher (that adds 'across()'), this is all equal:
|
||||
# (though the row names on the first are more correct)
|
||||
example_isolates \%>\% filter_carbapenems("R", "all")
|
||||
example_isolates \%>\% filter(across(carbapenems(), ~. == "R"))
|
||||
example_isolates[carbapenems() == "R", ]
|
||||
example_isolates \%>\% filter(carbapenems() == "R")
|
||||
example_isolates \%>\% filter(across(carbapenems(), ~.x == "R"))
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[=filter_ab_class]{filter_ab_class()}} for the \code{filter()} equivalent.
|
||||
}
|
||||
|
@ -1,228 +0,0 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/filter_ab_class.R
|
||||
\name{filter_ab_class}
|
||||
\alias{filter_ab_class}
|
||||
\alias{filter_aminoglycosides}
|
||||
\alias{filter_betalactams}
|
||||
\alias{filter_carbapenems}
|
||||
\alias{filter_cephalosporins}
|
||||
\alias{filter_1st_cephalosporins}
|
||||
\alias{filter_2nd_cephalosporins}
|
||||
\alias{filter_3rd_cephalosporins}
|
||||
\alias{filter_4th_cephalosporins}
|
||||
\alias{filter_5th_cephalosporins}
|
||||
\alias{filter_fluoroquinolones}
|
||||
\alias{filter_glycopeptides}
|
||||
\alias{filter_macrolides}
|
||||
\alias{filter_oxazolidinones}
|
||||
\alias{filter_penicillins}
|
||||
\alias{filter_tetracyclines}
|
||||
\title{Filter Isolates on Result in Antimicrobial Class}
|
||||
\usage{
|
||||
filter_ab_class(
|
||||
x,
|
||||
ab_class,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_aminoglycosides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_betalactams(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_carbapenems(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_1st_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_2nd_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_3rd_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_4th_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_5th_cephalosporins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_fluoroquinolones(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_glycopeptides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_macrolides(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_oxazolidinones(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_penicillins(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
|
||||
filter_tetracyclines(
|
||||
x,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
only_rsi_columns = FALSE,
|
||||
...
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{a data set}
|
||||
|
||||
\item{ab_class}{an antimicrobial class, like \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{result}{an antibiotic result: S, I or R (or a combination of more of them)}
|
||||
|
||||
\item{scope}{the scope to check which variables to check, can be \code{"any"} (default) or \code{"all"}}
|
||||
|
||||
\item{only_rsi_columns}{a \link{logical} to indicate whether only columns must be included that were transformed to class \verb{<rsi>} (see \code{\link[=as.rsi]{as.rsi()}}) on beforehand (defaults to \code{FALSE})}
|
||||
|
||||
\item{...}{arguments passed on to \code{\link[=filter_ab_class]{filter_ab_class()}}}
|
||||
}
|
||||
\description{
|
||||
Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside, or to filter on carbapenem-resistant isolates without the need to specify the drugs.
|
||||
}
|
||||
\details{
|
||||
All columns of \code{x} will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g. \code{\link[=filter_aminoglycosides]{filter_aminoglycosides()}} will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
|
||||
|
||||
The group of betalactams consists of all carbapenems, cephalosporins and penicillins.
|
||||
}
|
||||
\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.
|
||||
}
|
||||
|
||||
\examples{
|
||||
x <- filter_carbapenems(example_isolates)
|
||||
\donttest{
|
||||
# base R filter options (requires R >= 3.2)
|
||||
example_isolates[filter_carbapenems(), ]
|
||||
example_isolates[which(filter_carbapenems() & mo_is_gram_negative()), ]
|
||||
|
||||
if (require("dplyr")) {
|
||||
|
||||
# filter on isolates that have any result for any aminoglycoside
|
||||
example_isolates \%>\% filter_aminoglycosides()
|
||||
example_isolates \%>\% filter_ab_class("aminoglycoside")
|
||||
|
||||
# this is essentially the same as (but without determination of column names):
|
||||
example_isolates \%>\%
|
||||
filter_at(.vars = vars(c("GEN", "TOB", "AMK", "KAN")),
|
||||
.vars_predicate = any_vars(. \%in\% c("S", "I", "R")))
|
||||
|
||||
|
||||
# filter on isolates that show resistance to ANY aminoglycoside
|
||||
example_isolates \%>\% filter_aminoglycosides("R", "any")
|
||||
|
||||
# filter on isolates that show resistance to ALL aminoglycosides
|
||||
example_isolates \%>\% filter_aminoglycosides("R", "all")
|
||||
|
||||
# filter on isolates that show resistance to
|
||||
# any aminoglycoside and any fluoroquinolone
|
||||
example_isolates \%>\%
|
||||
filter_aminoglycosides("R") \%>\%
|
||||
filter_fluoroquinolones("R")
|
||||
|
||||
# filter on isolates that show resistance to
|
||||
# all aminoglycosides and all fluoroquinolones
|
||||
example_isolates \%>\%
|
||||
filter_aminoglycosides("R", "all") \%>\%
|
||||
filter_fluoroquinolones("R", "all")
|
||||
|
||||
# with dplyr 1.0.0 and higher (that adds 'across()'), this is all equal:
|
||||
# (though the row names on the first are more correct)
|
||||
example_isolates \%>\% filter_carbapenems("R", "all")
|
||||
example_isolates \%>\% filter(across(carbapenems(), ~. == "R"))
|
||||
example_isolates \%>\% filter(across(carbapenems(), function(x) x == "R"))
|
||||
example_isolates \%>\% filter(filter_carbapenems("R", "all"))
|
||||
}
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[=antibiotic_class_selectors]{antibiotic_class_selectors()}} for the \code{select()} equivalent.
|
||||
}
|
Reference in New Issue
Block a user