From fdf29e6c5b902db41346a931e25d9671f64966f1 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Thu, 3 Dec 2020 22:30:14 +0100 Subject: [PATCH] (v1.4.0.9031) as.ab() fix --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/ab.R | 6 ++++-- R/eucast_rules.R | 11 ++++++++--- R/mo_property.R | 8 ++++++++ docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 17 +++++++++-------- docs/pkgdown.yml | 2 +- docs/reference/guess_ab_col.html | 2 +- docs/reference/index.html | 2 +- docs/survey.html | 2 +- 15 files changed, 41 insertions(+), 24 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9d2d9dbe1..d87df6de8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.4.0.9030 +Version: 1.4.0.9031 Date: 2020-12-03 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 3f0143480..756fb329e 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.4.0.9030 +# AMR 1.4.0.9031 ## Last updated: 3 December 2020 ### New @@ -32,6 +32,7 @@ * `as.rsi()` on a data.frame will not print a message anymore if the values are already clean R/SI values * Fixed a bug where `mo_uncertainties()` would not return the results based on the MO matching score * Fixed a bug where `as.mo()` would not return results for known laboratory codes for microorganisms +* Fixed a bug where `as.ab()` would sometimes fail ### Other * All messages and warnings thrown by this package now break sentences on whole words diff --git a/R/ab.R b/R/ab.R index cd9192cc1..a9e2d4e86 100755 --- a/R/ab.R +++ b/R/ab.R @@ -153,7 +153,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = TRUE, ...) { } if (isTRUE(flag_multiple_results) & x[i] %like% "[ ]") { - from_text <- suppressWarnings(ab_from_text(x[i], initial_search = FALSE, translate_ab = FALSE)[[1]]) + from_text <- tryCatch(suppressWarnings(ab_from_text(x[i], initial_search = FALSE, translate_ab = FALSE)[[1]]), + error = function(e) character(0)) } else { from_text <- character(0) } @@ -345,7 +346,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = TRUE, ...) { if (isTRUE(flag_multiple_results)) { found <- from_text[1L] } else { - found <- suppressWarnings(ab_from_text(x[i], initial_search = FALSE, translate_ab = FALSE)[[1]][1L]) + found <- tryCatch(suppressWarnings(ab_from_text(x[i], initial_search = FALSE, translate_ab = FALSE)[[1]][1L]), + error = function(e) NA_character_) } if (!is.na(found)) { x_new[i] <- note_if_more_than_one_found(found, i, from_text) diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 5a9fa5dcf..163ddd787 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -38,12 +38,17 @@ EUCAST_VERSION_EXPERT_RULES <- list("3.1" = list(version_txt = "v3.1", title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'", url = "https://www.eucast.org/expert_rules_and_intrinsic_resistance/")) -format_eucast_version_nr <- function(version) { +format_eucast_version_nr <- function(version, markdown = TRUE) { # for documentation - adds title, version number, year and url in markdown language lst <- c(EUCAST_VERSION_BREAKPOINTS, EUCAST_VERSION_EXPERT_RULES) version <- format(version, nsmall = 1) - paste0("[", lst[[version]]$title, " ", lst[[version]]$version_txt, "](", lst[[version]]$url, ")", - " from ", lst[[version]]$year) + if (markdown == TRUE) { + paste0("[", lst[[version]]$title, " ", lst[[version]]$version_txt, "](", lst[[version]]$url, ")", + " from ", lst[[version]]$year) + } else { + paste0(lst[[version]]$title, " ", lst[[version]]$version_txt, + " from ", lst[[version]]$year) + } } #' Apply EUCAST rules diff --git a/R/mo_property.R b/R/mo_property.R index e88e8a822..23842286f 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -386,6 +386,14 @@ mo_is_intrinsic_resistant <- function(x, ab, language = get_locale(), ...) { stop_("length of `x` and `ab` must be equal, or one of them must be of length 1.") } + # show used version number once per session + if (is.null(getOption("AMR_intrinsic_resistance_note", NULL))) { + message_("Determining intrinsic resistance based on ", + AMR:::format_eucast_version_nr(3.2, FALSE), ". ", + font_bold("This message is shown once per session.")) + options(AMR_intrinsic_resistance_note = "shown") + } + # this saves about 50% in calculation time intrinsic_to_check <- intrinsic_resistant[which(intrinsic_resistant$microorganism %in% x | intrinsic_resistant$antibiotic %in% ab), , drop = FALSE] diff --git a/docs/404.html b/docs/404.html index 37052d8df..5562eea2a 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index fd0428c5b..cde8c1a84 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 diff --git a/docs/articles/index.html b/docs/articles/index.html index 8b3e7c781..ff62373d1 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 diff --git a/docs/authors.html b/docs/authors.html index ec3209170..7628ecd8f 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 diff --git a/docs/index.html b/docs/index.html index b86ab0048..07ad307f7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 diff --git a/docs/news/index.html b/docs/news/index.html index df543dd86..acfbb1f38 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

-AMR 1.4.0.9030 Unreleased +
+

+AMR 1.4.0.9031 Unreleased

@@ -252,21 +252,21 @@

Function is_new_episode() to determine patient episodes which are not necessarily based on microorganisms. It also supports grouped variables with e.g. mutate(), filter() and summarise() of the dplyr package:

 example_isolates %>%
-  group_by(patient_id, hospital_id) %>%
-  filter(is_new_episode(date, episode_days = 60))
+ group_by(patient_id, hospital_id) %>% + filter(is_new_episode(date, episode_days = 60))

  • Functions mo_is_gram_negative() and mo_is_gram_positive() as wrappers around mo_gramstain(). They always return TRUE or FALSE (except when the input is NA or the MO code is UNKNOWN), thus always return FALSE for species outside the taxonomic kingdom of Bacteria. They can even determine the column with microorganisms themselves when used inside dplyr verbs:

     example_isolates %>%
    -  filter(mo_is_gram_positive())
    +  filter(mo_is_gram_positive())
     #> NOTE: Using column `mo` as input for mo_is_gram_positive()
  • Function mo_is_intrinsic_resistant() to test for intrinsic resistance, based on EUCAST Intrinsic Resistance and Unusual Phenotypes v3.2 from 2020. As with the new mo_is_gram_*() functions, if you have the dplyr package installed the column with microorganisms will be automatically determined when used inside dplyr verbs:

     example_isolates %>%
    -  filter(mo_is_intrinsic_resistant(ab = "Vancomycin"))
    +  filter(mo_is_intrinsic_resistant(ab = "Vancomycin"))
     #> NOTE: Using column `mo` as input for mo_is_intrinsic_resistant()
  • @@ -286,6 +286,7 @@ as.rsi() on a data.frame will not print a message anymore if the values are already clean R/SI values
  • Fixed a bug where mo_uncertainties() would not return the results based on the MO matching score
  • Fixed a bug where as.mo() would not return results for known laboratory codes for microorganisms
  • +
  • Fixed a bug where as.ab() would sometimes fail
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 1077154ec..5ea3ce6dc 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: datasets: datasets.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2020-12-03T15:56Z +last_built: 2020-12-03T21:21Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/guess_ab_col.html b/docs/reference/guess_ab_col.html index f532361bf..95f06241d 100644 --- a/docs/reference/guess_ab_col.html +++ b/docs/reference/guess_ab_col.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031
    diff --git a/docs/reference/index.html b/docs/reference/index.html index 71f65c2c1..7d4d77c0f 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031

    diff --git a/docs/survey.html b/docs/survey.html index 130a06645..6751d3237 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9030 + 1.4.0.9031