mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 07:26:12 +01:00
unit tests
This commit is contained in:
parent
8dcf101a9c
commit
8d902410f9
2
.github/prehooks/pre-commit
vendored
2
.github/prehooks/pre-commit
vendored
@ -37,7 +37,7 @@ if command -v Rscript > /dev/null; then
|
|||||||
Rscript -e "source('data-raw/_pre_commit_hook.R')"
|
Rscript -e "source('data-raw/_pre_commit_hook.R')"
|
||||||
currentpkg=$(Rscript -e "cat(pkgload::pkg_name())")
|
currentpkg=$(Rscript -e "cat(pkgload::pkg_name())")
|
||||||
echo "- Adding changed files in ./data-raw and ./man to this commit"
|
echo "- Adding changed files in ./data-raw and ./man to this commit"
|
||||||
git add data-raw/* --quiet
|
git add data-raw/* --ignore-missing
|
||||||
git add man/*
|
git add man/*
|
||||||
git add R/sysdata.rda
|
git add R/sysdata.rda
|
||||||
git add NAMESPACE
|
git add NAMESPACE
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 1.8.2.9135
|
Version: 1.8.2.9136
|
||||||
Date: 2023-02-18
|
Date: 2023-02-18
|
||||||
Title: Antimicrobial Resistance Data Analysis
|
Title: Antimicrobial Resistance Data Analysis
|
||||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
|||||||
# AMR 1.8.2.9135
|
# AMR 1.8.2.9136
|
||||||
|
|
||||||
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ stop_ifnot_installed <- function(package) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_is_available <- function(pkg, also_load = TRUE, min_version = NULL) {
|
pkg_is_available <- function(pkg, also_load = FALSE, min_version = NULL) {
|
||||||
if (also_load == TRUE) {
|
if (also_load == TRUE) {
|
||||||
out <- suppressWarnings(require(pkg, character.only = TRUE, warn.conflicts = FALSE))
|
out <- suppressWarnings(require(pkg, character.only = TRUE, warn.conflicts = FALSE))
|
||||||
} else {
|
} else {
|
||||||
@ -1318,14 +1318,14 @@ create_pillar_column <- function(x, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
as_original_data_class <- function(df, old_class = NULL, extra_class = NULL) {
|
as_original_data_class <- function(df, old_class = NULL, extra_class = NULL) {
|
||||||
if ("tbl_df" %in% old_class && pkg_is_available("tibble", also_load = FALSE)) {
|
if ("tbl_df" %in% old_class && pkg_is_available("tibble")) {
|
||||||
# this will then also remove groups
|
# this will then also remove groups
|
||||||
fn <- import_fn("as_tibble", "tibble")
|
fn <- import_fn("as_tibble", "tibble")
|
||||||
} else if ("tbl_ts" %in% old_class && pkg_is_available("tsibble", also_load = FALSE)) {
|
} else if ("tbl_ts" %in% old_class && pkg_is_available("tsibble")) {
|
||||||
fn <- import_fn("as_tsibble", "tsibble")
|
fn <- import_fn("as_tsibble", "tsibble")
|
||||||
} else if ("data.table" %in% old_class && pkg_is_available("data.table", also_load = FALSE)) {
|
} else if ("data.table" %in% old_class && pkg_is_available("data.table")) {
|
||||||
fn <- import_fn("as.data.table", "data.table")
|
fn <- import_fn("as.data.table", "data.table")
|
||||||
} else if ("tabyl" %in% old_class && pkg_is_available("janitor", also_load = FALSE)) {
|
} else if ("tabyl" %in% old_class && pkg_is_available("janitor")) {
|
||||||
fn <- import_fn("as_tabyl", "janitor")
|
fn <- import_fn("as_tabyl", "janitor")
|
||||||
} else {
|
} else {
|
||||||
fn <- function(x) base::as.data.frame(df, stringsAsFactors = FALSE)
|
fn <- function(x) base::as.data.frame(df, stringsAsFactors = FALSE)
|
||||||
|
@ -563,6 +563,7 @@ print.antibiogram <- function(x, as_kable = !interactive(), italicise = TRUE, ..
|
|||||||
meet_criteria(italicise, allow_class = "logical", has_length = 1)
|
meet_criteria(italicise, allow_class = "logical", has_length = 1)
|
||||||
|
|
||||||
if (isTRUE(as_kable) &&
|
if (isTRUE(as_kable) &&
|
||||||
|
pkg_is_available("knitr") &&
|
||||||
# be sure not to run kable in pkgdown for our website generation
|
# be sure not to run kable in pkgdown for our website generation
|
||||||
!(missing(as_kable) && identical(Sys.getenv("IN_PKGDOWN"), "true"))) {
|
!(missing(as_kable) && identical(Sys.getenv("IN_PKGDOWN"), "true"))) {
|
||||||
out <- knitr::kable(x, ...)
|
out <- knitr::kable(x, ...)
|
||||||
|
@ -1219,7 +1219,7 @@ eucast_dosage <- function(ab, administration = "iv", version_breakpoints = 12.0)
|
|||||||
rownames(out) <- NULL
|
rownames(out) <- NULL
|
||||||
out$ab <- ab
|
out$ab <- ab
|
||||||
out$name <- ab_name(ab, language = NULL)
|
out$name <- ab_name(ab, language = NULL)
|
||||||
if (pkg_is_available("tibble", also_load = FALSE)) {
|
if (pkg_is_available("tibble")) {
|
||||||
import_fn("as_tibble", "tibble")(out)
|
import_fn("as_tibble", "tibble")(out)
|
||||||
} else {
|
} else {
|
||||||
out
|
out
|
||||||
|
@ -130,7 +130,7 @@ join_microorganisms <- function(type, x, by, suffix, ...) {
|
|||||||
add_MO_lookup_to_AMR_env()
|
add_MO_lookup_to_AMR_env()
|
||||||
|
|
||||||
if (!is.data.frame(x)) {
|
if (!is.data.frame(x)) {
|
||||||
if (pkg_is_available("tibble", also_load = FALSE)) {
|
if (pkg_is_available("tibble")) {
|
||||||
x <- import_fn("tibble", "tibble")(mo = x)
|
x <- import_fn("tibble", "tibble")(mo = x)
|
||||||
} else {
|
} else {
|
||||||
x <- data.frame(mo = x, stringsAsFactors = FALSE)
|
x <- data.frame(mo = x, stringsAsFactors = FALSE)
|
||||||
|
2
R/sir.R
2
R/sir.R
@ -1080,7 +1080,7 @@ sir_interpretation_history <- function(clean = FALSE) {
|
|||||||
# sort descending on time
|
# sort descending on time
|
||||||
out <- out[order(out$datetime, decreasing = TRUE), , drop = FALSE]
|
out <- out[order(out$datetime, decreasing = TRUE), , drop = FALSE]
|
||||||
|
|
||||||
if (pkg_is_available("tibble", also_load = FALSE)) {
|
if (pkg_is_available("tibble")) {
|
||||||
import_fn("as_tibble", "tibble")(out)
|
import_fn("as_tibble", "tibble")(out)
|
||||||
} else {
|
} else {
|
||||||
out
|
out
|
||||||
|
4
R/zzz.R
4
R/zzz.R
@ -112,7 +112,7 @@ if (utf8_supported && !is_latex) {
|
|||||||
s3_register("cleaner::freq", "mo")
|
s3_register("cleaner::freq", "mo")
|
||||||
s3_register("cleaner::freq", "sir")
|
s3_register("cleaner::freq", "sir")
|
||||||
# Support for skim() from the skimr package
|
# Support for skim() from the skimr package
|
||||||
if (pkg_is_available("skimr", also_load = FALSE, min_version = "2.0.0")) {
|
if (pkg_is_available("skimr", min_version = "2.0.0")) {
|
||||||
s3_register("skimr::get_skimmers", "mo")
|
s3_register("skimr::get_skimmers", "mo")
|
||||||
s3_register("skimr::get_skimmers", "sir")
|
s3_register("skimr::get_skimmers", "sir")
|
||||||
s3_register("skimr::get_skimmers", "mic")
|
s3_register("skimr::get_skimmers", "mic")
|
||||||
@ -178,7 +178,7 @@ if (utf8_supported && !is_latex) {
|
|||||||
try(invisible(get_mo_source()), silent = TRUE)
|
try(invisible(get_mo_source()), silent = TRUE)
|
||||||
}
|
}
|
||||||
# be sure to print tibbles as tibbles
|
# be sure to print tibbles as tibbles
|
||||||
if (pkg_is_available("tibble", also_load = FALSE)) {
|
if (pkg_is_available("tibble")) {
|
||||||
try(loadNamespace("tibble"), silent = TRUE)
|
try(loadNamespace("tibble"), silent = TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ expect_identical(suppressWarnings(rsi_df(example_isolates)),
|
|||||||
expect_identical(suppressWarnings(is.rsi.eligible(example_isolates)),
|
expect_identical(suppressWarnings(is.rsi.eligible(example_isolates)),
|
||||||
suppressWarnings(is_sir_eligible(example_isolates)))
|
suppressWarnings(is_sir_eligible(example_isolates)))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("ggplot2", also_load = FALSE)) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_equal(suppressWarnings(ggplot_rsi(example_isolates[, c("CIP", "GEN", "TOB")])),
|
expect_equal(suppressWarnings(ggplot_rsi(example_isolates[, c("CIP", "GEN", "TOB")])),
|
||||||
suppressWarnings(ggplot_sir(example_isolates[, c("CIP", "GEN", "TOB")])))
|
suppressWarnings(ggplot_sir(example_isolates[, c("CIP", "GEN", "TOB")])))
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ expect_equal(AMR:::trimws2(" test ", "r"), " test")
|
|||||||
# expect_warning(AMR:::get_column_abx(example_isolates, hard_dependencies = "FUS"))
|
# expect_warning(AMR:::get_column_abx(example_isolates, hard_dependencies = "FUS"))
|
||||||
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
|
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
# 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 = TRUE))
|
||||||
# expect_warning(AMR:::get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = FALSE))
|
# 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 run a test that checks for this:
|
# we rely on "grouped_tbl" being a class of grouped tibbles, so run a test that checks for this:
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward)))
|
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward)))
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ expect_identical(
|
|||||||
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")
|
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_identical(
|
expect_identical(
|
||||||
example_isolates %>% set_ab_names(),
|
example_isolates %>% set_ab_names(),
|
||||||
example_isolates %>% rename_with(set_ab_names)
|
example_isolates %>% rename_with(set_ab_names)
|
||||||
|
@ -95,7 +95,7 @@ expect_identical(
|
|||||||
c("gen", "tobra")
|
c("gen", "tobra")
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_equal(example_isolates %>% select(administrable_per_os() & penicillins()) %>% ncol(), 5, tolerance = 0.5)
|
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(), 7, tolerance = 0.5)
|
||||||
expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5)
|
expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5)
|
||||||
|
@ -120,12 +120,12 @@ expect_silent(plot(ab7))
|
|||||||
expect_silent(plot(ab8))
|
expect_silent(plot(ab8))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_inherits(autoplot(ab1), "gg")
|
expect_inherits(ggplot2::autoplot(ab1), "gg")
|
||||||
expect_inherits(autoplot(ab2), "gg")
|
expect_inherits(ggplot2::autoplot(ab2), "gg")
|
||||||
expect_inherits(autoplot(ab3), "gg")
|
expect_inherits(ggplot2::autoplot(ab3), "gg")
|
||||||
expect_inherits(autoplot(ab4), "gg")
|
expect_inherits(ggplot2::autoplot(ab4), "gg")
|
||||||
expect_inherits(autoplot(ab5), "gg")
|
expect_inherits(ggplot2::autoplot(ab5), "gg")
|
||||||
expect_inherits(autoplot(ab6), "gg")
|
expect_inherits(ggplot2::autoplot(ab6), "gg")
|
||||||
expect_inherits(autoplot(ab7), "gg")
|
expect_inherits(ggplot2::autoplot(ab7), "gg")
|
||||||
expect_inherits(autoplot(ab8), "gg")
|
expect_inherits(ggplot2::autoplot(ab8), "gg")
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("curl", also_load = FALSE) &&
|
if (AMR:::pkg_is_available("curl") &&
|
||||||
AMR:::pkg_is_available("rvest", also_load = FALSE) &&
|
AMR:::pkg_is_available("rvest") &&
|
||||||
AMR:::pkg_is_available("xml2", also_load = FALSE) &&
|
AMR:::pkg_is_available("xml2") &&
|
||||||
tryCatch(curl::has_internet(), error = function(e) FALSE)) {
|
tryCatch(curl::has_internet(), error = function(e) FALSE)) {
|
||||||
expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1)
|
expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1)
|
||||||
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5)
|
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5)
|
||||||
|
@ -32,7 +32,7 @@ expect_inherits(b, "bug_drug_combinations")
|
|||||||
expect_stdout(suppressMessages(print(b)))
|
expect_stdout(suppressMessages(print(b)))
|
||||||
expect_true(is.data.frame(format(b)))
|
expect_true(is.data.frame(format(b)))
|
||||||
expect_true(is.data.frame(format(b, add_ab_group = FALSE)))
|
expect_true(is.data.frame(format(b, add_ab_group = FALSE)))
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_true(example_isolates %>%
|
expect_true(example_isolates %>%
|
||||||
group_by(ward) %>%
|
group_by(ward) %>%
|
||||||
bug_drug_combinations(FUN = mo_gramstain) %>%
|
bug_drug_combinations(FUN = mo_gramstain) %>%
|
||||||
|
@ -58,7 +58,7 @@ expect_error(count_susceptible("test", as_percent = "test"))
|
|||||||
expect_error(count_df(c("A", "B", "C")))
|
expect_error(count_df(c("A", "B", "C")))
|
||||||
expect_error(count_df(example_isolates[, "date", drop = TRUE]))
|
expect_error(count_df(example_isolates[, "date", drop = TRUE]))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_equal(example_isolates %>% count_susceptible(AMC), 1433)
|
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 = TRUE), 1687)
|
||||||
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = FALSE), 1764)
|
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = FALSE), 1764)
|
||||||
|
@ -55,7 +55,7 @@ expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$m
|
|||||||
# antibiotic names must always be coercible to their original AB code
|
# antibiotic names must always be coercible to their original AB code
|
||||||
expect_identical(as.ab(antibiotics$name), antibiotics$ab)
|
expect_identical(as.ab(antibiotics$name), antibiotics$ab)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("tibble", also_load = FALSE)) {
|
if (AMR:::pkg_is_available("tibble")) {
|
||||||
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
|
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
|
||||||
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE]
|
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE]
|
||||||
for (i in seq_len(length(datasets))) {
|
for (i in seq_len(length(datasets))) {
|
||||||
|
@ -48,12 +48,12 @@ expect_silent(plot(as.disk(c(10, 20, 40))))
|
|||||||
expect_silent(plot(as.disk(c(10, 20, 40)), expand = FALSE))
|
expect_silent(plot(as.disk(c(10, 20, 40)), expand = FALSE))
|
||||||
expect_silent(plot(as.disk(c(10, 20, 40)), mo = "Escherichia coli", ab = "cipr"))
|
expect_silent(plot(as.disk(c(10, 20, 40)), mo = "Escherichia coli", ab = "cipr"))
|
||||||
if (AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_inherits(autoplot(as.disk(c(10, 20, 40))), "gg")
|
expect_inherits(ggplot2::autoplot(as.disk(c(10, 20, 40))), "gg")
|
||||||
expect_inherits(autoplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg")
|
expect_inherits(ggplot2::autoplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg")
|
||||||
expect_inherits(autoplot(as.disk(c(10, 20, 40)), mo = "Escherichia coli", ab = "cipr"), "gg")
|
expect_inherits(ggplot2::autoplot(as.disk(c(10, 20, 40)), mo = "Escherichia coli", ab = "cipr"), "gg")
|
||||||
}
|
}
|
||||||
expect_stdout(print(as.disk(12)))
|
expect_stdout(print(as.disk(12)))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("tibble")) {
|
||||||
expect_stdout(print(tibble(d = as.disk(12))))
|
expect_stdout(print(tibble::tibble(d = as.disk(12))))
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ expect_equal(
|
|||||||
c(1, 2, 2, 2, 3)
|
c(1, 2, 2, 2, 3)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_identical(
|
expect_identical(
|
||||||
test_df %>% group_by(patient_id) %>% mutate(f = is_new_episode(date, 365)) %>% pull(f),
|
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)
|
c(TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE)
|
||||||
|
@ -98,7 +98,7 @@ b <- data.frame(
|
|||||||
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
||||||
|
|
||||||
# piperacillin must be R in Enterobacteriaceae when tica is R
|
# piperacillin must be R in Enterobacteriaceae when tica is R
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_equal(
|
expect_equal(
|
||||||
suppressWarnings(
|
suppressWarnings(
|
||||||
example_isolates %>%
|
example_isolates %>%
|
||||||
@ -150,7 +150,7 @@ expect_equal(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# also test norf
|
# also test norf
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_stdout(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
|
expect_stdout(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ expect_error(first_isolate(example_isolates,
|
|||||||
col_mo = "mo"
|
col_mo = "mo"
|
||||||
))
|
))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
# if mo is not an mo class, result should be the same
|
# if mo is not an mo class, result should be the same
|
||||||
expect_identical(
|
expect_identical(
|
||||||
example_isolates %>%
|
example_isolates %>%
|
||||||
|
@ -27,7 +27,8 @@
|
|||||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE) &&
|
||||||
|
AMR:::pkg_is_available("ggplot2", also_load = TRUE)) {
|
||||||
pdf(NULL) # prevent Rplots.pdf being created
|
pdf(NULL) # prevent Rplots.pdf being created
|
||||||
|
|
||||||
# data should be equal
|
# data should be equal
|
||||||
|
@ -278,7 +278,7 @@ expect_error(custom_mdro_guideline("test" ~ A))
|
|||||||
# ))
|
# ))
|
||||||
|
|
||||||
# print groups
|
# print groups
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_stdout(x <- mdro(example_isolates %>% group_by(ward), info = TRUE, pct_required_classes = 0))
|
expect_stdout(x <- mdro(example_isolates %>% group_by(ward), info = TRUE, pct_required_classes = 0))
|
||||||
expect_stdout(x <- mdro(example_isolates %>% group_by(ward), guideline = custom, info = TRUE))
|
expect_stdout(x <- mdro(example_isolates %>% group_by(ward), guideline = custom, info = TRUE))
|
||||||
}
|
}
|
||||||
|
@ -63,16 +63,16 @@ expect_silent(plot(as.mic(c(1, 2, 4, 8))))
|
|||||||
expect_silent(plot(as.mic(c(1, 2, 4, 8)), expand = FALSE))
|
expect_silent(plot(as.mic(c(1, 2, 4, 8)), expand = FALSE))
|
||||||
expect_silent(plot(as.mic(c(1, 2, 4, 8)), mo = "Escherichia coli", ab = "cipr"))
|
expect_silent(plot(as.mic(c(1, 2, 4, 8)), mo = "Escherichia coli", ab = "cipr"))
|
||||||
if (AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_inherits(autoplot(as.mic(c(1, 2, 4, 8))), "gg")
|
expect_inherits(ggplot2::autoplot(as.mic(c(1, 2, 4, 8))), "gg")
|
||||||
expect_inherits(autoplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg")
|
expect_inherits(ggplot2::autoplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg")
|
||||||
expect_inherits(autoplot(as.mic(c(1, 2, 4, 8, 32)), mo = "Escherichia coli", ab = "cipr"), "gg")
|
expect_inherits(ggplot2::autoplot(as.mic(c(1, 2, 4, 8, 32)), mo = "Escherichia coli", ab = "cipr"), "gg")
|
||||||
}
|
}
|
||||||
expect_stdout(print(as.mic(c(1, 2, 4, 8))))
|
expect_stdout(print(as.mic(c(1, 2, 4, 8))))
|
||||||
|
|
||||||
expect_inherits(summary(as.mic(c(2, 8))), c("summaryDefault", "table"))
|
expect_inherits(summary(as.mic(c(2, 8))), c("summaryDefault", "table"))
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("tibble")) {
|
||||||
expect_stdout(print(tibble(m = as.mic(2:4))))
|
expect_stdout(print(tibble::tibble(m = as.mic(2:4))))
|
||||||
}
|
}
|
||||||
|
|
||||||
# all mathematical operations
|
# all mathematical operations
|
||||||
|
@ -160,7 +160,7 @@ expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRP
|
|||||||
expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR")
|
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
|
expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
# select with one column
|
# select with one column
|
||||||
expect_identical(
|
expect_identical(
|
||||||
example_isolates %>%
|
example_isolates %>%
|
||||||
@ -302,9 +302,9 @@ expect_equal(
|
|||||||
c("F_YEAST", "F_FUNGUS")
|
c("F_YEAST", "F_FUNGUS")
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("tibble")) {
|
||||||
# print tibble
|
# print tibble
|
||||||
expect_stdout(print(tibble(mo = as.mo("B_ESCHR_COLI"))))
|
expect_stdout(print(tibble::tibble(mo = as.mo("B_ESCHR_COLI"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
# assigning and subsetting
|
# assigning and subsetting
|
||||||
|
@ -198,7 +198,7 @@ expect_equal(
|
|||||||
mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
|
mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
|
||||||
"Escherichia coli"
|
"Escherichia coli"
|
||||||
)
|
)
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
|
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
|
||||||
730,
|
730,
|
||||||
tolerance = 0.5
|
tolerance = 0.5
|
||||||
|
@ -57,7 +57,7 @@ if (AMR:::pkg_is_available("ggplot2")) {
|
|||||||
ggplot_pca(pca_model, arrows_textangled = FALSE)
|
ggplot_pca(pca_model, arrows_textangled = FALSE)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
resistance_data <- example_isolates %>%
|
resistance_data <- example_isolates %>%
|
||||||
group_by(
|
group_by(
|
||||||
order = mo_order(mo),
|
order = mo_order(mo),
|
||||||
|
@ -47,7 +47,7 @@ expect_equal(
|
|||||||
proportion_SI(example_isolates$AMX)
|
proportion_SI(example_isolates$AMX)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_equal(example_isolates %>% proportion_SI(AMC),
|
expect_equal(example_isolates %>% proportion_SI(AMC),
|
||||||
0.7626397,
|
0.7626397,
|
||||||
tolerance = 0.0001
|
tolerance = 0.0001
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_stdout(AMX_R <- example_isolates %>%
|
expect_stdout(AMX_R <- example_isolates %>%
|
||||||
filter(mo == "B_ESCHR_COLI") %>%
|
filter(mo == "B_ESCHR_COLI") %>%
|
||||||
sir_predict(
|
sir_predict(
|
||||||
@ -52,7 +52,7 @@ pdf(NULL) # prevent Rplots.pdf being created
|
|||||||
expect_silent(plot(x))
|
expect_silent(plot(x))
|
||||||
if (AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_silent(ggplot_sir_predict(x))
|
expect_silent(ggplot_sir_predict(x))
|
||||||
expect_silent(autoplot(x))
|
expect_silent(ggplot2::autoplot(x))
|
||||||
expect_error(ggplot_sir_predict(example_isolates))
|
expect_error(ggplot_sir_predict(example_isolates))
|
||||||
}
|
}
|
||||||
expect_stdout(sir_predict(
|
expect_stdout(sir_predict(
|
||||||
|
@ -45,7 +45,7 @@ pdf(NULL) # prevent Rplots.pdf being created
|
|||||||
expect_silent(barplot(as.sir(c("S", "I", "R"))))
|
expect_silent(barplot(as.sir(c("S", "I", "R"))))
|
||||||
expect_silent(plot(as.sir(c("S", "I", "R"))))
|
expect_silent(plot(as.sir(c("S", "I", "R"))))
|
||||||
if (AMR:::pkg_is_available("ggplot2")) {
|
if (AMR:::pkg_is_available("ggplot2")) {
|
||||||
expect_inherits(autoplot(as.sir(c("S", "I", "R"))), "gg")
|
expect_inherits(ggplot2::autoplot(as.sir(c("S", "I", "R"))), "gg")
|
||||||
}
|
}
|
||||||
expect_stdout(print(as.sir(c("S", "I", "R"))))
|
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"))
|
||||||
@ -68,7 +68,7 @@ expect_identical(
|
|||||||
expect_error(as.sir.mic(as.mic(16)))
|
expect_error(as.sir.mic(as.mic(16)))
|
||||||
expect_error(as.sir.disk(as.disk(16)))
|
expect_error(as.sir.disk(as.disk(16)))
|
||||||
expect_error(get_guideline("this one does not exist"))
|
expect_error(get_guideline("this one does not exist"))
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
# 40 sir columns
|
# 40 sir columns
|
||||||
expect_equal(
|
expect_equal(
|
||||||
example_isolates %>%
|
example_isolates %>%
|
||||||
@ -88,12 +88,12 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
|||||||
pull(MEM) %>%
|
pull(MEM) %>%
|
||||||
is.sir())
|
is.sir())
|
||||||
}
|
}
|
||||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) {
|
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||||
expect_inherits(
|
expect_inherits(
|
||||||
skim(example_isolates),
|
skim(example_isolates),
|
||||||
"data.frame"
|
"data.frame"
|
||||||
)
|
)
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_inherits(
|
expect_inherits(
|
||||||
example_isolates %>%
|
example_isolates %>%
|
||||||
mutate(
|
mutate(
|
||||||
@ -146,7 +146,7 @@ expect_equal(
|
|||||||
suppressMessages(as.sir(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
suppressMessages(as.sir(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")),
|
||||||
as.sir("R")
|
as.sir("R")
|
||||||
)
|
)
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_true(suppressWarnings(example_isolates %>%
|
expect_true(suppressWarnings(example_isolates %>%
|
||||||
mutate(amox_mic = as.mic(2)) %>%
|
mutate(amox_mic = as.mic(2)) %>%
|
||||||
select(mo, amox_mic) %>%
|
select(mo, amox_mic) %>%
|
||||||
@ -188,7 +188,7 @@ expect_equal(
|
|||||||
),
|
),
|
||||||
"R"
|
"R"
|
||||||
)
|
)
|
||||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
|
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||||
expect_true(example_isolates %>%
|
expect_true(example_isolates %>%
|
||||||
mutate(amox_disk = as.disk(15)) %>%
|
mutate(amox_disk = as.disk(15)) %>%
|
||||||
select(mo, amox_disk) %>%
|
select(mo, amox_disk) %>%
|
||||||
|
@ -28,12 +28,12 @@
|
|||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
# extra tests for {vctrs} pkg support
|
# extra tests for {vctrs} pkg support
|
||||||
if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) {
|
if (AMR:::pkg_is_available("tibble")) {
|
||||||
test <- dplyr::tibble(ab = as.ab("CIP"),
|
test <- tibble::tibble(ab = as.ab("CIP"),
|
||||||
mo = as.mo("Escherichia coli"),
|
mo = as.mo("Escherichia coli"),
|
||||||
mic = as.mic(2),
|
mic = as.mic(2),
|
||||||
disk = as.disk(20),
|
disk = as.disk(20),
|
||||||
sir = as.sir("S"))
|
sir = as.sir("S"))
|
||||||
check1 <- lapply(test, class)
|
check1 <- lapply(test, class)
|
||||||
test[1, "ab"] <- "GEN"
|
test[1, "ab"] <- "GEN"
|
||||||
test[1, "mo"] <- "B_KLBSL_PNMN"
|
test[1, "mo"] <- "B_KLBSL_PNMN"
|
||||||
@ -46,8 +46,8 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) {
|
|||||||
check2 <- lapply(test, class)
|
check2 <- lapply(test, class)
|
||||||
expect_identical(check1, check2)
|
expect_identical(check1, check2)
|
||||||
|
|
||||||
test <- dplyr::tibble(cipro = as.sir("S"),
|
test <- tibble::tibble(cipro = as.sir("S"),
|
||||||
variable = "test")
|
variable = "test")
|
||||||
expect_equal(nrow(test[quinolones() == "S", ]), 1)
|
expect_equal(nrow(test[quinolones() == "S", ]), 1)
|
||||||
expect_equal(nrow(test[quinolones() == "R", ]), 0)
|
expect_equal(nrow(test[quinolones() == "R", ]), 0)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ call_functions <- c(
|
|||||||
"xlab" = "ggplot2",
|
"xlab" = "ggplot2",
|
||||||
"ylab" = "ggplot2"
|
"ylab" = "ggplot2"
|
||||||
)
|
)
|
||||||
if (AMR:::pkg_is_available("skimr", also_load = FALSE, min_version = "2.0.0")) {
|
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) {
|
||||||
call_functions <- c(call_functions,
|
call_functions <- c(call_functions,
|
||||||
# skimr
|
# skimr
|
||||||
"inline_hist" = "skimr",
|
"inline_hist" = "skimr",
|
||||||
|
Loading…
Reference in New Issue
Block a user