From c0cf7ab02b4ac54182183dba0469ce13b27cf9d3 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Sun, 12 Jul 2020 11:43:31 +0200 Subject: [PATCH] (v1.2.0.9033) speed improvement mdro(), filter_ab_class() --- .lintr | 1 - DESCRIPTION | 4 ++-- NEWS.md | 5 +++-- R/filter_ab_class.R | 12 +++++----- R/mdro.R | 10 ++++----- codecov.yml | 34 +++++++++++++++++++++++++++++ docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/WHONET.html | 4 ++-- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 14 +++++++----- docs/pkgdown.yml | 2 +- docs/reference/filter_ab_class.html | 4 ++-- docs/reference/index.html | 2 +- man/filter_ab_class.Rd | 2 +- 17 files changed, 69 insertions(+), 35 deletions(-) delete mode 100644 .lintr create mode 100644 codecov.yml diff --git a/.lintr b/.lintr deleted file mode 100644 index 1e82191e..00000000 --- a/.lintr +++ /dev/null @@ -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)) diff --git a/DESCRIPTION b/DESCRIPTION index 3f7b4567..1dfdd366 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), diff --git a/NEWS.md b/NEWS.md index 722eac91..0cb707aa 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.2.0.9032 -## Last updated: 09-Jul-2020 +# AMR 1.2.0.9033 +## Last updated: 12-Jul-2020 ### 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 ``, 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. diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index b37ea9a0..de0130e0 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -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 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 diff --git a/R/mdro.R b/R/mdro.R index 01835ad6..fd972a0c 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -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 } diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..90034b66 --- /dev/null +++ b/codecov.yml @@ -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 diff --git a/docs/404.html b/docs/404.html index 1db1be6b..5a1087c6 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index ad2fe669..4acc9648 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index 46684c5e..550a1924 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -39,7 +39,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 @@ -186,7 +186,7 @@

How to work with WHONET data

Matthijs S. Berends

-

09 July 2020

+

12 July 2020

Source: vignettes/WHONET.Rmd diff --git a/docs/articles/index.html b/docs/articles/index.html index 2bd5ee92..3d18eab4 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 diff --git a/docs/authors.html b/docs/authors.html index b682fe49..70b287a3 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 diff --git a/docs/index.html b/docs/index.html index 2dfebaa1..53a85d4b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 diff --git a/docs/news/index.html b/docs/news/index.html index d36a9a62..550b2693 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033 @@ -229,13 +229,13 @@ Source: NEWS.md -
-

-AMR 1.2.0.9032 Unreleased +
+

+AMR 1.2.0.9033 Unreleased

-
+

-Last updated: 09-Jul-2020 +Last updated: 12-Jul-2020

@@ -286,6 +286,8 @@
  • 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() +
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 4bc83d8c..a3ba0cf6 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -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 diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 9f737481..3ae94bd1 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033
    @@ -284,7 +284,7 @@ ... -

    parameters passed on to filter_at from the dplyr package

    +

    previously used when this package still depended on the dplyr package, now ignored

    diff --git a/docs/reference/index.html b/docs/reference/index.html index bd20d1db..6d89d6a7 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9032 + 1.2.0.9033
    diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index 1f99f243..7b9ea39d 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -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.