1
0
mirror of https://github.com/msberends/AMR.git synced 2026-03-07 15:35:20 +01:00

(v3.0.1.9026) fix ab_group(NA)

This commit is contained in:
2026-03-06 12:41:27 +01:00
parent 4e3ea95fbd
commit 60e8f2bae6
8 changed files with 41 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 3.0.1.9023 Version: 3.0.1.9026
Date: 2026-03-03 Date: 2026-03-06
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@@ -133,8 +133,10 @@ export("%like%")
export("%like_case%") export("%like_case%")
export("%unlike%") export("%unlike%")
export("%unlike_case%") export("%unlike_case%")
export(NA_ab_)
export(NA_disk_) export(NA_disk_)
export(NA_mic_) export(NA_mic_)
export(NA_mo_)
export(NA_sir_) export(NA_sir_)
export(ab_atc) export(ab_atc)
export(ab_atc_group1) export(ab_atc_group1)

View File

@@ -1,4 +1,4 @@
# AMR 3.0.1.9023 # AMR 3.0.1.9026
### New ### New
* Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes` * Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes`
@@ -9,13 +9,13 @@
- `all_disk()`, `all_disk_predictors()` - `all_disk()`, `all_disk_predictors()`
* Data set `esbl_isolates` to practise with AMR modelling * Data set `esbl_isolates` to practise with AMR modelling
* AMR selectors `peptides()`, `phosphonics()` and `spiropyrimidinetriones()` * AMR selectors `peptides()`, `phosphonics()` and `spiropyrimidinetriones()`
* Antimicrobials in the `antimicrobials` data set: ceftibuten/avibactam (`CTA`), kasugamycin (`KAS`), ostreogrycin (`OST`), thiostrepton (`THS`), xeruborbactam (`XER`), zorbamycin (`ZOR`)
* Support for Wildtype (WT) / Non-wildtype (NWT) in `as.sir()`, all plotting functions, and all susceptibility/resistance functions. * Support for Wildtype (WT) / Non-wildtype (NWT) in `as.sir()`, all plotting functions, and all susceptibility/resistance functions.
- `as.sir()` gained an argument `as_wt_nwt`, which defaults to `TRUE` only when `breakpoint_type = "ECOFF"` (#254) - `as.sir()` gained an argument `as_wt_nwt`, which defaults to `TRUE` only when `breakpoint_type = "ECOFF"` (#254)
- This transforms the output from S/R to WT/NWT - This transforms the output from S/R to WT/NWT
- Functions such as `susceptibility()` count WT as S and NWT as R - Functions such as `susceptibility()` count WT as S and NWT as R
* `interpretive_rules()`, which allows future implementation of CLSI interpretive rules (#235) * `interpretive_rules()`, which allows future implementation of CLSI interpretive rules (#235)
- `eucast_rules()` has become a wrapper around that function. - `eucast_rules()` has become a wrapper around that function
* Two new `NA` objects, `NA_ab_` and `NA_mo_`, analogous to base R's `NA_character_` and `NA_integer_`, for use in pipelines that require typed missing values
### Fixes ### Fixes
* Fixed a bug in `as.ab()` where certain AB codes containing "PH" or "TH" (such as `ETH`, `MTH`, `PHE`, `PHN`, `STH`, `THA`, `THI1`) would incorrectly return `NA` when combined in a vector with any untranslatable value (#245) * Fixed a bug in `as.ab()` where certain AB codes containing "PH" or "TH" (such as `ETH`, `MTH`, `PHE`, `PHN`, `STH`, `THA`, `THI1`) would incorrectly return `NA` when combined in a vector with any untranslatable value (#245)
@@ -31,7 +31,7 @@
* `as.mic()` and `rescale_mic()` gained the argument `round_to_next_log2`, which can be set to `TRUE` to round all values up to the nearest next log2 level (#255) * `as.mic()` and `rescale_mic()` gained the argument `round_to_next_log2`, which can be set to `TRUE` to round all values up to the nearest next log2 level (#255)
* `antimicrobials$group` is now a `list` instead of a `character`, to contain any group the drug is in (#246) * `antimicrobials$group` is now a `list` instead of a `character`, to contain any group the drug is in (#246)
* `ab_group()` gained an argument `all_groups` to return all groups the antimicrobial drug is in (#246) * `ab_group()` gained an argument `all_groups` to return all groups the antimicrobial drug is in (#246)
* Added taniborbactam (`TAN`) and cefepime/taniborbactam (`FTA`) to the `antimicrobials` data set * Added to the `antimicrobials` data set: cefepime/taniborbactam (`FTA`), ceftibuten/avibactam (`CTA`), kasugamycin (`KAS`), ostreogrycin (`OST`), taniborbactam (`TAN`), thiostrepton (`THS`), xeruborbactam (`XER`), and zorbamycin (`ZOR`)
* Added explaining message to `as.sir()` when interpreting numeric values (e.g., 1 for S, 2 for I, 3 for R) (#244) * Added explaining message to `as.sir()` when interpreting numeric values (e.g., 1 for S, 2 for I, 3 for R) (#244)
* Updated handling of capped MIC values (`<`, `<=`, `>`, `>=`) in `as.sir()` in the argument `capped_mic_handling`: (#243) * Updated handling of capped MIC values (`<`, `<=`, `>`, `>=`) in `as.sir()` in the argument `capped_mic_handling`: (#243)
* Introduced four clearly defined options: `"none"`, `"conservative"` (default), `"standard"`, and `"lenient"` * Introduced four clearly defined options: `"none"`, `"conservative"` (default), `"standard"`, and `"lenient"`

8
R/ab.R
View File

@@ -514,6 +514,14 @@ ab_reset_session <- function() {
} }
} }
#' @rdname as.ab
#' @details `NA_ab_` is a missing value of the new `ab` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
#' @format NULL
#' @export
NA_ab_ <- set_clean_class(NA_character_,
new_class = c("ab", "character")
)
# this prevents the requirement for putting the dependency in Imports: # this prevents the requirement for putting the dependency in Imports:
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(pillar::pillar_shaft, ab) #' @rawNamespace if(getRversion() >= "3.0.0") S3method(pillar::pillar_shaft, ab)
pillar_shaft.ab <- function(x, ...) { pillar_shaft.ab <- function(x, ...) {

View File

@@ -172,6 +172,9 @@ ab_group <- function(x, language = get_AMR_locale(), all_groups = FALSE, ...) {
grps <- ab_validate(x = x, property = "group", ...) grps <- ab_validate(x = x, property = "group", ...)
for (i in seq_along(grps)) { for (i in seq_along(grps)) {
if (is.null(grps[[i]]) || all(is.na(grps[[i]]))) {
grps[[i]] <- NA_character_
}
if (all_groups == FALSE) { if (all_groups == FALSE) {
# take the first match based on ABX_PRIORITY_LIST # take the first match based on ABX_PRIORITY_LIST
grps[[i]] <- grps[[i]][1] grps[[i]] <- grps[[i]][1]

8
R/mo.R
View File

@@ -623,6 +623,14 @@ mo_cleaning_regex <- function() {
) )
} }
#' @rdname as.mo
#' @details `NA_mo_` is a missing value of the new `mo` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
#' @format NULL
#' @export
NA_mo_ <- set_clean_class(NA_character_,
new_class = c("mo", "character")
)
# UNDOCUMENTED METHODS ---------------------------------------------------- # UNDOCUMENTED METHODS ----------------------------------------------------
# this prevents the requirement for putting the dependency in Imports: # this prevents the requirement for putting the dependency in Imports:

View File

@@ -1,10 +1,12 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ab.R % Please edit documentation in R/ab.R
\docType{data}
\name{as.ab} \name{as.ab}
\alias{as.ab} \alias{as.ab}
\alias{ab} \alias{ab}
\alias{is.ab} \alias{is.ab}
\alias{ab_reset_session} \alias{ab_reset_session}
\alias{NA_ab_}
\title{Transform Input to an Antibiotic ID} \title{Transform Input to an Antibiotic ID}
\usage{ \usage{
as.ab(x, flag_multiple_results = TRUE, language = get_AMR_locale(), as.ab(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
@@ -13,6 +15,8 @@ as.ab(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
is.ab(x) is.ab(x)
ab_reset_session() ab_reset_session()
NA_ab_
} }
\arguments{ \arguments{
\item{x}{A \link{character} vector to determine to antibiotic ID.} \item{x}{A \link{character} vector to determine to antibiotic ID.}
@@ -47,6 +51,8 @@ Use the \code{\link[=ab_property]{ab_*}} functions to get properties based on th
Note: the \code{\link[=as.ab]{as.ab()}} and \code{\link[=ab_property]{ab_*}} functions may use very long regular expression to match brand names of antimicrobial drugs. This may fail on some systems. Note: the \code{\link[=as.ab]{as.ab()}} and \code{\link[=ab_property]{ab_*}} functions may use very long regular expression to match brand names of antimicrobial drugs. This may fail on some systems.
You can add your own manual codes to be considered by \code{\link[=as.ab]{as.ab()}} and all \code{\link[=ab_property]{ab_*}} functions, see \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}}. You can add your own manual codes to be considered by \code{\link[=as.ab]{as.ab()}} and all \code{\link[=ab_property]{ab_*}} functions, see \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}}.
\code{NA_ab_} is a missing value of the new \code{ab} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
} }
\section{Source}{ \section{Source}{
@@ -111,3 +117,4 @@ if (require("dplyr")) {
\item \code{\link[=ab_from_text]{ab_from_text()}} for a function to retrieve antimicrobial drugs from clinical text (from health care records) \item \code{\link[=ab_from_text]{ab_from_text()}} for a function to retrieve antimicrobial drugs from clinical text (from health care records)
} }
} }
\keyword{datasets}

View File

@@ -1,5 +1,6 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mo.R % Please edit documentation in R/mo.R
\docType{data}
\name{as.mo} \name{as.mo}
\alias{as.mo} \alias{as.mo}
\alias{mo} \alias{mo}
@@ -9,6 +10,7 @@
\alias{mo_failures} \alias{mo_failures}
\alias{mo_reset_session} \alias{mo_reset_session}
\alias{mo_cleaning_regex} \alias{mo_cleaning_regex}
\alias{NA_mo_}
\title{Transform Arbitrary Input to Valid Microbial Taxonomy} \title{Transform Arbitrary Input to Valid Microbial Taxonomy}
\usage{ \usage{
as.mo(x, Becker = FALSE, Lancefield = FALSE, as.mo(x, Becker = FALSE, Lancefield = FALSE,
@@ -31,6 +33,8 @@ mo_failures()
mo_reset_session() mo_reset_session()
mo_cleaning_regex() mo_cleaning_regex()
NA_mo_
} }
\arguments{ \arguments{
\item{x}{A \link{character} vector or a \link{data.frame} with one or two columns.} \item{x}{A \link{character} vector or a \link{data.frame} with one or two columns.}
@@ -151,6 +155,8 @@ This is based on:
\item Lancefield RC (1933). \strong{A serological differentiation of human and other groups of hemolytic streptococci.} \emph{J Exp Med.} 57(4): 571-95; \doi{10.1084/jem.57.4.571} \item Lancefield RC (1933). \strong{A serological differentiation of human and other groups of hemolytic streptococci.} \emph{J Exp Med.} 57(4): 571-95; \doi{10.1084/jem.57.4.571}
} }
} }
\code{NA_mo_} is a missing value of the new \code{mo} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
} }
\section{Source}{ \section{Source}{
@@ -260,3 +266,4 @@ mo_is_intrinsic_resistant("ESCCOL", ab = "vanco")
The \code{\link[=mo_property]{mo_*}} functions (such as \code{\link[=mo_genus]{mo_genus()}}, \code{\link[=mo_gramstain]{mo_gramstain()}}) to get properties based on the returned code. The \code{\link[=mo_property]{mo_*}} functions (such as \code{\link[=mo_genus]{mo_genus()}}, \code{\link[=mo_gramstain]{mo_gramstain()}}) to get properties based on the returned code.
} }
\keyword{datasets}