1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 06:46:11 +01:00

(v1.2.0.9016) fix in rsi_calc()

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-06-26 10:21:22 +02:00
parent 033ca49817
commit b31003c0b6
21 changed files with 71 additions and 61 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.2.0.9015 Version: 1.2.0.9016
Date: 2020-06-25 Date: 2020-06-26
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(
person(role = c("aut", "cre"), person(role = c("aut", "cre"),

View File

@ -1,5 +1,5 @@
# AMR 1.2.0.9015 # AMR 1.2.0.9016
## <small>Last updated: 25-Jun-2020</small> ## <small>Last updated: 26-Jun-2020</small>
### New ### New
* Function `ab_from_text()` to retrieve antimicrobial drugs from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally: * Function `ab_from_text()` to retrieve antimicrobial drugs from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally:
@ -31,7 +31,7 @@
* Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set * Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set
### Changed ### Changed
* Fixed a bug for using `susceptibility` or `resistance()` outside `summarise()` * Using unexisting columns in all `count_*()`, `proportion_*()`, `susceptibility()` and `resistance()` functions wil now return an error instead of dropping them silently
* Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded * Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded
* All `*_join_microorganisms()` functions and `bug_drug_combinations()` now return the original data class (e.g. `tibble`s and `data.table`s) * All `*_join_microorganisms()` functions and `bug_drug_combinations()` now return the original data class (e.g. `tibble`s and `data.table`s)
* Fixed a bug where `as.ab()` would return an error on invalid input values * Fixed a bug where `as.ab()` would return an error on invalid input values

View File

@ -202,6 +202,7 @@ import_fn <- function(name, pkg) {
} }
stop_if <- function(expr, ..., call = TRUE) { stop_if <- function(expr, ..., call = TRUE) {
if (isTRUE(expr)) {
msg <- paste0(c(...), collapse = "") msg <- paste0(c(...), collapse = "")
if (!isFALSE(call)) { if (!isFALSE(call)) {
if (isTRUE(call)) { if (isTRUE(call)) {
@ -212,12 +213,12 @@ stop_if <- function(expr, ..., call = TRUE) {
} }
msg <- paste0("in ", call, "(): ", msg) msg <- paste0("in ", call, "(): ", msg)
} }
if (isTRUE(expr)) {
stop(msg, call. = FALSE) stop(msg, call. = FALSE)
} }
} }
stop_ifnot <- function(expr, ..., call = TRUE) { stop_ifnot <- function(expr, ..., call = TRUE) {
if (!isTRUE(expr)) {
msg <- paste0(c(...), collapse = "") msg <- paste0(c(...), collapse = "")
if (!isFALSE(call)) { if (!isFALSE(call)) {
if (isTRUE(call)) { if (isTRUE(call)) {
@ -228,7 +229,6 @@ stop_ifnot <- function(expr, ..., call = TRUE) {
} }
msg <- paste0("in ", call, "(): ", msg) msg <- paste0("in ", call, "(): ", msg)
} }
if (!isTRUE(expr)) {
stop(msg, call. = FALSE) stop(msg, call. = FALSE)
} }
} }

View File

@ -58,12 +58,17 @@ ab_from_text <- function(text, collapse = NULL, translate_ab = "name", ...) {
} }
text_split <- unlist(strsplit(text, "[ ;.,:/\\|-]")) text_split <- unlist(strsplit(text, "[ ;.,:/\\|-]"))
result <- as.ab(unique(c(text_split[grep(to_regex(abbr), text_split)], result <- suppressWarnings(
as.ab(unique(c(text_split[grep(to_regex(abbr), text_split)],
text_split[grep(to_regex(names), text_split)], text_split[grep(to_regex(names), text_split)],
# regular expression must not be too long, so split synonyms in two: # regular expression must not be too long, so split synonyms in two:
text_split[grep(to_regex(synonyms[c(1:0.5 * length(synonyms))]), text_split)], text_split[grep(to_regex(synonyms[c(1:0.5 * length(synonyms))]), text_split)],
text_split[grep(to_regex(synonyms[c(0.5 * length(synonyms):length(synonyms))]), text_split)])), text_split[grep(to_regex(synonyms[c(0.5 * length(synonyms):length(synonyms))]), text_split)])),
...) ...))
result <- result[!is.na(result)]
if (length(result) == 0) {
result <- as.ab(NA)
}
translate_ab <- get_translate_ab(translate_ab) translate_ab <- get_translate_ab(translate_ab)
if (!isFALSE(translate_ab)) { if (!isFALSE(translate_ab)) {
result <- ab_property(result, property = translate_ab) result <- ab_property(result, property = translate_ab)

View File

@ -130,7 +130,8 @@ as.mic <- function(x, na.rm = FALSE) {
} }
all_valid_mics <- function(x) { all_valid_mics <- function(x) {
x_mic <- suppressWarnings(as.mic(x[!is.na(x)])) x_mic <- tryCatch(suppressWarnings(as.mic(x[!is.na(x)])),
error = function(e) NA)
!any(is.na(x_mic)) & !all(is.na(x)) !any(is.na(x_mic)) & !all(is.na(x))
} }

View File

@ -166,10 +166,10 @@ as.rsi.default <- function(x, ...) {
} }
} }
x <- x %>% unlist() x <- as.character(unlist(x))
x.bak <- x x.bak <- x
na_before <- x[is.na(x) | x == ""] %>% length() na_before <- length(x[is.na(x) | x == ""])
# remove all spaces # remove all spaces
x <- gsub(" +", "", x) x <- gsub(" +", "", x)
# remove all MIC-like values: numbers, operators and periods # remove all MIC-like values: numbers, operators and periods
@ -188,7 +188,7 @@ as.rsi.default <- function(x, ...) {
x <- gsub("^I+$", "I", x) x <- gsub("^I+$", "I", x)
x <- gsub("^R+$", "R", x) x <- gsub("^R+$", "R", x)
x[!x %in% c("S", "I", "R")] <- NA x[!x %in% c("S", "I", "R")] <- NA
na_after <- x[is.na(x) | x == ""] %>% length() na_after <- length(x[is.na(x) | x == ""])
if (!isFALSE(list(...)$warn)) { # so as.rsi(..., warn = FALSE) will never throw a warning if (!isFALSE(list(...)$warn)) { # so as.rsi(..., warn = FALSE) will never throw a warning
if (na_before != na_after) { if (na_before != na_after) {

View File

@ -48,18 +48,23 @@ rsi_calc <- function(...,
"Please read Details in the help page (`?proportion`) as this may have a considerable impact on your analysis.", call = -2) "Please read Details in the help page (`?proportion`) as this may have a considerable impact on your analysis.", call = -2)
ndots <- length(dots) ndots <- length(dots)
if ("data.frame" %in% class(dots_df)) { if (is.data.frame(dots_df)) {
# data.frame passed with other columns, like: example_isolates %>% proportion_S(AMC, GEN) # data.frame passed with other columns, like: example_isolates %>% proportion_S(AMC, GEN)
dots <- as.character(dots) dots <- as.character(dots)
dots <- dots[dots != "."] # remove first element, it's the data.frame
if (length(dots) == 1) {
dots <- character(0)
} else {
dots <- dots[2:length(dots)]
}
if (length(dots) == 0 | all(dots == "df")) { if (length(dots) == 0 | all(dots == "df")) {
# for complete data.frames, like example_isolates %>% select(AMC, GEN) %>% proportion_S() # for complete data.frames, like example_isolates %>% select(AMC, GEN) %>% proportion_S()
# and the old rsi function, which has "df" as name of the first parameter # and the old rsi function, which has "df" as name of the first parameter
x <- dots_df x <- dots_df
} else if (length(dots) == 1 | all(!dots %in% colnames(dots_df))) {
x <- dots_df
} else { } else {
x <- dots_df[, dots[dots %in% colnames(dots_df)], drop = FALSE] dots_not_exist <- dots[!dots %in% colnames(dots_df)]
stop_if(length(dots_not_exist) > 0, "column(s) not found: ", paste0("'", dots_not_exist, "'", collapse = ", "), call = -2)
x <- dots_df[, dots, drop = FALSE]
} }
} else if (ndots == 1) { } else if (ndots == 1) {
# only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$AMC) and example_isolates$AMC %>% proportion_S() # only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$AMC) and example_isolates$AMC %>% proportion_S()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9015</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>
@ -229,13 +229,13 @@
<small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small> <small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div> </div>
<div id="amr-1209015" class="section level1"> <div id="amr-1209016" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9015"> <h1 class="page-header" data-toc-text="1.2.0.9016">
<a href="#amr-1209015" class="anchor"></a>AMR 1.2.0.9015<small> Unreleased </small> <a href="#amr-1209016" class="anchor"></a>AMR 1.2.0.9016<small> Unreleased </small>
</h1> </h1>
<div id="last-updated-25-jun-2020" class="section level2"> <div id="last-updated-26-jun-2020" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-25-jun-2020" class="anchor"></a><small>Last updated: 25-Jun-2020</small> <a href="#last-updated-26-jun-2020" class="anchor"></a><small>Last updated: 26-Jun-2020</small>
</h2> </h2>
<div id="new" class="section level3"> <div id="new" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -274,8 +274,7 @@
<h3 class="hasAnchor"> <h3 class="hasAnchor">
<a href="#changed" class="anchor"></a>Changed</h3> <a href="#changed" class="anchor"></a>Changed</h3>
<ul> <ul>
<li>Fixed a bug for using <code>susceptibility</code> or <code><a href="../reference/proportion.html">resistance()</a></code> outside <code><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise()</a></code> <li>Using unexisting columns in all <code>count_*()</code>, <code>proportion_*()</code>, <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> functions wil now return an error instead of dropping them silently</li>
</li>
<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>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 and <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> now return the original data class (e.g. <code>tibble</code>s and <code>data.table</code>s)</li> <li>All <code>*_join_microorganisms()</code> functions and <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> now return the original data class (e.g. <code>tibble</code>s and <code>data.table</code>s)</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>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li>

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html WHONET: WHONET.html
benchmarks: benchmarks.html benchmarks: benchmarks.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
last_built: 2020-06-25T17:20Z last_built: 2020-06-26T08:20Z
urls: urls:
reference: https://msberends.gitlab.io/AMR/reference reference: https://msberends.gitlab.io/AMR/reference
article: https://msberends.gitlab.io/AMR/articles article: https://msberends.gitlab.io/AMR/articles

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9014</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9014</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>

View File

@ -83,7 +83,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9014</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9014</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>

View File

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

View File

@ -83,7 +83,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <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.9014</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9016</span>
</span> </span>
</div> </div>