1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-13 04:42:09 +02:00

(v2.1.1.9050) vctrs fix for sir, small documentation fixes

This commit is contained in:
2024-06-15 15:33:49 +02:00
parent 9bf7584d58
commit bdbf5198a2
15 changed files with 248 additions and 165 deletions

View File

@ -185,59 +185,31 @@ All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR
example_isolates
# Examples sections below are split into 'base R', 'dplyr', and 'data.table':
# base R ------------------------------------------------------------------
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
example_isolates[, carbapenems()]
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates[, c("mo", aminoglycosides())]
# select only antibiotic columns with DDDs for oral treatment
example_isolates[, administrable_per_os()]
# filter using any() or all()
example_isolates[any(carbapenems() == "R"), ]
subset(example_isolates, any(carbapenems() == "R"))
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
example_isolates[any(carbapenems()), ]
example_isolates[all(carbapenems()), ]
# filter with multiple antibiotic selectors using c()
example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
# filter + select in one go: get penicillins in carbapenem-resistant strains
example_isolates[any(carbapenems() == "R"), penicillins()]
# You can combine selectors with '&' to be more specific. For example,
# penicillins() would select benzylpenicillin ('peni G') and
# administrable_per_os() would select erythromycin. Yet, when combined these
# drugs are both omitted since benzylpenicillin is not administrable per os
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# ab_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antibiotic columns with an oral DDD
# of at least 1 gram:
example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
# Examples sections below are split into 'dplyr', 'base R', and 'data.table':
\donttest{
# dplyr -------------------------------------------------------------------
if (require("dplyr")) {
tibble(kefzol = random_sir(5)) \%>\%
select(cephalosporins())
. example_isolates \%>\% select(carbapenems())
}
if (require("dplyr")) {
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates \%>\% select(mo, aminoglycosides())
}
if (require("dplyr")) {
# select only antibiotic columns with DDDs for oral treatment
. example_isolates \%>\% select(administrable_per_os())
}
if (require("dplyr")) {
# get AMR for all aminoglycosides e.g., per ward:
example_isolates \%>\%
group_by(ward) \%>\%
summarise(across(aminoglycosides(), resistance))
summarise(across(aminoglycosides(),
resistance))
}
if (require("dplyr")) {
# You can combine selectors with '&' to be more specific:
@ -249,7 +221,8 @@ if (require("dplyr")) {
example_isolates \%>\%
filter(mo_genus() \%in\% c("Escherichia", "Klebsiella")) \%>\%
group_by(ward) \%>\%
summarise(across(not_intrinsic_resistant(), resistance))
summarise_at(not_intrinsic_resistant(),
resistance)
}
if (require("dplyr")) {
# get susceptibility for antibiotics whose name contains "trim":
@ -315,6 +288,44 @@ if (require("dplyr")) {
}
# base R ------------------------------------------------------------------
# select columns 'IPM' (imipenem) and 'MEM' (meropenem)
example_isolates[, carbapenems()]
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
example_isolates[, c("mo", aminoglycosides())]
# select only antibiotic columns with DDDs for oral treatment
example_isolates[, administrable_per_os()]
# filter using any() or all()
example_isolates[any(carbapenems() == "R"), ]
subset(example_isolates, any(carbapenems() == "R"))
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
example_isolates[any(carbapenems()), ]
example_isolates[all(carbapenems()), ]
# filter with multiple antibiotic selectors using c()
example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]
# filter + select in one go: get penicillins in carbapenem-resistant strains
example_isolates[any(carbapenems() == "R"), penicillins()]
# You can combine selectors with '&' to be more specific. For example,
# penicillins() would select benzylpenicillin ('peni G') and
# administrable_per_os() would select erythromycin. Yet, when combined these
# drugs are both omitted since benzylpenicillin is not administrable per os
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# ab_selector() applies a filter in the `antibiotics` data set and is thus
# very flexible. For instance, to select antibiotic columns with an oral DDD
# of at least 1 gram:
example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
# data.table --------------------------------------------------------------
# data.table is supported as well, just use it in the same way as with

View File

@ -251,6 +251,51 @@ summary(example_isolates) # see all SIR results at a glance
# For INTERPRETING disk diffusion and MIC values -----------------------
\donttest{
## Using dplyr -------------------------------------------------
if (require("dplyr")) {
# approaches that all work without additional arguments:
df \%>\% mutate_if(is.mic, as.sir)
df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.sir)
df \%>\% mutate(across(where(is.mic), as.sir))
df \%>\% mutate_at(vars(AMP:TOB), as.sir)
df \%>\% mutate(across(AMP:TOB, as.sir))
# approaches that all work with additional arguments:
df \%>\% mutate_if(is.mic, as.sir, mo = "column1", guideline = "CLSI")
df \%>\% mutate(across(where(is.mic),
function(x) as.sir(x, mo = "column1", guideline = "CLSI")))
df \%>\% mutate_at(vars(AMP:TOB), as.sir, mo = "column1", guideline = "CLSI")
df \%>\% mutate(across(AMP:TOB,
function(x) as.sir(x, mo = "column1", guideline = "CLSI")))
# for veterinary breakpoints, add 'host':
df \%>\% mutate_if(is.mic, as.sir, guideline = "CLSI", host = "species_column")
df \%>\% mutate_if(is.mic, as.sir, guideline = "CLSI", host = "horse")
df \%>\% mutate(across(where(is.mic),
function(x) as.sir(x, guideline = "CLSI", host = "species_column")))
df \%>\% mutate_at(vars(AMP:TOB), as.sir, guideline = "CLSI", host = "species_column")
df \%>\% mutate(across(AMP:TOB,
function(x) as.sir(x, mo = "column1", guideline = "CLSI")))
# to include information about urinary tract infections (UTI)
data.frame(mo = "E. coli",
nitrofuratoin = c("<= 2", 32),
from_the_bladder = c(TRUE, FALSE)) \%>\%
as.sir(uti = "from_the_bladder")
data.frame(mo = "E. coli",
nitrofuratoin = c("<= 2", 32),
specimen = c("urine", "blood")) \%>\%
as.sir() # automatically determines urine isolates
df \%>\%
mutate_at(vars(AMP:TOB), as.sir, mo = "E. coli", uti = TRUE)
}
## Using base R ------------------------------------------------
# a whole data set, even with combined MIC values and disk zones
df <- data.frame(
microorganism = "Escherichia coli",
@ -280,36 +325,6 @@ as.sir(
guideline = "EUCAST"
)
\donttest{
# the dplyr way
if (require("dplyr")) {
df \%>\% mutate_if(is.mic, as.sir)
df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.sir)
df \%>\% mutate(across(where(is.mic), as.sir))
df \%>\% mutate_at(vars(AMP:TOB), as.sir)
df \%>\% mutate(across(AMP:TOB, as.sir))
df \%>\%
mutate_at(vars(AMP:TOB), as.sir, mo = "microorganism")
# to include information about urinary tract infections (UTI)
data.frame(
mo = "E. coli",
NIT = c("<= 2", 32),
from_the_bladder = c(TRUE, FALSE)
) \%>\%
as.sir(uti = "from_the_bladder")
data.frame(
mo = "E. coli",
NIT = c("<= 2", 32),
specimen = c("urine", "blood")
) \%>\%
as.sir() # automatically determines urine isolates
df \%>\%
mutate_at(vars(AMP:TOB), as.sir, mo = "E. coli", uti = TRUE)
}
# For CLEANING existing SIR values ------------------------------------