From e9e3de44698ca61b8fcc05f7ca6b275734cbb8f0 Mon Sep 17 00:00:00 2001 From: Nick Thomson Date: Thu, 17 Jul 2025 23:15:52 +0800 Subject: [PATCH] (v3.0.0.9009) fix as.sir when uti = FALSE --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/sir.R | 33 +++++++++++++++------------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd143d099..92338a8c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 3.0.0.9008 +Version: 3.0.0.9009 Date: 2025-07-17 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 328620710..d9b5cbf59 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 3.0.0.9008 +# AMR 3.0.0.9009 This is primarily a bugfix release, though we added one nice feature too. @@ -13,6 +13,7 @@ This is primarily a bugfix release, though we added one nice feature too. * Fixed a bug in `as.ab()` for antimicrobial codes with a number in it if they are preceded by a space * Fixed a bug in `eucast_rules()` for using specific custom rules * Fixed a bug in `as.sir()` to allow any tidyselect language (#220) +* Fixed a bug in `as.sir()` to pick right breakpoint when `uti = FALSE` (#216) * Fixed a bug in `ggplot_sir()` when using `combine_SI = FALSE` (#213) * Fixed all plotting to contain a separate colour for SDD (susceptible dose-dependent) * Fixed some specific Dutch translations for antimicrobials diff --git a/R/sir.R b/R/sir.R index 5ed895d46..2cff56159 100755 --- a/R/sir.R +++ b/R/sir.R @@ -1656,26 +1656,23 @@ as_sir_method <- function(method_short, next } - # sort on host and taxonomic rank - # (this will e.g. prefer 'species' breakpoints over 'order' breakpoints) - if (is.na(uti_current)) { - breakpoints_current <- breakpoints_current %pm>% - # `uti` is a column in the data set - # this will put UTI = FALSE first, then UTI = NA, then UTI = TRUE - pm_mutate(uti_index = ifelse(!is.na(uti) & uti == FALSE, 1, - ifelse(is.na(uti), 2, - 3 - ) - )) %pm>% - # be as specific as possible (i.e. prefer species over genus): - pm_arrange(rank_index, uti_index) - } else if (uti_current == TRUE) { - breakpoints_current <- breakpoints_current %pm>% - subset(uti == TRUE) %pm>% - # be as specific as possible (i.e. prefer species over genus): - pm_arrange(rank_index) + # if the user explicitly set uti, keep only those rows + if (!is.na(uti_current)) { + breakpoints_current <- breakpoints_current[breakpoints_current$uti == uti_current, , drop = FALSE] } + # build a helper factor so FALSE < NA < TRUE + uti_index <- factor( + ifelse(is.na(breakpoints_current$uti), "NA", + as.character(breakpoints_current$uti) + ), + levels = c("FALSE", "NA", "TRUE") + ) + + # sort on host and taxonomic rank first, then by UTI + # (this will e.g. prefer 'species' breakpoints over 'order' breakpoints) + breakpoints_current <- breakpoints_current[order(breakpoints_current$rank_index, uti_index), , drop = FALSE] + # throw messages for different body sites site <- breakpoints_current[1L, "site", drop = FALSE] # this is the one we'll take if (is.na(site)) {