(v1.2.0.9001) filter_ab_class() update

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-06-03 11:48:00 +02:00
parent 02d07b9fb3
commit 5dc4c96b7d
18 changed files with 159 additions and 77 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 1.2.0.9000
Date: 2020-06-02
Version: 1.2.0.9001
Date: 2020-06-03
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),

View File

@ -114,6 +114,7 @@ export(filter_first_weighted_isolate)
export(filter_fluoroquinolones)
export(filter_glycopeptides)
export(filter_macrolides)
export(filter_penicillins)
export(filter_tetracyclines)
export(first_isolate)
export(full_join_microorganisms)

View File

@ -1,9 +1,12 @@
# AMR 1.2.0.9000
## <small>Last updated: 02-Jun-2020</small>
# AMR 1.2.0.9001
## <small>Last updated: 03-Jun-2020</small>
### Changed
* Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded
* All `*_join_microorganisms()` functions now return the original data class (e.g. tibbles and data.tables)
* Fixed a bug where `as.ab()` would return an error on invalid input values
* Added function `filter_penicillins()` to filter isolates on a specific result in any column with a name in the antimicrobial 'penicillins' class (more specific: ATC subgroup *Beta-lactam antibacterials, penicillins*)
* Added official antimicrobial names to all `filter_ab_class()` functions, such as `filter_aminoglycosides()`
# AMR 1.2.0
@ -20,7 +23,7 @@
### Changed
* Taxonomy:
* Updated the taxonomy of microorganisms tot May 2020, using the Catalogue of Life (CoL), the Global Biodiversity Information Facility (GBIF) and the List of Prokaryotic names with Standing in Nomenclature (LPSN, hosted by DSMZ since February 2020). **Note:** a taxonomic update may always impact determination of first isolates (using `first_isolate()`), since some bacterial names might be renamed to other genera or other (sub)species. This is expected behaviour.
* Updated the taxonomy of microorganisms to May 2020, using the Catalogue of Life (CoL), the Global Biodiversity Information Facility (GBIF) and the List of Prokaryotic names with Standing in Nomenclature (LPSN, hosted by DSMZ since February 2020). **Note:** a taxonomic update may always impact determination of first isolates (using `first_isolate()`), since some bacterial names might be renamed to other genera or other (sub)species. This is expected behaviour.
* Removed the Catalogue of Life IDs (like 776351), since they now work with a species ID (hexadecimal string)
* EUCAST rules:
* The `eucast_rules()` function no longer applies "other" rules at default that are made available by this package (like setting ampicillin = R when ampicillin + enzyme inhibitor = R). The default input value for `rules` is now `c("breakpoints", "expert")` instead of `"all"`, but this can be changed by the user. To return to the old behaviour, set `options(AMR.eucast_rules = "all")`.

View File

@ -21,14 +21,14 @@
#' Filter isolates on result in antimicrobial class
#'
#' Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside.
#' 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.
#' @inheritSection lifecycle Stable lifecycle
#' @param x a data set
#' @param ab_class an antimicrobial class, like `"carbapenems"`, as can be found in [`antibiotics$group`][antibiotics]
#' @param result an antibiotic result: S, I or R (or a combination of more of them)
#' @param scope the scope to check which variables to check, can be `"any"` (default) or `"all"`
#' @param ... parameters passed on to `filter_at` from the `dplyr` package
#' @details The `group` column in [antibiotics] data set will be searched for `ab_class` (case-insensitive). If no results are found, the `atc_group1` and `atc_group2` columns will be searched. Next, `x` will be checked for column names with a value in any abbreviations, codes or official names found in the [antibiotics] data set.
#' @details The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched for the input given in `ab_class` (case-insensitive). Next, `x` will be checked for column names with a value in any abbreviation, code or official name found in the [antibiotics] data set.
#' @rdname filter_ab_class
#' @export
#' @examples
@ -36,6 +36,7 @@
#' library(dplyr)
#'
#' # filter on isolates that have any result for any aminoglycoside
#' example_isolates %>% filter_ab_class("aminoglycoside")
#' example_isolates %>% filter_aminoglycosides()
#'
#' # this is essentially the same as (but without determination of column names):
@ -45,7 +46,7 @@
#'
#'
#' # filter on isolates that show resistance to ANY aminoglycoside
#' example_isolates %>% filter_aminoglycosides("R")
#' example_isolates %>% filter_aminoglycosides("R", "any")
#'
#' # filter on isolates that show resistance to ALL aminoglycosides
#' example_isolates %>% filter_aminoglycosides("R", "all")
@ -76,13 +77,14 @@ filter_ab_class <- function(x,
# save to return later
x_class <- class(x)
x.bak <- x
x <- as.data.frame(x, stringsAsFactors = FALSE)
scope <- scope[1L]
if (is.null(result)) {
result <- c("S", "I", "R")
}
# make result = "SI" work too:
# make result = "SI" works too:
result <- unlist(strsplit(result, ""))
if (!all(result %in% c("S", "I", "R"))) {
@ -92,46 +94,62 @@ filter_ab_class <- function(x,
stop("`scope` must be one of: any, all", call. = FALSE)
}
# get only columns with class ab, mic or disk - those are AMR results
vars_df <- colnames(x)[sapply(x, function(y) is.rsi(y) | is.mic(y) | is.disk(y))]
vars_df_ab <- suppressWarnings(as.ab(vars_df))
# get the columns with a group names in the chosen ab class
vars_df <- vars_df[which(ab_group(vars_df_ab) %like% ab_class |
ab_atc_group1(vars_df_ab) %like% ab_class |
ab_atc_group2(vars_df_ab) %like% ab_class)]
ab_group <- find_ab_group(ab_class)
if (length(vars_df) > 0) {
if (length(result) == 1) {
operator <- " is "
} else {
operator <- " is one of "
}
if (scope == "any") {
scope_txt <- " or "
scope_fn <- any
} else {
scope_txt <- " and "
scope_fn <- all
if (length(vars_df) > 1) {
operator <- gsub("is", "are", operator)
}
}
if (length(vars_df) > 1) {
scope <- paste(scope, "of columns ")
} else {
scope <- "column "
}
message(font_blue(paste0("Filtering on ", ab_group, ": ", scope,
paste0(font_bold(paste0("`", vars_df, "`"), collapse = NULL), collapse = scope_txt), operator, toString(result))))
filtered <<- as.logical(by(x, seq_len(nrow(x)),
function(row) scope_fn(unlist(row[, vars_df]) %in% result, na.rm = TRUE)))
x <- x[which(filtered), , drop = FALSE]
} else {
message(font_blue(paste0("NOTE: no antimicrobial agents of class ", ab_group,
" (such as ", find_ab_names(ab_group),
") found, data left unchanged.")))
# get all columns in data with names that resemble antibiotics
ab_in_data <- suppressMessages(get_column_abx(x))
if (length(ab_in_data) == 0) {
message(font_blue("NOTE: no antimicrobial agents found, data left unchanged."))
return(x.bak)
}
# get reference data
ab_class <- gsub("[^a-zA-Z0-9]+", ".*", ab_class)
ab_class <- gsub("(ph|f)", "(ph|f)", ab_class)
ab_class <- gsub("(t|th)", "(t|th)", ab_class)
ab_reference <- subset(antibiotics,
group %like% ab_class |
atc_group1 %like% ab_class |
atc_group2 %like% ab_class)
ab_group <- find_ab_group(ab_class)
# get the columns with a group names in the chosen ab class
agents <- ab_in_data[names(ab_in_data) %in% ab_reference$ab]
if (length(agents) == 0) {
message(font_blue(paste0("NOTE: no antimicrobial agents of class ", ab_group,
" found (such as ", find_ab_names(ab_class, 2),
"), data left unchanged.")))
return(x.bak)
}
if (length(result) == 1) {
operator <- " is "
} else {
operator <- " is one of "
}
if (scope == "any") {
scope_txt <- " or "
scope_fn <- any
} else {
scope_txt <- " and "
scope_fn <- all
if (length(agents) > 1) {
operator <- gsub("is", "are", operator)
}
}
if (length(agents) > 1) {
scope <- paste(scope, "of columns ")
} else {
scope <- "column "
}
# sort columns on official name
agents <- agents[order(ab_name(names(agents), language = NULL))]
message(font_blue(paste0("Filtering on ", ab_group, ": ", scope,
paste(paste0("`", font_bold(agents, collapse = NULL),
"` (", ab_name(names(agents), tolower = TRUE, language = NULL), ")"),
collapse = scope_txt),
operator, toString(result))))
filtered <- as.logical(by(x, seq_len(nrow(x)),
function(row) scope_fn(unlist(row[, agents]) %in% result, na.rm = TRUE)))
x <- x[which(filtered), , drop = FALSE]
class(x) <- x_class
x
}
@ -279,6 +297,19 @@ filter_macrolides <- function(x,
...)
}
#' @rdname filter_ab_class
#' @export
filter_penicillins <- function(x,
result = NULL,
scope = "any",
...) {
filter_ab_class(x = x,
ab_class = "penicillin",
result = result,
scope = scope,
...)
}
#' @rdname filter_ab_class
#' @export
filter_tetracyclines <- function(x,
@ -312,9 +343,9 @@ find_ab_group <- function(ab_class) {
)
}
find_ab_names <- function(ab_group) {
find_ab_names <- function(ab_group, n = 3) {
drugs <- antibiotics[which(antibiotics$group %like% ab_group), "name"]
paste0(ab_name(sample(drugs, size = min(4, length(drugs)), replace = FALSE),
tolower = TRUE, language = NULL),
paste0(sort(ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE),
tolower = TRUE, language = NULL)),
collapse = ", ")
}

View File

@ -160,6 +160,11 @@ get_column_abx <- function(x,
x <- x[!is.na(x)]
}
if (length(x) == 0) {
message(font_blue("No columns found."))
return(x)
}
# sort on name
x <- x[order(names(x), x)]
duplicates <- c(x[base::duplicated(x)], x[base::duplicated(names(x))])
@ -167,7 +172,7 @@ get_column_abx <- function(x,
x <- c(x[!names(x) %in% names(duplicates)], duplicates)
x <- x[order(names(x), x)]
# succeeded with aut-guessing
# succeeded with auto-guessing
message(font_blue("OK."))
for (i in seq_len(length(x))) {

View File

@ -55,7 +55,9 @@
#' }
inner_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
check_dataset_integrity()
check_groups_before_join(x, "inner_join_microorganisms")
checked <- joins_check_df(x, by)
x_class <- class(x)
x <- checked$x
by <- checked$by
join <- suppressWarnings(
@ -64,6 +66,7 @@ inner_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
if (NROW(join) > NROW(x)) {
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
}
class(join) <- x_class
join
}
@ -71,7 +74,9 @@ inner_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
#' @export
left_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
check_dataset_integrity()
check_groups_before_join(x, "left_join_microorganisms")
checked <- joins_check_df(x, by)
x_class <- class(x)
x <- checked$x
by <- checked$by
join <- suppressWarnings(
@ -80,6 +85,7 @@ left_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
if (NROW(join) > NROW(x)) {
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
}
class(join) <- x_class
join
}
@ -87,7 +93,9 @@ left_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
#' @export
right_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
check_dataset_integrity()
check_groups_before_join(x, "right_join_microorganisms")
checked <- joins_check_df(x, by)
x_class <- class(x)
x <- checked$x
by <- checked$by
join <- suppressWarnings(
@ -96,6 +104,7 @@ right_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
if (NROW(join) > NROW(x)) {
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
}
class(join) <- x_class
join
}
@ -103,7 +112,9 @@ right_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
#' @export
full_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
check_dataset_integrity()
check_groups_before_join(x, "full_join_microorganisms")
checked <- joins_check_df(x, by)
x_class <- class(x)
x <- checked$x
by <- checked$by
join <- suppressWarnings(
@ -112,6 +123,7 @@ full_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
if (NROW(join) > NROW(x)) {
warning("The newly joined tbl contains ", nrow(join) - nrow(x), " rows more that its original.")
}
class(join) <- x_class
join
}
@ -119,24 +131,32 @@ full_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
#' @export
semi_join_microorganisms <- function(x, by = NULL, ...) {
check_dataset_integrity()
check_groups_before_join(x, "semi_join_microorganisms")
x_class <- class(x)
checked <- joins_check_df(x, by)
x <- checked$x
by <- checked$by
suppressWarnings(
join <- suppressWarnings(
semi_join(x = x, y = microorganisms, by = by, ...)
)
class(join) <- x_class
join
}
#' @rdname join
#' @export
anti_join_microorganisms <- function(x, by = NULL, ...) {
check_dataset_integrity()
check_groups_before_join(x, "anti_join_microorganisms")
checked <- joins_check_df(x, by)
x_class <- class(x)
x <- checked$x
by <- checked$by
suppressWarnings(
join <- suppressWarnings(
anti_join(x = x, y = microorganisms, by = by, ...)
)
class(join) <- x_class
join
}
joins_check_df <- function(x, by) {
@ -146,6 +166,7 @@ joins_check_df <- function(x, by) {
by <- "mo"
}
}
x <- as.data.frame(x, stringsAsFactors = FALSE)
if (is.null(by)) {
# search for column with class `mo` and return first one found
by <- colnames(x)[lapply(x, is.mo) == TRUE][1]
@ -168,3 +189,9 @@ joins_check_df <- function(x, by) {
list(x = x,
by = joinby)
}
check_groups_before_join <- function(x, fn) {
if (is.data.frame(x) && !is.null(attributes(x)$groups)) {
warning("Groups are dropped, since the ", fn, "() function relies on merge() from base R, not on join() from dplyr.", call. = FALSE)
}
}

Binary file not shown.

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>

View File

@ -43,7 +43,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>
@ -229,20 +229,24 @@
<small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div>
<div id="amr-1209000" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9000">
<a href="#amr-1209000" class="anchor"></a>AMR 1.2.0.9000<small> Unreleased </small>
<div id="amr-1209001" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9001">
<a href="#amr-1209001" class="anchor"></a>AMR 1.2.0.9001<small> Unreleased </small>
</h1>
<div id="last-updated-02-jun-2020" class="section level2">
<div id="last-updated-03-jun-2020" class="section level2">
<h2 class="hasAnchor">
<a href="#last-updated-02-jun-2020" class="anchor"></a><small>Last updated: 02-Jun-2020</small>
<a href="#last-updated-03-jun-2020" class="anchor"></a><small>Last updated: 03-Jun-2020</small>
</h2>
<div id="changed" class="section level3">
<h3 class="hasAnchor">
<a href="#changed" class="anchor"></a>Changed</h3>
<ul>
<li>Fixed a bug where <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> would not work on a tibble when the <code>tibble</code> or <code>dplyr</code> package was loaded</li>
<li>All <code>*_join_microorganisms()</code> functions now return the original data class (e.g. tibbles and data.tables)</li>
<li>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li>
<li>Added function <code><a href="../reference/filter_ab_class.html">filter_penicillins()</a></code> to filter isolates on a specific result in any column with a name in the antimicrobial penicillins class (more specific: ATC subgroup <em>Beta-lactam antibacterials, penicillins</em>)</li>
<li>Added official antimicrobial names to all <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code> functions, such as <code><a href="../reference/filter_ab_class.html">filter_aminoglycosides()</a></code>
</li>
</ul>
</div>
</div>
@ -274,7 +278,7 @@
<ul>
<li>Taxonomy:
<ul>
<li>Updated the taxonomy of microorganisms tot May 2020, using the Catalogue of Life (CoL), the Global Biodiversity Information Facility (GBIF) and the List of Prokaryotic names with Standing in Nomenclature (LPSN, hosted by DSMZ since February 2020). <strong>Note:</strong> a taxonomic update may always impact determination of first isolates (using <code><a href="../reference/first_isolate.html">first_isolate()</a></code>), since some bacterial names might be renamed to other genera or other (sub)species. This is expected behaviour.</li>
<li>Updated the taxonomy of microorganisms to May 2020, using the Catalogue of Life (CoL), the Global Biodiversity Information Facility (GBIF) and the List of Prokaryotic names with Standing in Nomenclature (LPSN, hosted by DSMZ since February 2020). <strong>Note:</strong> a taxonomic update may always impact determination of first isolates (using <code><a href="../reference/first_isolate.html">first_isolate()</a></code>), since some bacterial names might be renamed to other genera or other (sub)species. This is expected behaviour.</li>
<li>Removed the Catalogue of Life IDs (like 776351), since they now work with a species ID (hexadecimal string)</li>
</ul>
</li>

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html
benchmarks: benchmarks.html
resistance_predict: resistance_predict.html
last_built: 2020-06-02T14:04Z
last_built: 2020-06-03T09:44Z
urls:
reference: https://msberends.gitlab.io/AMR/reference
article: https://msberends.gitlab.io/AMR/articles

View File

@ -49,7 +49,7 @@
<script src="../extra.js"></script>
<meta property="og:title" content="Filter isolates on result in antimicrobial class — filter_ab_class" />
<meta property="og:description" content="Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside." />
<meta property="og:description" content="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." />
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" />
@ -82,7 +82,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>
@ -232,7 +232,7 @@
</div>
<div class="ref-description">
<p>Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside.</p>
<p>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.</p>
</div>
<pre class="usage"><span class='fu'>filter_ab_class</span>(<span class='no'>x</span>, <span class='no'>ab_class</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
@ -259,6 +259,8 @@
<span class='fu'>filter_macrolides</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
<span class='fu'>filter_penicillins</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)
<span class='fu'>filter_tetracyclines</span>(<span class='no'>x</span>, <span class='kw'>result</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>scope</span> <span class='kw'>=</span> <span class='st'>"any"</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
@ -288,7 +290,7 @@
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>The <code>group</code> column in <a href='antibiotics.html'>antibiotics</a> data set will be searched for <code>ab_class</code> (case-insensitive). If no results are found, the <code>atc_group1</code> and <code>atc_group2</code> columns will be searched. Next, <code>x</code> will be checked for column names with a value in any abbreviations, codes or official names found in the <a href='antibiotics.html'>antibiotics</a> data set.</p>
<p>The columns <code>group</code>, <code>atc_group1</code> and <code>atc_group2</code> of the <a href='antibiotics.html'>antibiotics</a> data set will be searched for the input given in <code>ab_class</code> (case-insensitive). Next, <code>x</code> will be checked for column names with a value in any abbreviation, code or official name found in the <a href='antibiotics.html'>antibiotics</a> data set.</p>
<h2 class="hasAnchor" id="stable-lifecycle"><a class="anchor" href="#stable-lifecycle"></a>Stable lifecycle</h2>
@ -302,6 +304,7 @@ The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>stable</s
<span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>dplyr</span>)
<span class='co'># filter on isolates that have any result for any aminoglycoside</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>filter_ab_class</span>(<span class='st'>"aminoglycoside"</span>)
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>filter_aminoglycosides</span>()
<span class='co'># this is essentially the same as (but without determination of column names):</span>
@ -311,7 +314,7 @@ The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>stable</s
<span class='co'># filter on isolates that show resistance to ANY aminoglycoside</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>filter_aminoglycosides</span>(<span class='st'>"R"</span>)
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>filter_aminoglycosides</span>(<span class='st'>"R"</span>, <span class='st'>"any"</span>)
<span class='co'># filter on isolates that show resistance to ALL aminoglycosides</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>filter_aminoglycosides</span>(<span class='st'>"R"</span>, <span class='st'>"all"</span>)

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9000</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9001</span>
</span>
</div>
@ -421,7 +421,7 @@
</tr><tr>
<td>
<p><code><a href="filter_ab_class.html">filter_ab_class()</a></code> <code><a href="filter_ab_class.html">filter_aminoglycosides()</a></code> <code><a href="filter_ab_class.html">filter_carbapenems()</a></code> <code><a href="filter_ab_class.html">filter_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_1st_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_2nd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_3rd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_4th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_5th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_fluoroquinolones()</a></code> <code><a href="filter_ab_class.html">filter_glycopeptides()</a></code> <code><a href="filter_ab_class.html">filter_macrolides()</a></code> <code><a href="filter_ab_class.html">filter_tetracyclines()</a></code> </p>
<p><code><a href="filter_ab_class.html">filter_ab_class()</a></code> <code><a href="filter_ab_class.html">filter_aminoglycosides()</a></code> <code><a href="filter_ab_class.html">filter_carbapenems()</a></code> <code><a href="filter_ab_class.html">filter_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_1st_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_2nd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_3rd_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_4th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_5th_cephalosporins()</a></code> <code><a href="filter_ab_class.html">filter_fluoroquinolones()</a></code> <code><a href="filter_ab_class.html">filter_glycopeptides()</a></code> <code><a href="filter_ab_class.html">filter_macrolides()</a></code> <code><a href="filter_ab_class.html">filter_penicillins()</a></code> <code><a href="filter_ab_class.html">filter_tetracyclines()</a></code> </p>
</td>
<td><p>Filter isolates on result in antimicrobial class</p></td>
</tr><tr>

View File

@ -13,6 +13,7 @@
\alias{filter_fluoroquinolones}
\alias{filter_glycopeptides}
\alias{filter_macrolides}
\alias{filter_penicillins}
\alias{filter_tetracyclines}
\title{Filter isolates on result in antimicrobial class}
\usage{
@ -40,6 +41,8 @@ filter_glycopeptides(x, result = NULL, scope = "any", ...)
filter_macrolides(x, result = NULL, scope = "any", ...)
filter_penicillins(x, result = NULL, scope = "any", ...)
filter_tetracyclines(x, result = NULL, scope = "any", ...)
}
\arguments{
@ -54,10 +57,10 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...)
\item{...}{parameters passed on to \code{filter_at} from the \code{dplyr} package}
}
\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.
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{
The \code{group} column in \link{antibiotics} data set will be searched for \code{ab_class} (case-insensitive). If no results are found, the \code{atc_group1} and \code{atc_group2} columns will be searched. Next, \code{x} will be checked for column names with a value in any abbreviations, codes or official names found in the \link{antibiotics} data set.
The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched for the input given in \code{ab_class} (case-insensitive). Next, \code{x} will be checked for column names with a value in any abbreviation, code or official name found in the \link{antibiotics} data set.
}
\section{Stable lifecycle}{
@ -72,6 +75,7 @@ If the unlying code needs breaking changes, they will occur gradually. For examp
library(dplyr)
# filter on isolates that have any result for any aminoglycoside
example_isolates \%>\% filter_ab_class("aminoglycoside")
example_isolates \%>\% filter_aminoglycosides()
# this is essentially the same as (but without determination of column names):
@ -81,7 +85,7 @@ example_isolates \%>\%
# filter on isolates that show resistance to ANY aminoglycoside
example_isolates \%>\% filter_aminoglycosides("R")
example_isolates \%>\% filter_aminoglycosides("R", "any")
# filter on isolates that show resistance to ALL aminoglycosides
example_isolates \%>\% filter_aminoglycosides("R", "all")

View File

@ -55,5 +55,9 @@ test_that("joins work", {
expect_warning(right_join_microorganisms("B_ESCHR_COLI"))
expect_warning(full_join_microorganisms("B_ESCHR_COLI"))
library(dplyr)
x <- tibble(bact = as.mo("E.coli"))
expect_warning(left_join_microorganisms(x %>% group_by(bact), "bact"))
})