Skip to content

Commit

Permalink
(v2.1.1.9048) vctrs update for sir
Browse files Browse the repository at this point in the history
  • Loading branch information
msberends committed Jun 13, 2024
1 parent 3179216 commit de17de1
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: AMR
Version: 2.1.1.9047
Version: 2.1.1.9048
Date: 2024-06-13
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AMR 2.1.1.9047
# AMR 2.1.1.9048

*(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!)*

Expand Down
3 changes: 3 additions & 0 deletions R/aa_globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ globalVariables(c(
"microorganisms",
"microorganisms.codes",
"mo",
"n",
"name",
"new",
"numerator",
Expand All @@ -186,8 +187,10 @@ globalVariables(c(
"total",
"txt",
"type",
"uti_index",
"value",
"varname",
"x",
"xvar",
"y",
"year",
Expand Down
18 changes: 12 additions & 6 deletions R/sir.R
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,16 @@ as.sir.default <- function(x,
x[x.bak == 2] <- "I"
x[x.bak == 3] <- "R"
}
} else if (inherits(x.bak, "character") && all(x %in% c("1", "2", "3", "S", "SDD", "I", "R", "N", NA_character_))) {
} else if (inherits(x.bak, "character") && all(x %in% c("1", "2", "3", "S", "I", "R", NA_character_))) {
x[x.bak == "1"] <- "S"
x[x.bak == "2"] <- "I"
x[x.bak == "3"] <- "R"
} else if (inherits(x.bak, "character") && all(x %in% c("1", "2", "3", "4", "5", "S", "SDD", "I", "R", "N", NA_character_))) {
x[x.bak == "1"] <- "S"
x[x.bak == "2"] <- "SDD"
x[x.bak == "3"] <- "I"
x[x.bak == "4"] <- "R"
x[x.bak == "5"] <- "N"
} else if (!all(is.na(x)) && !identical(levels(x), c("S", "SDD", "I", "R", "N")) && !all(x %in% c("S", "SDD", "I", "R", "N", NA))) {
if (all(x %unlike% "(S|I|R)", na.rm = TRUE)) {
# check if they are actually MICs or disks
Expand Down Expand Up @@ -1133,7 +1139,7 @@ as_sir_method <- function(method_short,
if (all(uti_current == FALSE, na.rm = TRUE)) {
breakpoints_current <- breakpoints_current %pm>%
# this will put UTI = FALSE first, then UTI = NA, then UTI = TRUE
pm_mutate(uti_index = ifelse(uti == FALSE, 1,
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):
Expand Down Expand Up @@ -1170,22 +1176,22 @@ as_sir_method <- function(method_short,
} else {
site <- paste0("body site '", site, "'")
}
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti_current %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_coerced)) {
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti_current %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_current)) {
# only UTI breakpoints available
warning_("in `as.sir()`: interpretation of ", font_bold(ab_formatted), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms, thus assuming `uti = TRUE`. See `?as.sir`.")
rise_warning <- TRUE
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti_current)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_current, ab_coerced)) {
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti_current)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_current, ab_current)) {
# both UTI and Non-UTI breakpoints available
msgs <- c(msgs, paste0("Breakpoints for UTI ", font_bold("and"), " non-UTI available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, ". Use argument `uti` to set which isolates are from urine. See `?as.sir`."))
breakpoints_current <- breakpoints_current %pm>%
pm_filter(uti == FALSE)
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_current, ab_coerced)) {
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_current, ab_current)) {
# breakpoints for multiple body sites available
msgs <- c(msgs, paste0("Multiple breakpoints available for ", ab_formatted, " in ", mo_formatted, " - assuming ", site, "."))
}

# first check if mo is intrinsic resistant
if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_current, ab_coerced) %in% AMR_env$intrinsic_resistant) {
if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_current, ab_current) %in% AMR_env$intrinsic_resistant) {
msgs <- c(msgs, paste0("Intrinsic resistance applied for ", ab_formatted, " in ", mo_formatted, ""))
new_sir <- rep(as.sir("R"), length(rows))
} else if (nrow(breakpoints_current) == 0) {
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
7 changes: 5 additions & 2 deletions R/vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ vec_arith.mic <- function(op, x, y, ...) {

# S3: sir ----
vec_ptype2.sir.default <- function (x, y, ..., x_arg = "", y_arg = "") {
x
NA_sir_[0]
}
vec_ptype2.sir.sir <- function(x, y, ...) {
x
NA_sir_[0]
}
vec_ptype2.character.sir <- function(x, y, ...) {
NA_sir_[0]
}
vec_cast.character.sir <- function(x, to, ...) {
as.character(x)
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ AMR_env$sup_1_icon <- import_fn("symbol", "cli", error_on_fail = FALSE)$sup_1 %o
# S3: sir
s3_register("vctrs::vec_ptype2", "sir.default")
s3_register("vctrs::vec_ptype2", "sir.sir")
s3_register("vctrs::vec_ptype2", "character.sir")
s3_register("vctrs::vec_cast", "character.sir")
s3_register("vctrs::vec_cast", "sir.character")

Expand Down
2 changes: 1 addition & 1 deletion data-raw/ab.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3e7a1cbb21b49cdc7626ea3016a017cc
4e536434d1301bedaec0e856c74cded8
Binary file modified data-raw/antibiotics.dta
Binary file not shown.
Binary file modified data-raw/antibiotics.feather
Binary file not shown.
Binary file modified data-raw/antibiotics.rds
Binary file not shown.
Binary file modified data-raw/antibiotics.sav
Binary file not shown.
2 changes: 1 addition & 1 deletion data-raw/antibiotics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AMC" 23665637 "Amoxicillin/clavulanic acid" "Beta-lactams/penicillins" "J01CR02" "Beta-lactam antibacterials, penicillins" "Combinations of penicillins, incl. beta-lactamase inhibitors" "a/c,amcl,aml,aug,xl" "amocla,amoclan,amoclav,amoksiclav,amoxsiklav,amoxyclav,augmentan,augmentin,augmentin xr,augmentine,auspilic,clamentin,clamobit,clavamox,clavinex,clavoxilin plus,clavulin,clavumox,coamoxiclav,eumetinex,kmoxilin,spectramox,spektramox,synulox,viaclav,xiclav" 1.5 "g" 3 "g" ""
"AXS" 465441 "Amoxicillin/sulbactam" "Beta-lactams/penicillins" "NA" "" "" "55614-2,55615-9,55616-7"
"AMB" 5280965 "Amphotericin B" "Antifungals/antimycotics" "A01AB04,A07AA07,G01AA03,J02AA01" "Antimycotics for systemic use" "Antibiotics" "amf,amfb,amph" "abelcet,abelecet,ambisome,amfotericina b,amphocin,amphomoronal,amphortericin b,amphotec,amphotericin,amphotericin b,amphotericine b,amphotericinum b,amphozone,anfotericine b,fungilin,fungisome,fungisone,fungizone,halizon" 40 "mg" 210 "mg" "16370-9,18863-1,23-2,24-0,25-7,26-5,3353-0,3354-8,40707-2,40757-7,49859-2,6978-1"
"AMH" "Amphotericin B-high" "Aminoglycosides" "NA" "amfo b high,amhl,ampho b high,amphotericin high" "" ""
"AMH" "Amphotericin B-high" "Antifungals/antimycotics" "NA" "amfo b high,amhl,ampho b high,amphotericin high" "" ""
"AMP" 6249 "Ampicillin" "Beta-lactams/penicillins" "J01CA01,S01AA19" "Beta-lactam antibacterials, penicillins" "Penicillins with extended spectrum" "am,amp,ampi" "acillin,adobacillin,amblosin,amcill,amfipen,amfipen v,amipenix s,ampichel,ampicil,ampicilina,ampicillin,ampicillin a,ampicillin acid,ampicillin anhydrate,ampicillin anhydrous,ampicillin base,ampicillin hydrate,ampicillin sodium,ampicillina,ampicilline,ampicillinum,ampicin,ampifarm,ampikel,ampimed,ampipenin,ampiscel,ampisyn,ampivax,ampivet,amplacilina,amplin,amplipenyl,amplisom,amplital,anhydrous ampicillin,austrapen,binotal,bonapicillin,britacil,campicillin,copharcilin,delcillin,deripen,divercillin,doktacillin,duphacillin,grampenil,guicitrina,guicitrine,lifeampil,marcillin,morepen,norobrittin,nuvapen,olin kid,omnipen,orbicilina,pen a oral,pen ampil,penbristol,penbritin,penbritin paediatric,penbritin syrup,penbrock,penicline,penimic,pensyn,pentrex,pentrexl,pentrexyl,pentritin,pfizerpen a,polycillin,polyflex,ponecil,princillin,principen,qidamp,racenacillin,redicilin,rosampline,roscillin,semicillin,semicillin r,servicillin,sumipanto,synpenin,texcillin,tokiocillin,tolomol,totacillin,totalciclina,totapen,trifacilina,ukapen,ultrabion,ultrabron,vampen,viccillin,viccillin s,vidocillin,wypicil" 2 "g" 6 "g" "101477-8,101478-6,18864-9,18865-6,20374-5,21066-6,23618-2,27-3,28-1,29-9,30-7,31-5,32-3,33-1,3355-5,33562-0,33919-2,34-9,43883-8,43884-6,6979-9,6980-7,87604-5"
"SAM" 119561 "Ampicillin/sulbactam" "Beta-lactams/penicillins" "J01CR01" "Beta-lactam antibacterials, penicillins" "Combinations of penicillins, incl. beta-lactamase inhibitors" "a/s,ab,ams,amsu,apsu,sam" "sulacillin" 6 "g" "101478-6,18865-6,20374-5,23618-2,31-5,32-3,33-1,34-9,6980-7"
"AMR" 73341 "Amprolium" "Other antibacterials" "QP51BX02" "" "amprocidum,amprol,amprolio,amprolium,amprolium chloride,amprovine,thiacoccid" ""
Expand Down
Binary file modified data-raw/antibiotics.xlsx
Binary file not shown.
Binary file modified data-raw/antibiotics.xpt
Binary file not shown.
Binary file modified data/antibiotics.rda
Binary file not shown.
6 changes: 6 additions & 0 deletions inst/tinytest/test-sir.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
mutate(MEM = as.sir(ifelse(AMC == "S", "S", MEM))) %>%
pull(MEM) %>%
is.sir())

expect_true(example_isolates %>%
select(AMC, MEM) %>%
mutate(MEM = if_else(AMC == "S", "S", MEM)) %>%
pull(MEM) %>%
is.sir())
}
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
expect_inherits(
Expand Down
4 changes: 2 additions & 2 deletions man/antibiotic_class_selectors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit de17de1

Please sign in to comment.