1
0
mirror of https://github.com/msberends/AMR.git synced 2025-04-19 08:33:49 +02:00

(v2.1.1.9160) cleanup

This commit is contained in:
dr. M.S. (Matthijs) Berends 2025-02-26 20:28:33 +01:00
parent 0c3ea4b538
commit 22e66741cc
No known key found for this signature in database
13 changed files with 38 additions and 50 deletions

View File

@ -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

View File

@ -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)

View File

@ -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).)*

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -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',

23
R/ab.R
View File

@ -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()
}
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,12 +384,11 @@ 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,
@ -407,7 +399,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
stringsAsFactors = FALSE
)
))
}
# take failed ATC codes apart from rest
if (length(x_unknown_ATCs) > 0 && fast_mode == FALSE) {

View File

@ -69,11 +69,8 @@
#' @export
#' @examples
#' \donttest{
#'
#' # returns NA and throws a warning (which is suppressed here):
#' suppressWarnings(
#' # 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.")
}

View File

@ -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 youre at.
First and foremost, you are trained on version 2.1.1.9160. Remember this whenever someone asks which AMR package version youre 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(
# 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"),

View File

@ -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(
# 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"),

View File

@ -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: