mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 07:51:57 +02:00
Replace RSI with SIR
This commit is contained in:
committed by
GitHub
parent
24b12024ce
commit
98e62c9af2
@ -29,7 +29,7 @@
|
||||
|
||||
expect_equal(count_resistant(example_isolates$AMX), count_R(example_isolates$AMX))
|
||||
expect_equal(count_susceptible(example_isolates$AMX), count_SI(example_isolates$AMX))
|
||||
expect_equal(count_all(example_isolates$AMX), n_rsi(example_isolates$AMX))
|
||||
expect_equal(count_all(example_isolates$AMX), n_sir(example_isolates$AMX))
|
||||
|
||||
# AMX resistance in `example_isolates`
|
||||
expect_equal(count_R(example_isolates$AMX), 804)
|
||||
@ -103,10 +103,10 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
)
|
||||
)
|
||||
|
||||
# grouping in rsi_calc_df() (= backbone of rsi_df())
|
||||
# grouping in sir_calc_df() (= backbone of sir_df())
|
||||
expect_true("ward" %in% (example_isolates %>%
|
||||
group_by(ward) %>%
|
||||
select(ward, AMX, CIP, gender) %>%
|
||||
rsi_df() %>%
|
||||
sir_df() %>%
|
||||
colnames()))
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ expect_identical(class(antibiotics$ab), c("ab", "character"))
|
||||
# check cross table reference
|
||||
expect_true(all(microorganisms.codes$mo %in% microorganisms$mo))
|
||||
expect_true(all(example_isolates$mo %in% microorganisms$mo))
|
||||
expect_true(all(rsi_translation$mo %in% microorganisms$mo))
|
||||
expect_true(all(rsi_translation$ab %in% antibiotics$ab))
|
||||
expect_true(all(clinical_breakpoints$mo %in% microorganisms$mo))
|
||||
expect_true(all(clinical_breakpoints$ab %in% antibiotics$ab))
|
||||
expect_true(all(intrinsic_resistant$mo %in% microorganisms$mo))
|
||||
expect_true(all(intrinsic_resistant$ab %in% antibiotics$ab))
|
||||
expect_false(any(is.na(microorganisms.codes$code)))
|
||||
@ -47,10 +47,10 @@ expect_false(any(is.na(microorganisms.codes$mo)))
|
||||
expect_true(all(dosage$ab %in% antibiotics$ab))
|
||||
expect_true(all(dosage$name %in% antibiotics$name))
|
||||
# check valid disks/MICs
|
||||
expect_false(any(is.na(as.mic(rsi_translation[which(rsi_translation$method == "MIC"), "breakpoint_S", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.mic(rsi_translation[which(rsi_translation$method == "MIC"), "breakpoint_R", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "DISK"), "breakpoint_S", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "DISK"), "breakpoint_R", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_S", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_R", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_S", drop = TRUE]))))
|
||||
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_R", drop = TRUE]))))
|
||||
|
||||
# antibiotic names must always be coercible to their original AB code
|
||||
expect_identical(as.ab(antibiotics$name), antibiotics$ab)
|
||||
|
@ -104,8 +104,8 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
example_isolates %>%
|
||||
filter(mo_family(mo) == "Enterobacteriaceae") %>%
|
||||
mutate(
|
||||
TIC = as.rsi("R"),
|
||||
PIP = as.rsi("S")
|
||||
TIC = as.sir("R"),
|
||||
PIP = as.sir("S")
|
||||
) %>%
|
||||
eucast_rules(col_mo = "mo", version_expertrules = 3.1, info = FALSE) %>%
|
||||
pull(PIP) %>%
|
||||
@ -117,15 +117,15 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
}
|
||||
|
||||
# azithromycin and clarythromycin must be equal to Erythromycin
|
||||
a <- suppressWarnings(as.rsi(eucast_rules(data.frame(
|
||||
a <- suppressWarnings(as.sir(eucast_rules(data.frame(
|
||||
mo = example_isolates$mo,
|
||||
ERY = example_isolates$ERY,
|
||||
AZM = as.rsi("R"),
|
||||
AZM = as.sir("R"),
|
||||
CLR = factor("R"),
|
||||
stringsAsFactors = FALSE
|
||||
),
|
||||
version_expertrules = 3.1,
|
||||
only_rsi_columns = FALSE
|
||||
only_sir_columns = FALSE
|
||||
)$CLR))
|
||||
b <- example_isolates$ERY
|
||||
expect_identical(
|
||||
@ -162,34 +162,34 @@ expect_stdout(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, ru
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(
|
||||
mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))
|
||||
cefotax = as.sir(c("S", "S"))
|
||||
),
|
||||
ampc_cephalosporin_resistance = TRUE,
|
||||
info = FALSE
|
||||
)$cefotax,
|
||||
as.rsi(c("S", "R"))
|
||||
as.sir(c("S", "R"))
|
||||
)
|
||||
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(
|
||||
mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))
|
||||
cefotax = as.sir(c("S", "S"))
|
||||
),
|
||||
ampc_cephalosporin_resistance = NA,
|
||||
info = FALSE
|
||||
)$cefotax,
|
||||
as.rsi(c("S", NA))
|
||||
as.sir(c("S", NA))
|
||||
)
|
||||
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(
|
||||
mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))
|
||||
cefotax = as.sir(c("S", "S"))
|
||||
),
|
||||
ampc_cephalosporin_resistance = NULL,
|
||||
info = FALSE
|
||||
)$cefotax,
|
||||
as.rsi(c("S", "S"))
|
||||
as.sir(c("S", "S"))
|
||||
)
|
||||
|
||||
# EUCAST dosage -----------------------------------------------------------
|
||||
|
@ -214,9 +214,9 @@ expect_equal(
|
||||
1108
|
||||
)
|
||||
|
||||
# empty rsi results
|
||||
# empty sir results
|
||||
expect_equal(
|
||||
sum(first_isolate(example_isolates, include_untested_rsi = FALSE)),
|
||||
sum(first_isolate(example_isolates, include_untested_sir = FALSE)),
|
||||
1366
|
||||
)
|
||||
|
||||
|
@ -34,7 +34,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi())$data %>%
|
||||
ggplot_sir())$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
@ -45,15 +45,15 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa
|
||||
|
||||
expect_stdout(print(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi(x = "interpretation", facet = "antibiotic")))
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic")))
|
||||
expect_stdout(print(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi(x = "antibiotic", facet = "interpretation")))
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation")))
|
||||
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
@ -65,7 +65,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
@ -77,7 +77,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(count_resistant) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
@ -124,7 +124,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa
|
||||
z = c("Value4", "Value5", "Value6")
|
||||
)) +
|
||||
geom_col(aes(x = x, y = y, fill = z)) +
|
||||
scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R"))$data,
|
||||
scale_sir_colours(Value4 = "S", Value5 = "I", Value6 = "R"))$data,
|
||||
"data.frame"
|
||||
)
|
||||
}
|
||||
|
@ -133,13 +133,13 @@ expect_equal(
|
||||
)
|
||||
|
||||
x <- data.frame(
|
||||
rifampicin = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
inh = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
gatifloxacin = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
eth = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
pza = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
MFX = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)),
|
||||
KAN = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5))
|
||||
rifampicin = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
inh = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
gatifloxacin = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
eth = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
pza = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
MFX = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)),
|
||||
KAN = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5))
|
||||
)
|
||||
expect_true(length(unique(mdr_tb(x))) > 2)
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
vctr_disk <- as.disk(c(20:25))
|
||||
vctr_mic <- as.mic(2^c(0:5))
|
||||
vctr_rsi <- as.rsi(c("S", "S", "I", "I", "R", "R"))
|
||||
vctr_sir <- as.sir(c("S", "S", "I", "I", "R", "R"))
|
||||
|
||||
expect_identical(
|
||||
mean_amr_distance(vctr_disk),
|
||||
@ -42,22 +42,22 @@ expect_identical(
|
||||
)
|
||||
|
||||
expect_identical(
|
||||
mean_amr_distance(vctr_rsi, combine_SI = FALSE),
|
||||
mean_amr_distance(vctr_sir, combine_SI = FALSE),
|
||||
(c(1, 1, 2, 2, 3, 3) - mean(c(1, 1, 2, 2, 3, 3))) / sd(c(1, 1, 2, 2, 3, 3))
|
||||
)
|
||||
expect_identical(
|
||||
mean_amr_distance(vctr_rsi, combine_SI = TRUE),
|
||||
mean_amr_distance(vctr_sir, combine_SI = TRUE),
|
||||
(c(1, 1, 1, 1, 3, 3) - mean(c(1, 1, 1, 1, 3, 3))) / sd(c(1, 1, 1, 1, 3, 3))
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_rsi, TOB = vctr_disk)),
|
||||
mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_sir, TOB = vctr_disk)),
|
||||
c(-1.10603655, -0.74968823, -0.39333990, -0.03699158, 0.96485397, 1.32120229),
|
||||
tolerance = 0.00001
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_rsi, TOB = vctr_disk), 2:3),
|
||||
mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_sir, TOB = vctr_disk), 2:3),
|
||||
c(-0.9909017, -0.7236405, -0.4563792, -0.1891180, 1.0463891, 1.3136503),
|
||||
tolerance = 0.00001
|
||||
)
|
||||
|
@ -63,7 +63,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
order = mo_order(mo),
|
||||
genus = mo_genus(mo)
|
||||
) %>%
|
||||
summarise_if(is.rsi, resistance, minimum = 0)
|
||||
summarise_if(is.sir, resistance, minimum = 0)
|
||||
pca_result <- resistance_data %>%
|
||||
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT")
|
||||
expect_inherits(pca_result, "prcomp")
|
||||
|
@ -32,8 +32,8 @@ expect_equal(proportion_SI(example_isolates$AMX), susceptibility(example_isolate
|
||||
# AMX resistance in `example_isolates`
|
||||
expect_equal(proportion_R(example_isolates$AMX), 0.5955556, tolerance = 0.0001)
|
||||
expect_equal(proportion_I(example_isolates$AMX), 0.002222222, tolerance = 0.0001)
|
||||
expect_equal(rsi_confidence_interval(example_isolates$AMX)[1], 0.5688204, tolerance = 0.0001)
|
||||
expect_equal(rsi_confidence_interval(example_isolates$AMX)[2], 0.6218738, tolerance = 0.0001)
|
||||
expect_equal(sir_confidence_interval(example_isolates$AMX)[1], 0.5688204, tolerance = 0.0001)
|
||||
expect_equal(sir_confidence_interval(example_isolates$AMX)[2], 0.6218738, tolerance = 0.0001)
|
||||
expect_equal(
|
||||
1 - proportion_R(example_isolates$AMX) - proportion_I(example_isolates$AMX),
|
||||
proportion_S(example_isolates$AMX)
|
||||
@ -69,7 +69,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
R = proportion_R(CIP, as_percent = TRUE),
|
||||
I = proportion_I(CIP, as_percent = TRUE),
|
||||
S = proportion_S(CIP, as_percent = TRUE),
|
||||
n = n_rsi(CIP),
|
||||
n = n_sir(CIP),
|
||||
total = n()
|
||||
) %>%
|
||||
pull(n) %>%
|
||||
@ -83,11 +83,11 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
group_by(ward) %>%
|
||||
summarise(
|
||||
cipro_p = proportion_SI(CIP, as_percent = TRUE),
|
||||
cipro_n = n_rsi(CIP),
|
||||
cipro_n = n_sir(CIP),
|
||||
genta_p = proportion_SI(GEN, as_percent = TRUE),
|
||||
genta_n = n_rsi(GEN),
|
||||
genta_n = n_sir(GEN),
|
||||
combination_p = proportion_SI(CIP, GEN, as_percent = TRUE),
|
||||
combination_n = n_rsi(CIP, GEN)
|
||||
combination_n = n_sir(CIP, GEN)
|
||||
) %>%
|
||||
pull(combination_n),
|
||||
c(1181, 577, 116)
|
||||
@ -110,7 +110,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
)
|
||||
)
|
||||
|
||||
expect_warning(example_isolates %>% group_by(ward) %>% summarise(across(KAN, rsi_confidence_interval)))
|
||||
expect_warning(example_isolates %>% group_by(ward) %>% summarise(across(KAN, sir_confidence_interval)))
|
||||
}
|
||||
|
||||
expect_warning(proportion_R(as.character(example_isolates$AMC)))
|
||||
@ -120,12 +120,12 @@ expect_warning(proportion_S(as.character(
|
||||
example_isolates$GEN
|
||||
)))
|
||||
|
||||
expect_warning(n_rsi(as.character(
|
||||
expect_warning(n_sir(as.character(
|
||||
example_isolates$AMC,
|
||||
example_isolates$GEN
|
||||
)))
|
||||
expect_equal(
|
||||
suppressWarnings(n_rsi(as.character(
|
||||
suppressWarnings(n_sir(as.character(
|
||||
example_isolates$AMC,
|
||||
example_isolates$GEN
|
||||
))),
|
||||
|
@ -37,4 +37,4 @@ expect_inherits(random_disk(100), "disk")
|
||||
expect_inherits(random_disk(100, mo = "Klebsiella pneumoniae"), "disk")
|
||||
expect_inherits(random_disk(100, mo = "Klebsiella pneumoniae", ab = "meropenem"), "disk")
|
||||
expect_inherits(random_disk(100, ab = "meropenem"), "disk")
|
||||
expect_inherits(random_rsi(100), "rsi")
|
||||
expect_inherits(random_sir(100), "sir")
|
||||
|
@ -30,7 +30,7 @@
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
expect_stdout(AMX_R <- example_isolates %>%
|
||||
filter(mo == "B_ESCHR_COLI") %>%
|
||||
rsi_predict(
|
||||
sir_predict(
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
model = "binomial",
|
||||
@ -51,25 +51,25 @@ expect_stdout(x <- suppressMessages(resistance_predict(example_isolates,
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(plot(x))
|
||||
if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_silent(ggplot_rsi_predict(x))
|
||||
expect_silent(ggplot_sir_predict(x))
|
||||
expect_silent(autoplot(x))
|
||||
expect_error(ggplot_rsi_predict(example_isolates))
|
||||
expect_error(ggplot_sir_predict(example_isolates))
|
||||
}
|
||||
expect_stdout(rsi_predict(
|
||||
expect_stdout(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "binomial",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE
|
||||
))
|
||||
expect_stdout(rsi_predict(
|
||||
expect_stdout(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "loglin",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE
|
||||
))
|
||||
expect_stdout(rsi_predict(
|
||||
expect_stdout(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "lin",
|
||||
col_ab = "AMX",
|
||||
@ -77,34 +77,34 @@ expect_stdout(rsi_predict(
|
||||
info = TRUE
|
||||
))
|
||||
|
||||
expect_error(rsi_predict(
|
||||
expect_error(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "INVALID MODEL",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE
|
||||
))
|
||||
expect_error(rsi_predict(
|
||||
expect_error(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "binomial",
|
||||
col_ab = "NOT EXISTING COLUMN",
|
||||
col_date = "date",
|
||||
info = TRUE
|
||||
))
|
||||
expect_error(rsi_predict(
|
||||
expect_error(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
model = "binomial",
|
||||
col_ab = "AMX",
|
||||
col_date = "NOT EXISTING COLUMN",
|
||||
info = TRUE
|
||||
))
|
||||
expect_error(rsi_predict(
|
||||
expect_error(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
col_ab = "AMX",
|
||||
col_date = "NOT EXISTING COLUMN",
|
||||
info = TRUE
|
||||
))
|
||||
expect_error(rsi_predict(
|
||||
expect_error(sir_predict(
|
||||
x = subset(example_isolates, mo == "B_ESCHR_COLI"),
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
|
@ -27,34 +27,34 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
# we must only have EUCAST and CLSI, because otherwise the rules in as.rsi() will fail
|
||||
# we must only have EUCAST and CLSI, because otherwise the rules in as.sir() will fail
|
||||
expect_identical(
|
||||
unique(gsub("[^A-Z]", "", AMR::rsi_translation$guideline)),
|
||||
unique(gsub("[^A-Z]", "", AMR::clinical_breakpoints$guideline)),
|
||||
c("EUCAST", "CLSI")
|
||||
)
|
||||
|
||||
expect_true(as.rsi("S") < as.rsi("I"))
|
||||
expect_true(as.rsi("I") < as.rsi("R"))
|
||||
expect_true(is.rsi(as.rsi("S")))
|
||||
expect_true(as.sir("S") < as.sir("I"))
|
||||
expect_true(as.sir("I") < as.sir("R"))
|
||||
expect_true(is.sir(as.sir("S")))
|
||||
x <- example_isolates$AMX
|
||||
expect_inherits(x[1], "rsi")
|
||||
expect_inherits(x[[1]], "rsi")
|
||||
expect_inherits(c(x[1], x[9]), "rsi")
|
||||
expect_inherits(unique(x[1], x[9]), "rsi")
|
||||
expect_inherits(x[1], "sir")
|
||||
expect_inherits(x[[1]], "sir")
|
||||
expect_inherits(c(x[1], x[9]), "sir")
|
||||
expect_inherits(unique(x[1], x[9]), "sir")
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(barplot(as.rsi(c("S", "I", "R"))))
|
||||
expect_silent(plot(as.rsi(c("S", "I", "R"))))
|
||||
expect_silent(barplot(as.sir(c("S", "I", "R"))))
|
||||
expect_silent(plot(as.sir(c("S", "I", "R"))))
|
||||
if (AMR:::pkg_is_available("ggplot2")) {
|
||||
expect_inherits(autoplot(as.rsi(c("S", "I", "R"))), "gg")
|
||||
expect_inherits(autoplot(as.sir(c("S", "I", "R"))), "gg")
|
||||
}
|
||||
expect_stdout(print(as.rsi(c("S", "I", "R"))))
|
||||
expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R"))
|
||||
expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R"))
|
||||
expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA)
|
||||
expect_stdout(print(as.sir(c("S", "I", "R"))))
|
||||
expect_equal(as.character(as.sir(c(1:3))), c("S", "I", "R"))
|
||||
expect_equal(as.character(as.sir(c(1:3))), c("S", "I", "R"))
|
||||
expect_equal(suppressWarnings(as.logical(as.sir("INVALID VALUE"))), NA)
|
||||
expect_equal(
|
||||
summary(as.rsi(c("S", "R"))),
|
||||
summary(as.sir(c("S", "R"))),
|
||||
structure(c(
|
||||
"Class" = "rsi",
|
||||
"Class" = "sir",
|
||||
"%R" = "50.0% (n=1)",
|
||||
"%SI" = "50.0% (n=1)",
|
||||
"- %S" = "50.0% (n=1)",
|
||||
@ -62,31 +62,31 @@ expect_equal(
|
||||
), class = c("summaryDefault", "table"))
|
||||
)
|
||||
expect_identical(
|
||||
as.logical(lapply(example_isolates, is.rsi.eligible)),
|
||||
as.logical(lapply(example_isolates, is.rsi))
|
||||
as.logical(lapply(example_isolates, is_sir_eligible)),
|
||||
as.logical(lapply(example_isolates, is.sir))
|
||||
)
|
||||
expect_error(as.rsi.mic(as.mic(16)))
|
||||
expect_error(as.rsi.disk(as.disk(16)))
|
||||
expect_error(as.sir.mic(as.mic(16)))
|
||||
expect_error(as.sir.disk(as.disk(16)))
|
||||
expect_error(get_guideline("this one does not exist"))
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
# 40 rsi columns
|
||||
# 40 sir columns
|
||||
expect_equal(
|
||||
example_isolates %>%
|
||||
mutate_at(vars(PEN:RIF), as.character) %>%
|
||||
lapply(is.rsi.eligible) %>%
|
||||
lapply(is_sir_eligible) %>%
|
||||
as.logical() %>%
|
||||
sum(),
|
||||
40
|
||||
)
|
||||
expect_equal(sum(is.rsi(example_isolates)), 40)
|
||||
expect_equal(sum(is.sir(example_isolates)), 40)
|
||||
|
||||
expect_stdout(print(tibble(ab = as.rsi("S"))))
|
||||
expect_stdout(print(tibble(ab = as.sir("S"))))
|
||||
|
||||
expect_true(example_isolates %>%
|
||||
select(AMC, MEM) %>%
|
||||
mutate(MEM = as.rsi(ifelse(AMC == "S", "S", MEM))) %>%
|
||||
mutate(MEM = as.sir(ifelse(AMC == "S", "S", MEM))) %>%
|
||||
pull(MEM) %>%
|
||||
is.rsi())
|
||||
is.sir())
|
||||
}
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) {
|
||||
expect_inherits(
|
||||
@ -106,12 +106,12 @@ if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) {
|
||||
}
|
||||
}
|
||||
|
||||
expect_equal(as.rsi(c("", "-", NA, "NULL")), c(NA_rsi_, NA_rsi_, NA_rsi_, NA_rsi_))
|
||||
expect_equal(as.sir(c("", "-", NA, "NULL")), c(NA_sir_, NA_sir_, NA_sir_, NA_sir_))
|
||||
|
||||
# S. pneumoniae/ampicillin in EUCAST 2020: 0.5-2 ug/ml (R is only > 2)
|
||||
expect_equal(suppressMessages(
|
||||
as.character(
|
||||
as.rsi(
|
||||
as.sir(
|
||||
x = as.mic(c(0.125, 0.5, 1, 2, 4)),
|
||||
mo = "B_STRPT_PNMN",
|
||||
ab = "AMP",
|
||||
@ -123,7 +123,7 @@ expect_equal(suppressMessages(
|
||||
# S. pneumoniae/amoxicillin in CLSI 2019: 2-8 ug/ml (R is 8 and > 8)
|
||||
expect_equal(suppressMessages(
|
||||
as.character(
|
||||
as.rsi(
|
||||
as.sir(
|
||||
x = as.mic(c(1, 2, 4, 8, 16)),
|
||||
mo = "B_STRPT_PNMN",
|
||||
ab = "AMX",
|
||||
@ -133,31 +133,31 @@ expect_equal(suppressMessages(
|
||||
c("S", "S", "I", "R", "R")
|
||||
)
|
||||
|
||||
expect_true(is.data.frame(rsi_interpretation_history(clean = FALSE)))
|
||||
expect_true(is.data.frame(rsi_interpretation_history(clean = TRUE)))
|
||||
expect_true(is.null(rsi_interpretation_history()))
|
||||
expect_true(is.data.frame(sir_interpretation_history(clean = FALSE)))
|
||||
expect_true(is.data.frame(sir_interpretation_history(clean = TRUE)))
|
||||
expect_true(is.null(sir_interpretation_history()))
|
||||
|
||||
# cutoffs at MIC = 8
|
||||
expect_equal(
|
||||
suppressMessages(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
||||
as.rsi("S")
|
||||
suppressMessages(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
||||
as.sir("S")
|
||||
)
|
||||
expect_equal(
|
||||
suppressMessages(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
||||
as.rsi("R")
|
||||
suppressMessages(as.sir(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
||||
as.sir("R")
|
||||
)
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
expect_true(suppressWarnings(example_isolates %>%
|
||||
mutate(amox_mic = as.mic(2)) %>%
|
||||
select(mo, amox_mic) %>%
|
||||
as.rsi() %>%
|
||||
as.sir() %>%
|
||||
pull(amox_mic) %>%
|
||||
is.rsi()))
|
||||
is.sir()))
|
||||
}
|
||||
|
||||
expect_equal(
|
||||
as.character(
|
||||
as.rsi(
|
||||
as.sir(
|
||||
x = as.disk(22),
|
||||
mo = "B_STRPT_PNMN",
|
||||
ab = "ERY",
|
||||
@ -168,7 +168,7 @@ expect_equal(
|
||||
)
|
||||
expect_equal(
|
||||
as.character(
|
||||
as.rsi(
|
||||
as.sir(
|
||||
x = as.disk(18),
|
||||
mo = "B_STRPT_PNMN",
|
||||
ab = "ERY",
|
||||
@ -179,7 +179,7 @@ expect_equal(
|
||||
)
|
||||
expect_equal(
|
||||
as.character(
|
||||
as.rsi(
|
||||
as.sir(
|
||||
x = as.disk(10),
|
||||
mo = "B_STRPT_PNMN",
|
||||
ab = "ERY",
|
||||
@ -192,9 +192,9 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
||||
expect_true(example_isolates %>%
|
||||
mutate(amox_disk = as.disk(15)) %>%
|
||||
select(mo, amox_disk) %>%
|
||||
as.rsi(guideline = "CLSI") %>%
|
||||
as.sir(guideline = "CLSI") %>%
|
||||
pull(amox_disk) %>%
|
||||
is.rsi())
|
||||
is.sir())
|
||||
}
|
||||
# frequency tables
|
||||
if (AMR:::pkg_is_available("cleaner")) {
|
||||
@ -212,26 +212,26 @@ df <- data.frame(
|
||||
CLR = "V"
|
||||
) # note about cleaning
|
||||
expect_inherits(
|
||||
suppressWarnings(as.rsi(df)),
|
||||
suppressWarnings(as.sir(df)),
|
||||
"data.frame"
|
||||
)
|
||||
expect_inherits(
|
||||
suppressWarnings(as.rsi(data.frame(
|
||||
suppressWarnings(as.sir(data.frame(
|
||||
mo = "Escherichia coli",
|
||||
amoxi = c("R", "S", "I", "invalid")
|
||||
amoxi = c("S", "I", "R", "invalid")
|
||||
))$amoxi),
|
||||
"rsi"
|
||||
"sir"
|
||||
)
|
||||
expect_warning(as.rsi(data.frame(
|
||||
expect_warning(as.sir(data.frame(
|
||||
mo = "E. coli",
|
||||
NIT = c("<= 2", 32)
|
||||
)))
|
||||
expect_message(as.rsi(data.frame(
|
||||
expect_message(as.sir(data.frame(
|
||||
mo = "E. coli",
|
||||
NIT = c("<= 2", 32),
|
||||
uti = TRUE
|
||||
)))
|
||||
expect_message(as.rsi(data.frame(
|
||||
expect_message(as.sir(data.frame(
|
||||
mo = "E. coli",
|
||||
NIT = c("<= 2", 32),
|
||||
specimen = c("urine", "blood")
|
||||
|
@ -33,7 +33,7 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) {
|
||||
mo = as.mo("Escherichia coli"),
|
||||
mic = as.mic(2),
|
||||
disk = as.disk(20),
|
||||
rsi = as.rsi("S"))
|
||||
sir = as.sir("S"))
|
||||
check1 <- lapply(test, class)
|
||||
test[1, "ab"] <- "GEN"
|
||||
test[1, "mo"] <- "B_KLBSL_PNMN"
|
||||
@ -42,11 +42,11 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) {
|
||||
test[1, "disk"] <- "35"
|
||||
test[1, "disk"] <- 25
|
||||
test[1, "disk"] <- 26L
|
||||
test[1, "rsi"] <- "R"
|
||||
test[1, "sir"] <- "R"
|
||||
check2 <- lapply(test, class)
|
||||
expect_identical(check1, check2)
|
||||
|
||||
test <- dplyr::tibble(cipro = as.rsi("S"),
|
||||
test <- dplyr::tibble(cipro = as.sir("S"),
|
||||
variable = "test")
|
||||
expect_equal(nrow(test[quinolones() == "S", ]), 1)
|
||||
expect_equal(nrow(test[quinolones() == "R", ]), 0)
|
||||
|
Reference in New Issue
Block a user