diff --git a/DESCRIPTION b/DESCRIPTION index fd701a9e..d33399a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9092 -Date: 2019-10-04 +Version: 0.7.1.9093 +Date: 2019-10-06 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 3237ced7..7ec3c834 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9092 -Last updated: 04-Oct-2019 +# AMR 0.7.1.9093 +Last updated: 06-Oct-2019 ### 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`: @@ -94,7 +94,7 @@ * 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`. **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` * Function `eucast_rules()`: * Fixed a bug for *Yersinia pseudotuberculosis* diff --git a/R/ab.R b/R/ab.R index 2dd16249..0f4872ca 100755 --- a/R/ab.R +++ b/R/ab.R @@ -84,7 +84,7 @@ as.ab <- function(x, ...) { # keep only max 1 space x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean, ignore.case = TRUE)) # 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 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 next } - # now also try to coerce brandname combinations like "Amoxy/clavulanic acid" - x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"), - function(y) { - for (i in 1:length(y)) { - y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE)) - y[i] <- ifelse(!is.na(y_name), - y_name, - y[i]) - } - y - })[[1]], - collapse = "/") - x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) - if (!is.na(x_translated_guess)) { - x_new[i] <- x_translated_guess - next + + if (!isFALSE(list(...)$initial_search2)) { + # now also try to coerce brandname combinations like "Amoxy/clavulanic acid" + x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"), + function(y) { + for (i in 1:length(y)) { + y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE, initial_search2 = FALSE)) + y[i] <- ifelse(!is.na(y_name), + y_name, + y[i]) + } + y + })[[1]], + collapse = "/") + x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) + if (!is.na(x_translated_guess)) { + x_new[i] <- x_translated_guess + next + } } } diff --git a/R/atc_online.R b/R/atc_online.R index a7eddce6..c7f26160 100644 --- a/R/atc_online.R +++ b/R/atc_online.R @@ -76,7 +76,7 @@ atc_online_property <- function(atc_code, administration = 'O', 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") } diff --git a/R/misc.R b/R/misc.R index 3408f1ee..0f53d59e 100755 --- a/R/misc.R +++ b/R/misc.R @@ -153,8 +153,8 @@ round2 <- function(x, digits = 0, force_zero = TRUE) { # https://stackoverflow.com/a/12688836/4575331 val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x) if (digits > 0 & force_zero == TRUE) { - val[val != as.integer(val)] <- paste0(val[val != as.integer(val)], - strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", 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) & !is.na(val)]))))) } val } diff --git a/docs/404.html b/docs/404.html index 5df817b2..e98eb780 100644 --- a/docs/404.html +++ b/docs/404.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index d13acc85..4ef934f1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 diff --git a/docs/articles/index.html b/docs/articles/index.html index b5bbc7ce..d144aec7 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 diff --git a/docs/authors.html b/docs/authors.html index 106d680b..577e8afc 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 diff --git a/docs/index.html b/docs/index.html index 68a074cc..98fcca0b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 diff --git a/docs/news/index.html b/docs/news/index.html index ddf79212..2efc5dc9 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9092 + 0.7.1.9093 @@ -231,11 +231,11 @@ -
+

-AMR 0.7.1.9092 Unreleased +AMR 0.7.1.9093 Unreleased

-

Last updated: 04-Oct-2019

+

Last updated: 06-Oct-2019

Breaking

@@ -336,8 +336,7 @@ Since this is a major change, usage of the old also_single_tested w
  • 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.
  • -
  • 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
  • Function eucast_rules(): @@ -1290,7 +1289,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

  • diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index 271b8477..2ed7e488 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -23,11 +23,11 @@ context("data.R") test_that("data sets are valid", { # 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(class(microorganisms$mo), "mo") - + expect_identical(nrow(antibiotics), length(unique(antibiotics$ab))) + expect_identical(class(antibiotics$ab), "ab") + # check cross table reference expect_true(all(microorganisms.codes$mo %in% microorganisms$mo)) expect_true(all(example_isolates$mo %in% microorganisms$mo))