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

(v0.7.1.9093) as.ab() fix

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-10-06 21:07:38 +02:00
parent 8bc4081b03
commit b6653a620a
13 changed files with 43 additions and 41 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 0.7.1.9092 Version: 0.7.1.9093
Date: 2019-10-04 Date: 2019-10-06
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 0.7.1.9092 # AMR 0.7.1.9093
<small>Last updated: 04-Oct-2019</small> <small>Last updated: 06-Oct-2019</small>
### Breaking ### Breaking
* Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`:
@ -94,7 +94,7 @@
* Added support for unknown yeasts and fungi * Added support for unknown yeasts and fungi
* Changed most microorganism IDs to improve readability. For example, the old code `B_ENTRC_FAE` could have been both *E. faecalis* and *E. faecium*. Its new code is `B_ENTRC_FCLS` and *E. faecium* has become `B_ENTRC_FACM`. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for *Aerococcus urinae* was `B_ARCCC_NAE`. This is now `B_AERCC_URIN`. * Changed most microorganism IDs to improve readability. For example, the old code `B_ENTRC_FAE` could have been both *E. faecalis* and *E. faecium*. Its new code is `B_ENTRC_FCLS` and *E. faecium* has become `B_ENTRC_FACM`. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for *Aerococcus urinae* was `B_ARCCC_NAE`. This is now `B_AERCC_URIN`.
**IMPORTANT:** Old microorganism IDs are still supported, but support will be dropped in a future version. Use `as.mo()` on your old codes to transform them to the new format. Using functions from the `mo_*` family (like `mo_name()` and `mo_gramstain()`) on old codes, will throw a warning. **IMPORTANT:** Old microorganism IDs are still supported, but support will be dropped in a future version. Use `as.mo()` on your old codes to transform them to the new format. Using functions from the `mo_*` family (like `mo_name()` and `mo_gramstain()`) on old codes, will throw a warning.
* More intelligent guessing for `as.ab()` * More intelligent guessing for `as.ab()` which also led to bidirectional language support
* Renamed data set `septic_patients` to `example_isolates` * Renamed data set `septic_patients` to `example_isolates`
* Function `eucast_rules()`: * Function `eucast_rules()`:
* Fixed a bug for *Yersinia pseudotuberculosis* * Fixed a bug for *Yersinia pseudotuberculosis*

37
R/ab.R
View File

@ -84,7 +84,7 @@ as.ab <- function(x, ...) {
# keep only max 1 space # keep only max 1 space
x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean, ignore.case = TRUE)) x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean, ignore.case = TRUE))
# non-character, space or number should be a slash # non-character, space or number should be a slash
x_bak_clean <- gsub("[^A-Za-z0-9 ]", "/", x_bak_clean) x_bak_clean <- gsub("[^A-Za-z0-9 -]", "/", x_bak_clean)
# spaces around non-characters must be removed: amox + clav -> amox/clav # spaces around non-characters must be removed: amox + clav -> amox/clav
x_bak_clean <- gsub("(.*[a-zA-Z0-9]) ([^a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) x_bak_clean <- gsub("(.*[a-zA-Z0-9]) ([^a-zA-Z0-9].*)", "\\1\\2", x_bak_clean)
x_bak_clean <- gsub("(.*[^a-zA-Z0-9]) ([a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) x_bak_clean <- gsub("(.*[^a-zA-Z0-9]) ([a-zA-Z0-9].*)", "\\1\\2", x_bak_clean)
@ -247,22 +247,25 @@ as.ab <- function(x, ...) {
x_new[i] <- x_translated_guess x_new[i] <- x_translated_guess
next next
} }
# now also try to coerce brandname combinations like "Amoxy/clavulanic acid"
x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"), if (!isFALSE(list(...)$initial_search2)) {
function(y) { # now also try to coerce brandname combinations like "Amoxy/clavulanic acid"
for (i in 1:length(y)) { x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"),
y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE)) function(y) {
y[i] <- ifelse(!is.na(y_name), for (i in 1:length(y)) {
y_name, y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE, initial_search2 = FALSE))
y[i]) y[i] <- ifelse(!is.na(y_name),
} y_name,
y y[i])
})[[1]], }
collapse = "/") y
x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) })[[1]],
if (!is.na(x_translated_guess)) { collapse = "/")
x_new[i] <- x_translated_guess x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE))
next if (!is.na(x_translated_guess)) {
x_new[i] <- x_translated_guess
next
}
} }
} }

View File

@ -76,7 +76,7 @@ atc_online_property <- function(atc_code,
administration = 'O', administration = 'O',
url = 'https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no') { url = 'https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no') {
if (!all(c("curl", "rvest", "xml2") %in% rownames(installed.packages()))) { if (!all(c("curl", "rvest", "xml2") %in% rownames(utils::installed.packages()))) {
stop("Packages 'xml2', 'rvest' and 'curl' are required for this function") stop("Packages 'xml2', 'rvest' and 'curl' are required for this function")
} }

View File

@ -153,8 +153,8 @@ round2 <- function(x, digits = 0, force_zero = TRUE) {
# https://stackoverflow.com/a/12688836/4575331 # https://stackoverflow.com/a/12688836/4575331
val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x) val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x)
if (digits > 0 & force_zero == TRUE) { if (digits > 0 & force_zero == TRUE) {
val[val != as.integer(val)] <- paste0(val[val != as.integer(val)], val[val != as.integer(val) & !is.na(val)] <- paste0(val[val != as.integer(val) & !is.na(val)],
strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", val[val != as.integer(val)]))))) strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", val[val != as.integer(val) & !is.na(val)])))))
} }
val val
} }

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>
@ -231,11 +231,11 @@
</div> </div>
<div id="amr-0-7-1-9092" class="section level1"> <div id="amr-0-7-1-9093" class="section level1">
<h1 class="page-header"> <h1 class="page-header">
<a href="#amr-0-7-1-9092" class="anchor"></a>AMR 0.7.1.9092<small> Unreleased </small> <a href="#amr-0-7-1-9093" class="anchor"></a>AMR 0.7.1.9093<small> Unreleased </small>
</h1> </h1>
<p><small>Last updated: 04-Oct-2019</small></p> <p><small>Last updated: 06-Oct-2019</small></p>
<div id="breaking" class="section level3"> <div id="breaking" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
<a href="#breaking" class="anchor"></a>Breaking</h3> <a href="#breaking" class="anchor"></a>Breaking</h3>
@ -336,8 +336,7 @@ Since this is a major change, usage of the old <code>also_single_tested</code> w
<li>Changed most microorganism IDs to improve readability. For example, the old code <code>B_ENTRC_FAE</code> could have been both <em>E. faecalis</em> and <em>E. faecium</em>. Its new code is <code>B_ENTRC_FCLS</code> and <em>E. faecium</em> has become <code>B_ENTRC_FACM</code>. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for <em>Aerococcus urinae</em> was <code>B_ARCCC_NAE</code>. This is now <code>B_AERCC_URIN</code>. <strong>IMPORTANT:</strong> Old microorganism IDs are still supported, but support will be dropped in a future version. Use <code><a href="../reference/as.mo.html">as.mo()</a></code> on your old codes to transform them to the new format. Using functions from the <code>mo_*</code> family (like <code><a href="../reference/mo_property.html">mo_name()</a></code> and <code><a href="../reference/mo_property.html">mo_gramstain()</a></code>) on old codes, will throw a warning.</li> <li>Changed most microorganism IDs to improve readability. For example, the old code <code>B_ENTRC_FAE</code> could have been both <em>E. faecalis</em> and <em>E. faecium</em>. Its new code is <code>B_ENTRC_FCLS</code> and <em>E. faecium</em> has become <code>B_ENTRC_FACM</code>. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for <em>Aerococcus urinae</em> was <code>B_ARCCC_NAE</code>. This is now <code>B_AERCC_URIN</code>. <strong>IMPORTANT:</strong> Old microorganism IDs are still supported, but support will be dropped in a future version. Use <code><a href="../reference/as.mo.html">as.mo()</a></code> on your old codes to transform them to the new format. Using functions from the <code>mo_*</code> family (like <code><a href="../reference/mo_property.html">mo_name()</a></code> and <code><a href="../reference/mo_property.html">mo_gramstain()</a></code>) on old codes, will throw a warning.</li>
</ul> </ul>
</li> </li>
<li>More intelligent guessing for <code><a href="../reference/as.ab.html">as.ab()</a></code> <li>More intelligent guessing for <code><a href="../reference/as.ab.html">as.ab()</a></code> which also led to bidirectional language support</li>
</li>
<li>Renamed data set <code>septic_patients</code> to <code>example_isolates</code> <li>Renamed data set <code>septic_patients</code> to <code>example_isolates</code>
</li> </li>
<li>Function <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code>: <li>Function <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code>:
@ -1290,7 +1289,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
<div id="tocnav"> <div id="tocnav">
<h2>Contents</h2> <h2>Contents</h2>
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="#amr-0-7-1-9092">0.7.1.9092</a></li> <li><a href="#amr-0-7-1-9093">0.7.1.9093</a></li>
<li><a href="#amr-0-7-1">0.7.1</a></li> <li><a href="#amr-0-7-1">0.7.1</a></li>
<li><a href="#amr-0-7-0">0.7.0</a></li> <li><a href="#amr-0-7-0">0.7.0</a></li>
<li><a href="#amr-0-6-1">0.6.1</a></li> <li><a href="#amr-0-6-1">0.6.1</a></li>

View File

@ -84,7 +84,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">0.7.1.9092</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9093</span>
</span> </span>
</div> </div>

View File

@ -23,10 +23,10 @@ context("data.R")
test_that("data sets are valid", { test_that("data sets are valid", {
# IDs should always be unique # IDs should always be unique
expect_identical(nrow(antibiotics), length(unique(antibiotics$ab)))
expect_identical(class(antibiotics$ab), "ab")
expect_identical(nrow(microorganisms), length(unique(microorganisms$mo))) expect_identical(nrow(microorganisms), length(unique(microorganisms$mo)))
expect_identical(class(microorganisms$mo), "mo") expect_identical(class(microorganisms$mo), "mo")
expect_identical(nrow(antibiotics), length(unique(antibiotics$ab)))
expect_identical(class(antibiotics$ab), "ab")
# check cross table reference # check cross table reference
expect_true(all(microorganisms.codes$mo %in% microorganisms$mo)) expect_true(all(microorganisms.codes$mo %in% microorganisms$mo))