(v1.2.0.9033) speed improvement mdro(), filter_ab_class()

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-07-12 11:43:31 +02:00
parent 1d66b5c43c
commit c0cf7ab02b
17 changed files with 69 additions and 35 deletions

1
.lintr
View File

@ -1 +0,0 @@
linters: with_defaults(line_length_linter = NULL, trailing_whitespace_linter = NULL, object_name_linter = NULL, cyclocomp_linter = NULL, object_usage_linter = NULL, object_length_linter(length = 50L))

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 1.2.0.9032
Date: 2020-07-09
Version: 1.2.0.9033
Date: 2020-07-12
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),

View File

@ -1,5 +1,5 @@
# AMR 1.2.0.9032
## <small>Last updated: 09-Jul-2020</small>
# AMR 1.2.0.9033
## <small>Last updated: 12-Jul-2020</small>
### New
* Function `ab_from_text()` to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally
@ -36,6 +36,7 @@
* Changed the summary for class `<mo>`, to highlight the %SI vs. %R
* Improved error handling, giving more useful info when functions return an error
* Any progress bar will now only show in interactive mode (i.e. not in R Markdown)
* Speed improvement for `mdro()` and `filter_ab_class()`
### Other
* Moved primary location of this project from GitLab to [GitHub](https://github.com/msberends/AMR), giving us native support for automated syntax checking without being dependent on external services such as AppVeyor and Travis CI.

View File

@ -27,7 +27,7 @@
#' @param ab_class an antimicrobial class, like `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value.
#' @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
#' @param ... previously used when this package still depended on the `dplyr` package, now ignored
#' @details All columns of `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. [filter_aminoglycosides()] will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
#' @rdname filter_ab_class
#' @seealso [antibiotic_class_selectors()] for the `select()` equivalent.
@ -85,13 +85,13 @@ filter_ab_class <- function(x,
# make result = "SI" works too:
result <- unlist(strsplit(result, ""))
stop_ifnot(all(result %in% c("S", "I", "R")), "`result` must be one or more of: S, I, R")
stop_ifnot(all(scope %in% c("any", "all")), "`scope` must be one of: any, all")
stop_ifnot(all(result %in% c("S", "I", "R")), "`result` must be one or more of: 'S', 'I', 'R'")
stop_ifnot(all(scope %in% c("any", "all")), "`scope` must be one of: 'any', 'all'")
# 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."))
message(font_blue("NOTE: no columns with class <rsi> found (see ?as.rsi), data left unchanged."))
return(x.bak)
}
# get reference data
@ -146,8 +146,8 @@ filter_ab_class <- function(x,
"` (", 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_transposed <- as.list(as.data.frame(t(x[, agents, drop = FALSE])))
filtered <- sapply(x_transposed, function(y) scope_fn(y %in% result, na.rm = TRUE))
x <- x[which(filtered), , drop = FALSE]
class(x) <- x_class
x

View File

@ -468,9 +468,8 @@ mdro <- function(x,
} else if (any_all == "all") {
search_function <- all
}
row_filter <- as.logical(by(x,
seq_len(nrow(x)),
function(row) search_function(unlist(row[, cols]) %in% search_result, na.rm = TRUE)))
x_transposed <- as.list(as.data.frame(t(x[, cols, drop = FALSE])))
row_filter <- sapply(x_transposed, function(y) search_function(y %in% search_result, na.rm = TRUE))
row_filter <- x[row_filter, "row_number", drop = TRUE]
rows <- rows[rows %in% row_filter]
x[rows, "MDRO"] <<- to
@ -507,9 +506,8 @@ mdro <- function(x,
na.rm = TRUE)
})
# for PDR; all agents are R (or I if combine_SI = FALSE)
row_filter <- as.logical(by(x[rows, ],
seq_len(nrow(x[rows, ])),
function(row) all(unlist(row[, lst_vector]) %in% search_result, na.rm = TRUE)))
x_transposed <- as.list(as.data.frame(t(x[rows, lst_vector, drop = FALSE])))
row_filter <- sapply(x_transposed, function(y) all(y %in% search_result, na.rm = TRUE))
x[row_filter, "classes_affected"] <<- 999
}

34
codecov.yml Normal file
View File

@ -0,0 +1,34 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.github.io/AMR. #
# ==================================================================== #
codecov:
require_ci_to_pass: no # allow fail
comment: no
coverage:
precision: 1
round: up
range: "0...100"
status:
project: no
patch: no
changes: no

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</span>
</span>
</div>

View File

@ -39,7 +39,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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</span>
</span>
</div>
@ -186,7 +186,7 @@
<h1 data-toc-skip>How to work with WHONET data</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">09 July 2020</h4>
<h4 class="date">12 July 2020</h4>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/master/vignettes/WHONET.Rmd"><code>vignettes/WHONET.Rmd</code></a></small>
<div class="hidden name"><code>WHONET.Rmd</code></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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</span>
</span>
</div>
@ -229,13 +229,13 @@
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div>
<div id="amr-1209032" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9032">
<a href="#amr-1209032" class="anchor"></a>AMR 1.2.0.9032<small> Unreleased </small>
<div id="amr-1209033" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9033">
<a href="#amr-1209033" class="anchor"></a>AMR 1.2.0.9033<small> Unreleased </small>
</h1>
<div id="last-updated-09-jul-2020" class="section level2">
<div id="last-updated-12-jul-2020" class="section level2">
<h2 class="hasAnchor">
<a href="#last-updated-09-jul-2020" class="anchor"></a><small>Last updated: 09-Jul-2020</small>
<a href="#last-updated-12-jul-2020" class="anchor"></a><small>Last updated: 12-Jul-2020</small>
</h2>
<div id="new" class="section level3">
<h3 class="hasAnchor">
@ -286,6 +286,8 @@
<li>Changed the summary for class <code>&lt;mo&gt;</code>, to highlight the %SI vs. %R</li>
<li>Improved error handling, giving more useful info when functions return an error</li>
<li>Any progress bar will now only show in interactive mode (i.e. not in R Markdown)</li>
<li>Speed improvement for <code><a href="../reference/mdro.html">mdro()</a></code> and <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code>
</li>
</ul>
</div>
<div id="other" class="section level3">

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html
benchmarks: benchmarks.html
resistance_predict: resistance_predict.html
last_built: 2020-07-09T18:06Z
last_built: 2020-07-12T09:42Z
urls:
reference: https://msberends.github.io/AMR/reference
article: https://msberends.github.io/AMR/articles

View File

@ -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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</span>
</span>
</div>
@ -284,7 +284,7 @@
</tr>
<tr>
<th>...</th>
<td><p>parameters passed on to <code>filter_at</code> from the <code>dplyr</code> package</p></td>
<td><p>previously used when this package still depended on the <code>dplyr</code> package, now ignored</p></td>
</tr>
</table>

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.9032</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9033</span>
</span>
</div>

View File

@ -54,7 +54,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...)
\item{scope}{the scope to check which variables to check, can be \code{"any"} (default) or \code{"all"}}
\item{...}{parameters passed on to \code{filter_at} from the \code{dplyr} package}
\item{...}{previously used when this package still depended on the \code{dplyr} package, now ignored}
}
\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.