From 04d49a62afe65ecd256e7723e77140e317a16cc9 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Thu, 15 Aug 2019 17:09:27 +0200 Subject: [PATCH] (v0.7.1.9057) get_column_abx() improvement --- DESCRIPTION | 4 ++-- NEWS.md | 3 ++- R/guess_ab_col.R | 28 +++++++++++----------------- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 9 +++++---- docs/reference/first_isolate.html | 4 ++-- docs/reference/index.html | 2 +- docs/reference/key_antibiotics.html | 4 ++-- tests/testthat/test-misc.R | 4 ++-- 12 files changed, 31 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f5e0783c..f7787964 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9056 -Date: 2019-08-14 +Version: 0.7.1.9057 +Date: 2019-08-15 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 7a95044b..c43f1c52 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9056 +# AMR 0.7.1.9057 ### Breaking * Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too. @@ -46,6 +46,7 @@ * Printed info now distinguishes between added and changes values * Using Verbose mode (i.e. `eucast_rules(..., verbose = TRUE)`) returns more informative and readable output * Using factors as input now adds missing factors levels when the function changes antibiotic results +* Improved the internal auto-guessing function for determining antibiotics in your data set (`AMR:::get_column_abx()`) * Added tibble printing support for classes `rsi`, `mic`, `disk`, `ab` `mo`. When using tibbles containing antibiotic columns, values `S` will print in green, values `I` will print in yellow and values `R` will print in red. Microbial IDs (class `mo`) will emphasise on the genus and species, not on the kingdom. ```r # (run this on your own console, as this page does not support colour printing) diff --git a/R/guess_ab_col.R b/R/guess_ab_col.R index d2b347b4..a642da8b 100755 --- a/R/guess_ab_col.R +++ b/R/guess_ab_col.R @@ -148,27 +148,21 @@ get_column_abx <- function(x, } # sort on name - x <- x[sort(names(x))] - dupes <- x[base::duplicated(x)] - + x <- x[order(names(x), x)] + duplicates <- x[base::duplicated(x)] + x <- x[!names(x) %in% names(duplicates)] + if (verbose == TRUE) { for (i in 1:length(x)) { - if (x[i] %in% dupes) { - message(red(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i], - "` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ") [DUPLICATED USE]."))) - } else { - message(blue(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i], - "` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ")."))) - } + message(blue(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i], + "` (", ab_name(names(x)[i], tolower = TRUE), ")."))) } - } - - if (n_distinct(x) != length(x)) { - msg_txt <- paste("Column(s)", paste0("`", dupes, "`", collapse = " and "), "used for more than one antibiotic.") - if (verbose == FALSE) { - msg_txt <- paste(msg_txt, "Use verbose = TRUE to see which antibiotics are used by which columns.") + } else if (length(duplicates) > 0) { + for (i in 1:length(duplicates)) { + warning(red(paste0("Using column `", bold(duplicates[i]), "` as input for `", names(x[which(x == duplicates[i])]), + "` (", ab_name(names(x[names(which(x == duplicates))[i]]), tolower = TRUE), + "), although it was matched for multiple antibiotics or columns.")), call. = FALSE) } - stop(msg_txt, call. = FALSE) } if (!is.null(hard_dependencies)) { diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 99df50d3..2c74e00c 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9056 + 0.7.1.9057 diff --git a/docs/articles/index.html b/docs/articles/index.html index ccc04821..a47c52ae 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9056 + 0.7.1.9057 diff --git a/docs/authors.html b/docs/authors.html index 83e42092..dd7017a8 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9056 + 0.7.1.9057 diff --git a/docs/index.html b/docs/index.html index c6612322..11e54661 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9056 + 0.7.1.9057 diff --git a/docs/news/index.html b/docs/news/index.html index 73f88c11..601160b1 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9056 + 0.7.1.9057 @@ -225,9 +225,9 @@ -
+

-AMR 0.7.1.9056 Unreleased +AMR 0.7.1.9057 Unreleased

@@ -288,6 +288,7 @@
  • Using factors as input now adds missing factors levels when the function changes antibiotic results
  • +
  • Improved the internal auto-guessing function for determining antibiotics in your data set (AMR:::get_column_abx())
  • Added tibble printing support for classes rsi, mic, disk, ab mo. When using tibbles containing antibiotic columns, values S will print in green, values I will print in yellow and values R will print in red. Microbial IDs (class mo) will emphasise on the genus and species, not on the kingdom.

    # (run this on your own console, as this page does not support colour printing)
    @@ -1237,7 +1238,7 @@ Using as.mo(..., allow_uncertain = 3)
           

    Contents

    @@ -476,7 +476,7 @@ To conduct an analysis of antimicrobial resistance, you should only include the
  • @@ -388,7 +388,7 @@