diff --git a/.github/workflows/lintr.yaml b/.github/workflows/lintr.yaml index 982e789a7..595c2cdfd 100644 --- a/.github/workflows/lintr.yaml +++ b/.github/workflows/lintr.yaml @@ -53,7 +53,9 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::lintr + extra-packages: | + any::lintr + any::cyclocomp - name: Lint run: | @@ -63,6 +65,7 @@ jobs: linters <- sort(linters[grepl("_linter$", linters)]) # lose deprecated linters <- linters[!grepl("^(closed_curly|open_curly|paren_brace|semicolon_terminator|consecutive_stopifnot|no_tab|single_quotes|unnecessary_nested_if|unneeded_concatenation)_linter$", linters)] + linters <- linters[linters != "linter"] # and the ones we find unnnecessary linters <- linters[!grepl("^(extraction_operator|implicit_integer|line_length|object_name|nonportable_path|is)_linter$", linters)] # put the functions in a list diff --git a/DESCRIPTION b/DESCRIPTION index 4f68d510f..834f6473e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.1.1.9159 +Version: 2.1.1.9160 Date: 2025-02-26 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 0e8dbb204..ab9fda8ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9159 +# AMR 2.1.1.9160 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)* diff --git a/PythonPackage/AMR/AMR.egg-info/PKG-INFO b/PythonPackage/AMR/AMR.egg-info/PKG-INFO index f7b2915db..a33a88066 100644 --- a/PythonPackage/AMR/AMR.egg-info/PKG-INFO +++ b/PythonPackage/AMR/AMR.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.2 Name: AMR -Version: 2.1.1.9159 +Version: 2.1.1.9160 Summary: A Python wrapper for the AMR R package Home-page: https://github.com/msberends/AMR Author: Matthijs Berends diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9159.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9159.tar.gz deleted file mode 100644 index a9af2aaaf..000000000 Binary files a/PythonPackage/AMR/dist/amr-2.1.1.9159.tar.gz and /dev/null differ diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9159-py3-none-any.whl b/PythonPackage/AMR/dist/amr-2.1.1.9160-py3-none-any.whl similarity index 85% rename from PythonPackage/AMR/dist/amr-2.1.1.9159-py3-none-any.whl rename to PythonPackage/AMR/dist/amr-2.1.1.9160-py3-none-any.whl index 3b32c5035..f206d1fe1 100644 Binary files a/PythonPackage/AMR/dist/amr-2.1.1.9159-py3-none-any.whl and b/PythonPackage/AMR/dist/amr-2.1.1.9160-py3-none-any.whl differ diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9160.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9160.tar.gz new file mode 100644 index 000000000..dd3413f0a Binary files /dev/null and b/PythonPackage/AMR/dist/amr-2.1.1.9160.tar.gz differ diff --git a/PythonPackage/AMR/setup.py b/PythonPackage/AMR/setup.py index 6b1854d9e..ce79c3a09 100644 --- a/PythonPackage/AMR/setup.py +++ b/PythonPackage/AMR/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='AMR', - version='2.1.1.9159', + version='2.1.1.9160', packages=find_packages(), install_requires=[ 'rpy2', diff --git a/R/ab.R b/R/ab.R index c1505b79a..9473bea9e 100755 --- a/R/ab.R +++ b/R/ab.R @@ -106,10 +106,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), )) } - loop_time <- list(...)$loop_time - if (is.null(loop_time)) { - loop_time <- 1 - } already_regex <- isTRUE(list(...)$already_regex) fast_mode <- isTRUE(list(...)$fast_mode) @@ -134,8 +130,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), x_unknown_ATCs <- character(0) note_if_more_than_one_found <- function(found, index, from_text) { - if (loop_time == 1 && isTRUE(length(from_text) > 1)) { - abnames <- ab_name(from_text, tolower = TRUE, loop_time = loop_time + 1) + if (isTRUE(length(from_text) > 1)) { + abnames <- ab_name(from_text, tolower = TRUE) if (ab_name(found[1L], language = NULL) %like% "(clavulanic acid|(avi|tazo|mono|vabor)bactam)") { abnames <- abnames[!abnames %in% c("clavulanic acid", "avibactam", "tazobactam", "vaborbactam", "monobactam")] } @@ -190,15 +186,13 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), x_new[is.na(x)] <- NA already_known[is.na(x)] <- FALSE - if (loop_time == 1 && sum(already_known) < length(x)) { + if (sum(already_known) < length(x)) { progress <- progress_ticker(n = sum(!already_known), n_min = 25, print = info) # start if n >= 25 on.exit(close(progress)) } for (i in which(!already_known)) { - if (loop_time == 1) { - progress$tick() - } + progress$tick() if (is.na(x[i]) || is.null(x[i])) { next @@ -218,7 +212,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), } if (fast_mode == FALSE && flag_multiple_results == TRUE && x[i] %like% "[ ]") { - from_text <- tryCatch(suppressWarnings(ab_from_text(x[i], loop_time = loop_time + 1, translate_ab = FALSE)[[1]]), + from_text <- tryCatch(suppressWarnings(ab_from_text(x[i], translate_ab = FALSE)[[1]]), error = function(e) character(0) ) } else { @@ -331,9 +325,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), next } - # INITIAL SEARCH - More uncertain results ---- - if (loop_time == 1 && fast_mode == FALSE) { - # only run on first and second try + # More uncertain results ---- + if (fast_mode == FALSE) { ab_df <- AMR_env$AB_lookup ab_df$length_name <- nchar(ab_df$generalised_name) @@ -391,23 +384,21 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(), x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1]) } - if (loop_time == 1 && sum(already_known) < length(x)) { + if (sum(already_known) < length(x)) { close(progress) } # save to package env to save time for next time - if (loop_time == 1) { - AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$x %in% x), , drop = FALSE] - AMR_env$ab_previously_coerced <- unique(rbind_AMR( - AMR_env$ab_previously_coerced, - data.frame( - x = x, - ab = x_new, - x_bak = x_bak[match(x, x_bak_clean)], - stringsAsFactors = FALSE - ) - )) - } + AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$x %in% x), , drop = FALSE] + AMR_env$ab_previously_coerced <- unique(rbind_AMR( + AMR_env$ab_previously_coerced, + data.frame( + x = x, + ab = x_new, + x_bak = x_bak[match(x, x_bak_clean)], + stringsAsFactors = FALSE + ) + )) # take failed ATC codes apart from rest if (length(x_unknown_ATCs) > 0 && fast_mode == FALSE) { diff --git a/R/custom_antimicrobials.R b/R/custom_antimicrobials.R index 661d792e1..c8b611cd0 100755 --- a/R/custom_antimicrobials.R +++ b/R/custom_antimicrobials.R @@ -69,11 +69,8 @@ #' @export #' @examples #' \donttest{ -#' -#' # returns NA and throws a warning (which is suppressed here): -#' suppressWarnings( -#' as.ab("testab") -#' ) +#' # returns a wildly guessed result: +#' as.ab("testab") #' #' # now add a custom entry - it will be considered by as.ab() and #' # all ab_*() functions @@ -109,6 +106,7 @@ #' ab_name("J01CR50") #' #' # even antimicrobial selectors work +#' # see ?amr_selector #' x <- data.frame( #' random_column = "some value", #' coflu = as.sir("S"), @@ -155,7 +153,7 @@ add_custom_antimicrobials <- function(x) { } AMR_env$AB_lookup <- unique(rbind_AMR(AMR_env$AB_lookup, new_df)) - AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% x$ab), , drop = FALSE] + AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% c(x$ab, x$generalised_name) & !AMR_env$ab_previously_coerced$x %in% c(x$ab, x$generalised_name)), , drop = FALSE] class(AMR_env$AB_lookup$ab) <- c("ab", "character") message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antibiotics` data set.") } diff --git a/data-raw/gpt_training_text_v2.1.1.9159.txt b/data-raw/gpt_training_text_v2.1.1.9160.txt similarity index 99% rename from data-raw/gpt_training_text_v2.1.1.9159.txt rename to data-raw/gpt_training_text_v2.1.1.9160.txt index deffcfe6d..7a14eb64c 100644 --- a/data-raw/gpt_training_text_v2.1.1.9159.txt +++ b/data-raw/gpt_training_text_v2.1.1.9160.txt @@ -1,6 +1,6 @@ This knowledge base contains all context you must know about the AMR package for R. You are a GPT trained to be an assistant for the AMR package in R. You are an incredible R specialist, especially trained in this package and in the tidyverse. -First and foremost, you are trained on version 2.1.1.9159. Remember this whenever someone asks which AMR package version you’re at. +First and foremost, you are trained on version 2.1.1.9160. Remember this whenever someone asks which AMR package version you’re at. Below are the contents of the file, the file, and all the files (documentation) in the package. Every file content is split using 100 hypens. ---------------------------------------------------------------------------------------------------- @@ -1324,11 +1324,8 @@ Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to } \examples{ \donttest{ - -# returns NA and throws a warning (which is suppressed here): -suppressWarnings( - as.ab("testab") -) +# returns a wildly guessed result: +as.ab("testab") # now add a custom entry - it will be considered by as.ab() and # all ab_*() functions @@ -1364,6 +1361,7 @@ ab_atc("Co-fluampicil") ab_name("J01CR50") # even antimicrobial selectors work +# see ?amr_selector x <- data.frame( random_column = "some value", coflu = as.sir("S"), diff --git a/man/add_custom_antimicrobials.Rd b/man/add_custom_antimicrobials.Rd index 839b953b2..85c0625b1 100644 --- a/man/add_custom_antimicrobials.Rd +++ b/man/add_custom_antimicrobials.Rd @@ -50,11 +50,8 @@ Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to } \examples{ \donttest{ - -# returns NA and throws a warning (which is suppressed here): -suppressWarnings( - as.ab("testab") -) +# returns a wildly guessed result: +as.ab("testab") # now add a custom entry - it will be considered by as.ab() and # all ab_*() functions @@ -90,6 +87,7 @@ ab_atc("Co-fluampicil") ab_name("J01CR50") # even antimicrobial selectors work +# see ?amr_selector x <- data.frame( random_column = "some value", coflu = as.sir("S"), diff --git a/tests/testthat/test-amr_selectors.R b/tests/testthat/test-amr_selectors.R index f452d0d19..5d2071807 100644 --- a/tests/testthat/test-amr_selectors.R +++ b/tests/testthat/test-amr_selectors.R @@ -59,7 +59,7 @@ expect_equal(ncol(example_isolates[, tetracyclines(), drop = FALSE]), 3, toleran expect_equal(ncol(example_isolates[, trimethoprims(), drop = FALSE]), 2, tolerance = 0.5) expect_equal(ncol(example_isolates[, ureidopenicillins(), drop = FALSE]), 1, tolerance = 0.5) -expect_message(carbapenems()) +expect_message(expect_stdout(print(carbapenems()))) expect_error(administrable_per_os()) # Examples: