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
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
-
-