diff --git a/DESCRIPTION b/DESCRIPTION
index f51edcf7..2f8fe91d 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: AMR
-Version: 1.2.0.9005
-Date: 2020-06-09
+Version: 1.2.0.9006
+Date: 2020-06-11
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),
diff --git a/NEWS.md b/NEWS.md
index f0eb7c52..dd1ee8a2 100755
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,5 @@
-# AMR 1.2.0.9005
-## Last updated: 09-Jun-2020
+# AMR 1.2.0.9006
+## Last updated: 11-Jun-2020
### Changed
* 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 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
+* Improved auto-determination for columns of types and
# AMR 1.2.0
diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R
index 8c926c2f..b947fd77 100755
--- a/R/aa_helper_functions.R
+++ b/R/aa_helper_functions.R
@@ -103,60 +103,55 @@ search_type_in_df <- function(x, type) {
# -- mo
if (type == "mo") {
- if ("mo" %in% lapply(x, class)) {
- found <- colnames(x)[lapply(x, class) == "mo"][1]
+ if (any(sapply(x, is.mo))) {
+ found <- sort(colnames(x)[sapply(x, is.mo)])[1]
} else if ("mo" %in% colnames(x) &
suppressWarnings(
all(x$mo %in% c(NA,
microorganisms$mo,
microorganisms.translation$mo_old)))) {
found <- "mo"
- } else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria|bacterie)s?$")) {
- found <- colnames(x)[colnames(x) %like% "^(mo|microorganism|organism|bacteria|bacterie)s?$"][1]
- } else if (any(colnames(x) %like% "^(microorganism|organism|bacteria|bacterie)")) {
- found <- colnames(x)[colnames(x) %like% "^(microorganism|organism|bacteria|bacterie)"][1]
+ } else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria|ba[ck]terie)s?$")) {
+ 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|ba[ck]terie)")) {
+ found <- sort(colnames(x)[colnames(x) %like% "^(microorganism|organism|bacteria|ba[ck]terie)"])[1]
} 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
if (type == "keyantibiotics") {
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
if (type == "date") {
if (any(colnames(x) %like% "^(specimen date|specimen_date|spec_date)")) {
# 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"))) {
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)
}
- } else {
- for (i in seq_len(ncol(x))) {
- if (any(class(pull(x, i)) %in% c("Date", "POSIXct"))) {
- found <- colnames(x)[i]
- break
- }
- }
+ } else if (any(sapply(x, function(x) inherits(x, c("Date", "POSIXct"))))) {
+ found <- sort(colnames(x)[sapply(x, function(x) inherits(x, c("Date", "POSIXct")))])[1]
}
}
# -- patient id
if (type == "patient_id") {
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
if (type == "specimen") {
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)")) {
- found <- colnames(x)[colnames(x) %like% "^(specimen)"][1]
+ found <- sort(colnames(x)[colnames(x) %like% "^(specimen)"])[1]
}
}
# -- UTI (urinary tract infection)
@@ -164,13 +159,13 @@ search_type_in_df <- function(x, type) {
if (any(colnames(x) == "uti")) {
found <- colnames(x)[colnames(x) == "uti"][1]
} 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)) {
# this column should contain logicals
if (!is.logical(x[, found, drop = TRUE])) {
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
}
}
diff --git a/docs/404.html b/docs/404.html
index ab132b94..a674a1f9 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index e281e91f..b08bef1a 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 9a1e44dc..cbd03f55 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
diff --git a/docs/authors.html b/docs/authors.html
index bffcaf94..ed6ba49f 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
diff --git a/docs/index.html b/docs/index.html
index dabe1a1a..a4c8bb6f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -43,7 +43,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
diff --git a/docs/news/index.html b/docs/news/index.html
index 2e8a2ebb..e7000407 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -81,7 +81,7 @@
AMR (for R)
- 1.2.0.9005
+ 1.2.0.9006
@@ -229,13 +229,13 @@
Source: NEWS.md
-
-