1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 23:21:56 +02:00

fix scale functions

This commit is contained in:
2023-12-03 16:51:54 +01:00
parent c7461766ce
commit 7059568581
6 changed files with 41 additions and 51 deletions

View File

@ -27,38 +27,4 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
sir <- random_sir(100)
rsi <- sir
class(rsi) <- gsub("sir", "rsi", class(rsi))
mic <- random_mic(100)
disk <- random_disk(100)
expect_identical(summary(sir), summary(rsi))
expect_identical(c(sir), c(rsi))
expect_identical(suppressWarnings(suppressMessages(as.rsi(as.character(rsi)))),
suppressWarnings(suppressMessages(as.sir(as.character(sir)))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(mic, mo = "Escherichia coli", ab = "CIP"))),
suppressWarnings(suppressMessages(as.sir(mic, mo = "Escherichia coli", ab = "CIP"))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(disk, mo = "Escherichia coli", ab = "CIP"))),
suppressWarnings(suppressMessages(as.sir(disk, mo = "Escherichia coli", ab = "CIP"))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(data.frame(CIP = mic, mo = "Escherichia coli")))),
suppressWarnings(suppressMessages(as.sir(data.frame(CIP = mic, mo = "Escherichia coli")))))
expect_identical(suppressWarnings(n_rsi(example_isolates$CIP)),
suppressWarnings(n_sir(example_isolates$CIP)))
expect_identical(suppressWarnings(rsi_df(example_isolates)),
suppressWarnings(sir_df(example_isolates)))
expect_identical(suppressWarnings(is.rsi.eligible(example_isolates)),
suppressWarnings(is_sir_eligible(example_isolates)))
if (AMR:::pkg_is_available("ggplot2")) {
expect_equal(suppressWarnings(ggplot_rsi(example_isolates[, c("CIP", "GEN", "TOB")])),
suppressWarnings(ggplot_sir(example_isolates[, c("CIP", "GEN", "TOB")])))
p <- ggplot2::ggplot(example_isolates[, c("CIP", "GEN", "TOB")])
expect_equal(suppressWarnings(p + geom_rsi() + scale_rsi_colours() + labels_rsi_count() + facet_rsi() + theme_rsi()),
suppressWarnings(p + geom_sir() + scale_sir_colours() + labels_sir_count() + facet_sir() + theme_sir()))
}

View File

@ -86,10 +86,14 @@ call_functions <- c(
"ggplot" = "ggplot2",
"labs" = "ggplot2",
"layer" = "ggplot2",
"position_fill" = "ggplot2",
"position_dodge2" = "ggplot2",
"position_fill" = "ggplot2",
"scale_colour_discrete" = "ggplot2",
"scale_fill_discrete" = "ggplot2",
"scale_fill_manual" = "ggplot2",
"scale_x_discrete" = "ggplot2",
"scale_y_continuous" = "ggplot2",
"scale_y_discrete" = "ggplot2",
"theme" = "ggplot2",
"theme_minimal" = "ggplot2",
"unit" = "ggplot2",
@ -127,7 +131,7 @@ for (i in seq_len(length(import_functions))) {
expect_true(!is.null(AMR:::import_fn(name = fn, pkg = pkg, error_on_fail = FALSE)),
info = paste0("does not exist (anymore): function `", pkg, "::", fn, "()`")
)
} else {
} else if (pkg != "rstudioapi") {
warning("Package '", pkg, "' does not exist anymore")
}
}
@ -140,3 +144,12 @@ if (AMR:::pkg_is_available("cli")) {
if (AMR:::pkg_is_available("cli")) {
expect_true(!is.null(cli::symbol$ellipsis))
}
if (AMR:::pkg_is_available("ggplot2")) {
# the scale_*_mic() functions rely on these
expect_true(is.function(ggplot2::scale_x_discrete()$transform))
expect_true(is.function(ggplot2::scale_y_discrete()$transform))
expect_true(is.function(ggplot2::scale_colour_discrete()$transform))
expect_true(is.function(ggplot2::scale_fill_discrete()$transform))
}