-Last updated: 4 October 2021
+Last updated: 5 October 2021
diff --git a/inst/tinytest/test-_misc.R b/inst/tinytest/test-_misc.R
index 3d0bd421..fecae64f 100755
--- a/inst/tinytest/test-_misc.R
+++ b/inst/tinytest/test-_misc.R
@@ -42,12 +42,12 @@ expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE))
expect_warning(AMR:::get_column_abx(example_isolates, hard_dependencies = "FUS"))
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_warning(AMR:::get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = TRUE))
expect_warning(AMR:::get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = FALSE))
}
# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this:
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
}
diff --git a/inst/tinytest/test-ab_class_selectors.R b/inst/tinytest/test-ab_class_selectors.R
index e00b07dc..3dfbd713 100644
--- a/inst/tinytest/test-ab_class_selectors.R
+++ b/inst/tinytest/test-ab_class_selectors.R
@@ -65,6 +65,9 @@ expect_equal(nrow(subset(example_isolates, any(carbapenems() == "R"))), 55, tole
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
expect_equal(nrow(example_isolates[any(carbapenems()), ]), 962, tolerance = 0.5)
expect_equal(nrow(example_isolates[all(carbapenems()), ]), 756, tolerance = 0.5)
+expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55, tolerance = 0.5)
+expect_equal(nrow(example_isolates[any(carbapenems() != "R"), ]), 910, tolerance = 0.5)
+expect_equal(nrow(example_isolates[carbapenems() != "R", ]), 704, tolerance = 0.5)
# filter with multiple antibiotic selectors using c()
expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]), 26, tolerance = 0.5)
@@ -73,3 +76,9 @@ expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), penicillins()]), 55, tolerance = 0.5)
expect_equal(ncol(example_isolates[any(carbapenems() == "R"), penicillins()]), 7, tolerance = 0.5)
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
+ expect_equal(example_isolates %>% select(administrable_per_os() & penicillins()) %>% ncol(), 5, tolerance = 0.5)
+ expect_equal(example_isolates %>% select(administrable_iv() & penicillins()) %>% ncol(), 7, tolerance = 0.5)
+ expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5)
+ expect_warning(example_isolates %>% select(GEH = GEN) %>% select(aminoglycosides(only_treatable = TRUE)))
+}
diff --git a/inst/tinytest/test-ab_property.R b/inst/tinytest/test-ab_property.R
index 006c4c53..428aa788 100644
--- a/inst/tinytest/test-ab_property.R
+++ b/inst/tinytest/test-ab_property.R
@@ -69,7 +69,7 @@ expect_identical(colnames(set_ab_names(example_isolates[, 20:25], language = "nl
c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine"))
expect_identical(colnames(set_ab_names(example_isolates[, 20:25], "atc")),
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01"))
-if (AMR:::pkg_is_available("dplyr") && packageVersion("dplyr") >= "1.0.0") {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_identical(example_isolates %>% set_ab_names(),
example_isolates %>% rename_with(set_ab_names))
}
diff --git a/inst/tinytest/test-bug_drug_combinations.R b/inst/tinytest/test-bug_drug_combinations.R
index 769961a4..aa269f5b 100644
--- a/inst/tinytest/test-bug_drug_combinations.R
+++ b/inst/tinytest/test-bug_drug_combinations.R
@@ -28,7 +28,7 @@ expect_inherits(b, "bug_drug_combinations")
expect_stdout(suppressMessages(print(b)))
expect_true(is.data.frame(format(b)))
expect_true(is.data.frame(format(b, combine_IR = TRUE, add_ab_group = FALSE)))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_true(example_isolates %>%
group_by(hospital_id) %>%
bug_drug_combinations(FUN = mo_gramstain) %>%
diff --git a/inst/tinytest/test-count.R b/inst/tinytest/test-count.R
index b39f3d7f..0cfeb5ed 100644
--- a/inst/tinytest/test-count.R
+++ b/inst/tinytest/test-count.R
@@ -51,7 +51,7 @@ expect_error(count_susceptible("test", as_percent = "test"))
expect_error(count_df(c("A", "B", "C")))
expect_error(count_df(example_isolates[, "date"]))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_equal(example_isolates %>% count_susceptible(AMC), 1433)
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE), 1687)
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = FALSE), 1764)
diff --git a/inst/tinytest/test-disk.R b/inst/tinytest/test-disk.R
index 837266ea..b303ab8b 100755
--- a/inst/tinytest/test-disk.R
+++ b/inst/tinytest/test-disk.R
@@ -50,6 +50,6 @@ if (AMR:::pkg_is_available("ggplot2")) {
}
expect_stdout(print(as.disk(12)))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(print(tibble(d = as.disk(12))))
}
diff --git a/inst/tinytest/test-episode.R b/inst/tinytest/test-episode.R
index fd6bd680..89932ffd 100644
--- a/inst/tinytest/test-episode.R
+++ b/inst/tinytest/test-episode.R
@@ -36,7 +36,7 @@ test_df <- rbind(
expect_equal(get_episode(test_df$date, 365),
c(1, 1, 2, 2, 2, 3, 3, 4, 1, 2, 2, 2, 3))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_identical(test_df %>% group_by(patient_id) %>% mutate(f = is_new_episode(date, 365)) %>% pull(f),
c(TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE))
diff --git a/inst/tinytest/test-eucast_rules.R b/inst/tinytest/test-eucast_rules.R
index 087f51e2..26a6fafa 100755
--- a/inst/tinytest/test-eucast_rules.R
+++ b/inst/tinytest/test-eucast_rules.R
@@ -72,7 +72,7 @@ b <- data.frame(mo = c("Staphylococcus aureus",
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
# piperacillin must be R in Enterobacteriaceae when tica is R
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_equal(suppressWarnings(
example_isolates %>%
filter(mo_family(mo) == "Enterobacteriaceae") %>%
@@ -110,7 +110,7 @@ expect_equal(
"S")
# also test norf
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
}
diff --git a/inst/tinytest/test-first_isolate.R b/inst/tinytest/test-first_isolate.R
index f6e48fcd..a599d4b9 100755
--- a/inst/tinytest/test-first_isolate.R
+++ b/inst/tinytest/test-first_isolate.R
@@ -110,7 +110,7 @@ expect_error(first_isolate(example_isolates,
col_date = "non-existing col",
col_mo = "mo"))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# if mo is not an mo class, result should be the same
expect_identical(example_isolates %>%
mutate(mo = as.character(mo)) %>%
diff --git a/inst/tinytest/test-ggplot_rsi.R b/inst/tinytest/test-ggplot_rsi.R
index eec8c2a0..d7afc1f3 100644
--- a/inst/tinytest/test-ggplot_rsi.R
+++ b/inst/tinytest/test-ggplot_rsi.R
@@ -23,7 +23,7 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
-if (AMR:::pkg_is_available("dplyr") & AMR:::pkg_is_available("ggplot2")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_available("ggplot2")) {
pdf(NULL) # prevent Rplots.pdf being created
diff --git a/inst/tinytest/test-mdro.R b/inst/tinytest/test-mdro.R
index ebdc8356..22c717b2 100755
--- a/inst/tinytest/test-mdro.R
+++ b/inst/tinytest/test-mdro.R
@@ -232,7 +232,7 @@ expect_warning(mdro(example_isolates,
info = FALSE))
# print groups
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(x <- mdro(example_isolates %>% group_by(hospital_id), info = TRUE))
expect_stdout(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE))
}
diff --git a/inst/tinytest/test-mic.R b/inst/tinytest/test-mic.R
index face904d..1d73a8b8 100755
--- a/inst/tinytest/test-mic.R
+++ b/inst/tinytest/test-mic.R
@@ -58,7 +58,7 @@ expect_stdout(print(as.mic(c(1, 2, 4, 8))))
expect_inherits(summary(as.mic(c(2, 8))), c("summaryDefault", "table"))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(print(tibble(m = as.mic(2:4))))
}
diff --git a/inst/tinytest/test-mo.R b/inst/tinytest/test-mo.R
index 5623b0d6..7aefe37b 100644
--- a/inst/tinytest/test-mo.R
+++ b/inst/tinytest/test-mo.R
@@ -143,7 +143,7 @@ expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_S
expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR")
expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# select with one column
expect_identical(
example_isolates[1:10, ] %>%
@@ -272,7 +272,7 @@ expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))),
expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))),
c("F_YEAST", "F_FUNGUS"))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# print tibble
expect_stdout(print(tibble(mo = as.mo("B_ESCHR_COLI"))))
}
diff --git a/inst/tinytest/test-mo_property.R b/inst/tinytest/test-mo_property.R
index 35abe717..83a83689 100644
--- a/inst/tinytest/test-mo_property.R
+++ b/inst/tinytest/test-mo_property.R
@@ -119,7 +119,7 @@ expect_equal(mo_is_intrinsic_resistant(c("Escherichia coli", "Staphylococcus aur
# with reference data
expect_equal(mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
"Escherichia coli")
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
730, tolerance = 0.5)
expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(),
diff --git a/inst/tinytest/test-pca.R b/inst/tinytest/test-pca.R
index 24d085c6..e9ab0c70 100644
--- a/inst/tinytest/test-pca.R
+++ b/inst/tinytest/test-pca.R
@@ -47,7 +47,7 @@ if (AMR:::pkg_is_available("ggplot2")) {
ggplot_pca(pca_model, arrows_textangled = FALSE)
}
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
resistance_data <- example_isolates %>%
group_by(order = mo_order(mo),
genus = mo_genus(mo)) %>%
diff --git a/inst/tinytest/test-proportion.R b/inst/tinytest/test-proportion.R
index d27691e5..c0e4e1ed 100755
--- a/inst/tinytest/test-proportion.R
+++ b/inst/tinytest/test-proportion.R
@@ -35,7 +35,7 @@ expect_equal(proportion_R(example_isolates$AMX) + proportion_I(example_isolates$
expect_equal(proportion_S(example_isolates$AMX) + proportion_I(example_isolates$AMX),
proportion_SI(example_isolates$AMX))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_equal(example_isolates %>% proportion_SI(AMC),
0.7626397,
tolerance = 0.0001)
diff --git a/inst/tinytest/test-resistance_predict.R b/inst/tinytest/test-resistance_predict.R
index d06e3d02..81a02868 100644
--- a/inst/tinytest/test-resistance_predict.R
+++ b/inst/tinytest/test-resistance_predict.R
@@ -23,7 +23,7 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(AMX_R <- example_isolates %>%
filter(mo == "B_ESCHR_COLI") %>%
rsi_predict(col_ab = "AMX",
diff --git a/inst/tinytest/test-rsi.R b/inst/tinytest/test-rsi.R
index 004b177d..d2192806 100644
--- a/inst/tinytest/test-rsi.R
+++ b/inst/tinytest/test-rsi.R
@@ -51,7 +51,7 @@ expect_identical(as.logical(lapply(example_isolates, is.rsi.eligible)),
expect_error(as.rsi.mic(as.mic(16)))
expect_error(as.rsi.disk(as.disk(16)))
expect_error(get_guideline("this one does not exist"))
-if (AMR:::pkg_is_available("dplyr")) {
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# 40 rsi columns
expect_equal(example_isolates %>%
mutate_at(vars(PEN:RIF), as.character) %>%
@@ -66,7 +66,7 @@ if (AMR:::pkg_is_available("dplyr")) {
if (AMR:::pkg_is_available("skimr")) {
expect_inherits(skim(example_isolates),
"data.frame")
- if (AMR:::pkg_is_available("dplyr")) {
+ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_inherits(example_isolates %>%
mutate(m = as.mic(2),
d = as.disk(20)) %>%
@@ -96,7 +96,7 @@ expect_equal(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020
as.rsi("S"))
expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"),
as.rsi("R"))
-if (AMR:::pkg_is_available("dplyr")) {
+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) %>%
@@ -123,7 +123,7 @@ expect_equal(as.character(
ab = "ERY",
guideline = "CLSI")),
"R")
-if (AMR:::pkg_is_available("dplyr")) {
+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) %>%