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

(v1.2.0.9006) improve auto col-determination

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-06-11 20:03:13 +02:00
parent 352508889c
commit 4f94e1312f
12 changed files with 38 additions and 40 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.2.0.9005 Version: 1.2.0.9006
Date: 2020-06-09 Date: 2020-06-11
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.9005 # AMR 1.2.0.9006
## <small>Last updated: 09-Jun-2020</small> ## <small>Last updated: 11-Jun-2020</small>
### Changed ### Changed
* 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
@ -9,6 +9,7 @@
* Added function `filter_penicillins()` to filter isolates on a specific result in any column with a name in the antimicrobial 'penicillins' class (more specific: ATC subgroup *Beta-lactam antibacterials, penicillins*) * Added function `filter_penicillins()` to filter isolates on a specific result in any column with a name in the antimicrobial 'penicillins' class (more specific: ATC subgroup *Beta-lactam antibacterials, penicillins*)
* Added official antimicrobial names to all `filter_ab_class()` functions, such as `filter_aminoglycosides()` * Added official antimicrobial names to all `filter_ab_class()` functions, such as `filter_aminoglycosides()`
* 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
* Improved auto-determination for columns of types <mo> and <Date>
# AMR 1.2.0 # AMR 1.2.0

View File

@ -103,60 +103,55 @@ search_type_in_df <- function(x, type) {
# -- mo # -- mo
if (type == "mo") { if (type == "mo") {
if ("mo" %in% lapply(x, class)) { if (any(sapply(x, is.mo))) {
found <- colnames(x)[lapply(x, class) == "mo"][1] found <- sort(colnames(x)[sapply(x, is.mo)])[1]
} else if ("mo" %in% colnames(x) & } else if ("mo" %in% colnames(x) &
suppressWarnings( suppressWarnings(
all(x$mo %in% c(NA, all(x$mo %in% c(NA,
microorganisms$mo, microorganisms$mo,
microorganisms.translation$mo_old)))) { microorganisms.translation$mo_old)))) {
found <- "mo" found <- "mo"
} else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria|bacterie)s?$")) { } else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria|ba[ck]terie)s?$")) {
found <- colnames(x)[colnames(x) %like% "^(mo|microorganism|organism|bacteria|bacterie)s?$"][1] found <- sort(colnames(x)[colnames(x) %like% "^(mo|microorganism|organism|bacteria|ba[ck]terie)s?$"])[1]
} else if (any(colnames(x) %like% "^(microorganism|organism|bacteria|bacterie)")) { } else if (any(colnames(x) %like% "^(microorganism|organism|bacteria|ba[ck]terie)")) {
found <- colnames(x)[colnames(x) %like% "^(microorganism|organism|bacteria|bacterie)"][1] found <- sort(colnames(x)[colnames(x) %like% "^(microorganism|organism|bacteria|ba[ck]terie)"])[1]
} else if (any(colnames(x) %like% "species")) { } else if (any(colnames(x) %like% "species")) {
found <- colnames(x)[colnames(x) %like% "species"][1] found <- sort(colnames(x)[colnames(x) %like% "species"])[1]
} }
} }
# -- key antibiotics # -- key antibiotics
if (type == "keyantibiotics") { if (type == "keyantibiotics") {
if (any(colnames(x) %like% "^key.*(ab|antibiotics)")) { if (any(colnames(x) %like% "^key.*(ab|antibiotics)")) {
found <- colnames(x)[colnames(x) %like% "^key.*(ab|antibiotics)"][1] found <- sort(colnames(x)[colnames(x) %like% "^key.*(ab|antibiotics)"])[1]
} }
} }
# -- date # -- date
if (type == "date") { if (type == "date") {
if (any(colnames(x) %like% "^(specimen date|specimen_date|spec_date)")) { if (any(colnames(x) %like% "^(specimen date|specimen_date|spec_date)")) {
# WHONET support # WHONET support
found <- colnames(x)[colnames(x) %like% "^(specimen date|specimen_date|spec_date)"][1] found <- sort(colnames(x)[colnames(x) %like% "^(specimen date|specimen_date|spec_date)"])[1]
if (!any(class(pull(x, found)) %in% c("Date", "POSIXct"))) { if (!any(class(pull(x, found)) %in% c("Date", "POSIXct"))) {
stop(font_red(paste0("ERROR: Found column `", font_bold(found), "` to be used as input for `col_", type, stop(font_red(paste0("ERROR: Found column `", font_bold(found), "` to be used as input for `col_", type,
"`, but this column contains no valid dates. Transform its values to valid dates first.")), "`, but this column contains no valid dates. Transform its values to valid dates first.")),
call. = FALSE) call. = FALSE)
} }
} else { } else if (any(sapply(x, function(x) inherits(x, c("Date", "POSIXct"))))) {
for (i in seq_len(ncol(x))) { found <- sort(colnames(x)[sapply(x, function(x) inherits(x, c("Date", "POSIXct")))])[1]
if (any(class(pull(x, i)) %in% c("Date", "POSIXct"))) {
found <- colnames(x)[i]
break
}
}
} }
} }
# -- patient id # -- patient id
if (type == "patient_id") { if (type == "patient_id") {
if (any(colnames(x) %like% "^(identification |patient|patid)")) { if (any(colnames(x) %like% "^(identification |patient|patid)")) {
found <- colnames(x)[colnames(x) %like% "^(identification |patient|patid)"][1] found <- sort(colnames(x)[colnames(x) %like% "^(identification |patient|patid)"])[1]
} }
} }
# -- specimen # -- specimen
if (type == "specimen") { if (type == "specimen") {
if (any(colnames(x) %like% "(specimen type|spec_type)")) { if (any(colnames(x) %like% "(specimen type|spec_type)")) {
found <- colnames(x)[colnames(x) %like% "(specimen type|spec_type)"][1] found <- sort(colnames(x)[colnames(x) %like% "(specimen type|spec_type)"])[1]
} else if (any(colnames(x) %like% "^(specimen)")) { } else if (any(colnames(x) %like% "^(specimen)")) {
found <- colnames(x)[colnames(x) %like% "^(specimen)"][1] found <- sort(colnames(x)[colnames(x) %like% "^(specimen)"])[1]
} }
} }
# -- UTI (urinary tract infection) # -- UTI (urinary tract infection)
@ -164,13 +159,13 @@ search_type_in_df <- function(x, type) {
if (any(colnames(x) == "uti")) { if (any(colnames(x) == "uti")) {
found <- colnames(x)[colnames(x) == "uti"][1] found <- colnames(x)[colnames(x) == "uti"][1]
} else if (any(colnames(x) %like% "(urine|urinary)")) { } else if (any(colnames(x) %like% "(urine|urinary)")) {
found <- colnames(x)[colnames(x) %like% "(urine|urinary)"][1] found <- sort(colnames(x)[colnames(x) %like% "(urine|urinary)"])[1]
} }
if (!is.null(found)) { if (!is.null(found)) {
# this column should contain logicals # this column should contain logicals
if (!is.logical(x[, found, drop = TRUE])) { if (!is.logical(x[, found, drop = TRUE])) {
message(font_red(paste0("NOTE: Column `", font_bold(found), "` found as input for `col_", type, message(font_red(paste0("NOTE: Column `", font_bold(found), "` found as input for `col_", type,
"`, but this column does not contain 'logical' values (TRUE/FALSE) and was ignored."))) "`, but this column does not contain 'logical' values (TRUE/FALSE) and was ignored.")))
found <- NULL found <- NULL
} }
} }

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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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-1209005" class="section level1"> <div id="amr-1209006" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9005"> <h1 class="page-header" data-toc-text="1.2.0.9006">
<a href="#amr-1209005" class="anchor"></a>AMR 1.2.0.9005<small> Unreleased </small> <a href="#amr-1209006" class="anchor"></a>AMR 1.2.0.9006<small> Unreleased </small>
</h1> </h1>
<div id="last-updated-09-jun-2020" class="section level2"> <div id="last-updated-11-jun-2020" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-09-jun-2020" class="anchor"></a><small>Last updated: 09-Jun-2020</small> <a href="#last-updated-11-jun-2020" class="anchor"></a><small>Last updated: 11-Jun-2020</small>
</h2> </h2>
<div id="changed" class="section level3"> <div id="changed" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -250,6 +250,8 @@
<li>Added official antimicrobial names to all <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code> functions, such as <code><a href="../reference/filter_ab_class.html">filter_aminoglycosides()</a></code> <li>Added official antimicrobial names to all <code><a href="../reference/filter_ab_class.html">filter_ab_class()</a></code> functions, such as <code><a href="../reference/filter_ab_class.html">filter_aminoglycosides()</a></code>
</li> </li>
<li>Added antibiotics code “FOX1” for cefoxitin screening (abbreviation “cfsc”) to the <code>antibiotics</code> data set</li> <li>Added antibiotics code “FOX1” for cefoxitin screening (abbreviation “cfsc”) to the <code>antibiotics</code> data set</li>
<li>Improved auto-determination for columns of types <mo> and <date></date></mo>
</li>
</ul> </ul>
</div> </div>
</div> </div>

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-09T14:30Z last_built: 2020-06-11T17:56Z
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.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</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.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9006</span>
</span> </span>
</div> </div>