diff --git a/.github/prehooks/pre-commit b/.github/prehooks/pre-commit index 6649dccd..948df582 100755 --- a/.github/prehooks/pre-commit +++ b/.github/prehooks/pre-commit @@ -37,7 +37,7 @@ if command -v Rscript > /dev/null; then Rscript -e "source('data-raw/_pre_commit_hook.R')" currentpkg=$(Rscript -e "cat(pkgload::pkg_name())") 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 R/sysdata.rda git add NAMESPACE diff --git a/DESCRIPTION b/DESCRIPTION index 28884546..179a5483 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.2.9135 +Version: 1.8.2.9136 Date: 2023-02-18 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 8eaa35ae..f6aae2d5 100755 --- a/NEWS.md +++ b/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!)* diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 1ccac50c..54bf0dcb 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -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) { out <- suppressWarnings(require(pkg, character.only = TRUE, warn.conflicts = FALSE)) } else { @@ -1318,14 +1318,14 @@ create_pillar_column <- function(x, ...) { } 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 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") - } 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") - } 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") } else { fn <- function(x) base::as.data.frame(df, stringsAsFactors = FALSE) diff --git a/R/antibiogram.R b/R/antibiogram.R index 259850c7..f969eeb9 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -563,6 +563,7 @@ print.antibiogram <- function(x, as_kable = !interactive(), italicise = TRUE, .. meet_criteria(italicise, allow_class = "logical", has_length = 1) if (isTRUE(as_kable) && + pkg_is_available("knitr") && # be sure not to run kable in pkgdown for our website generation !(missing(as_kable) && identical(Sys.getenv("IN_PKGDOWN"), "true"))) { out <- knitr::kable(x, ...) diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 05995079..348cb1dd 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -1219,7 +1219,7 @@ eucast_dosage <- function(ab, administration = "iv", version_breakpoints = 12.0) rownames(out) <- NULL out$ab <- ab 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) } else { out diff --git a/R/join_microorganisms.R b/R/join_microorganisms.R index e3817ff9..9f8532df 100755 --- a/R/join_microorganisms.R +++ b/R/join_microorganisms.R @@ -130,7 +130,7 @@ join_microorganisms <- function(type, x, by, suffix, ...) { add_MO_lookup_to_AMR_env() 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) } else { x <- data.frame(mo = x, stringsAsFactors = FALSE) diff --git a/R/sir.R b/R/sir.R index 596371e2..f59757cc 100755 --- a/R/sir.R +++ b/R/sir.R @@ -1080,7 +1080,7 @@ sir_interpretation_history <- function(clean = FALSE) { # sort descending on time 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) } else { out diff --git a/R/zzz.R b/R/zzz.R index 1aea7f17..4685e3ab 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -112,7 +112,7 @@ if (utf8_supported && !is_latex) { s3_register("cleaner::freq", "mo") s3_register("cleaner::freq", "sir") # 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", "sir") s3_register("skimr::get_skimmers", "mic") @@ -178,7 +178,7 @@ if (utf8_supported && !is_latex) { try(invisible(get_mo_source()), silent = TRUE) } # 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) } diff --git a/inst/tinytest/test-_deprecated.R b/inst/tinytest/test-_deprecated.R index c20f9c27..6fc2e4ae 100644 --- a/inst/tinytest/test-_deprecated.R +++ b/inst/tinytest/test-_deprecated.R @@ -54,7 +54,7 @@ expect_identical(suppressWarnings(rsi_df(example_isolates)), expect_identical(suppressWarnings(is.rsi.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")])), suppressWarnings(ggplot_sir(example_isolates[, c("CIP", "GEN", "TOB")]))) diff --git a/inst/tinytest/test-_misc.R b/inst/tinytest/test-_misc.R index a5353548..3313633b 100755 --- a/inst/tinytest/test-_misc.R +++ b/inst/tinytest/test-_misc.R @@ -50,12 +50,12 @@ expect_equal(AMR:::trimws2(" test ", "r"), " test") # 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", 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 = FALSE)) } # 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))) } diff --git a/inst/tinytest/test-ab_property.R b/inst/tinytest/test-ab_property.R index d3abd53f..aabfb17a 100644 --- a/inst/tinytest/test-ab_property.R +++ b/inst/tinytest/test-ab_property.R @@ -82,7 +82,7 @@ expect_identical( 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( example_isolates %>% set_ab_names(), example_isolates %>% rename_with(set_ab_names) diff --git a/inst/tinytest/test-ab_selectors.R b/inst/tinytest/test-ab_selectors.R index c01562a2..5a74e545 100644 --- a/inst/tinytest/test-ab_selectors.R +++ b/inst/tinytest/test-ab_selectors.R @@ -95,7 +95,7 @@ expect_identical( 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_iv() & penicillins()) %>% ncol(), 7, tolerance = 0.5) expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5) diff --git a/inst/tinytest/test-antibiogram.R b/inst/tinytest/test-antibiogram.R index 8c925279..f551d28f 100644 --- a/inst/tinytest/test-antibiogram.R +++ b/inst/tinytest/test-antibiogram.R @@ -120,12 +120,12 @@ expect_silent(plot(ab7)) expect_silent(plot(ab8)) if (AMR:::pkg_is_available("ggplot2")) { - expect_inherits(autoplot(ab1), "gg") - expect_inherits(autoplot(ab2), "gg") - expect_inherits(autoplot(ab3), "gg") - expect_inherits(autoplot(ab4), "gg") - expect_inherits(autoplot(ab5), "gg") - expect_inherits(autoplot(ab6), "gg") - expect_inherits(autoplot(ab7), "gg") - expect_inherits(autoplot(ab8), "gg") + expect_inherits(ggplot2::autoplot(ab1), "gg") + expect_inherits(ggplot2::autoplot(ab2), "gg") + expect_inherits(ggplot2::autoplot(ab3), "gg") + expect_inherits(ggplot2::autoplot(ab4), "gg") + expect_inherits(ggplot2::autoplot(ab5), "gg") + expect_inherits(ggplot2::autoplot(ab6), "gg") + expect_inherits(ggplot2::autoplot(ab7), "gg") + expect_inherits(ggplot2::autoplot(ab8), "gg") } diff --git a/inst/tinytest/test-atc_online.R b/inst/tinytest/test-atc_online.R index 3dff8631..ca9d3e98 100644 --- a/inst/tinytest/test-atc_online.R +++ b/inst/tinytest/test-atc_online.R @@ -27,9 +27,9 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -if (AMR:::pkg_is_available("curl", also_load = FALSE) && - AMR:::pkg_is_available("rvest", also_load = FALSE) && - AMR:::pkg_is_available("xml2", also_load = FALSE) && +if (AMR:::pkg_is_available("curl") && + AMR:::pkg_is_available("rvest") && + AMR:::pkg_is_available("xml2") && tryCatch(curl::has_internet(), error = function(e) FALSE)) { expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1) expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5) diff --git a/inst/tinytest/test-bug_drug_combinations.R b/inst/tinytest/test-bug_drug_combinations.R index 4ec5eec0..79dab75e 100644 --- a/inst/tinytest/test-bug_drug_combinations.R +++ b/inst/tinytest/test-bug_drug_combinations.R @@ -32,7 +32,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, 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 %>% group_by(ward) %>% bug_drug_combinations(FUN = mo_gramstain) %>% diff --git a/inst/tinytest/test-count.R b/inst/tinytest/test-count.R index 9af023e0..ee86eeb5 100644 --- a/inst/tinytest/test-count.R +++ b/inst/tinytest/test-count.R @@ -58,7 +58,7 @@ expect_error(count_susceptible("test", as_percent = "test")) expect_error(count_df(c("A", "B", "C"))) 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, 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-data.R b/inst/tinytest/test-data.R index a2c203a2..f20fba76 100644 --- a/inst/tinytest/test-data.R +++ b/inst/tinytest/test-data.R @@ -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 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) datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE] for (i in seq_len(length(datasets))) { diff --git a/inst/tinytest/test-disk.R b/inst/tinytest/test-disk.R index 064beeb4..105630e3 100755 --- a/inst/tinytest/test-disk.R +++ b/inst/tinytest/test-disk.R @@ -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)), mo = "Escherichia coli", ab = "cipr")) if (AMR:::pkg_is_available("ggplot2")) { - expect_inherits(autoplot(as.disk(c(10, 20, 40))), "gg") - expect_inherits(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))), "gg") + expect_inherits(ggplot2::autoplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg") + expect_inherits(ggplot2::autoplot(as.disk(c(10, 20, 40)), mo = "Escherichia coli", ab = "cipr"), "gg") } expect_stdout(print(as.disk(12))) -if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { - expect_stdout(print(tibble(d = as.disk(12)))) +if (AMR:::pkg_is_available("tibble")) { + expect_stdout(print(tibble::tibble(d = as.disk(12)))) } diff --git a/inst/tinytest/test-episode.R b/inst/tinytest/test-episode.R index ee420dd2..c3fa1ccb 100644 --- a/inst/tinytest/test-episode.R +++ b/inst/tinytest/test-episode.R @@ -51,7 +51,7 @@ expect_equal( 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( 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 8f3efa36..4743c16d 100755 --- a/inst/tinytest/test-eucast_rules.R +++ b/inst/tinytest/test-eucast_rules.R @@ -98,7 +98,7 @@ b <- data.frame( 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", min_version = "1.0.0")) { +if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) { expect_equal( suppressWarnings( example_isolates %>% @@ -150,7 +150,7 @@ expect_equal( ) # 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))) } diff --git a/inst/tinytest/test-first_isolate.R b/inst/tinytest/test-first_isolate.R index 7cc03773..7a5b2c17 100755 --- a/inst/tinytest/test-first_isolate.R +++ b/inst/tinytest/test-first_isolate.R @@ -139,7 +139,7 @@ expect_error(first_isolate(example_isolates, 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 expect_identical( example_isolates %>% diff --git a/inst/tinytest/test-ggplot_rsi.R b/inst/tinytest/test-ggplot_rsi.R index cb5cd549..a4c116a9 100644 --- a/inst/tinytest/test-ggplot_rsi.R +++ b/inst/tinytest/test-ggplot_rsi.R @@ -27,7 +27,8 @@ # 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 # data should be equal diff --git a/inst/tinytest/test-mdro.R b/inst/tinytest/test-mdro.R index 6b829107..d1a8e0fe 100755 --- a/inst/tinytest/test-mdro.R +++ b/inst/tinytest/test-mdro.R @@ -278,7 +278,7 @@ expect_error(custom_mdro_guideline("test" ~ A)) # )) # 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), guideline = custom, info = TRUE)) } diff --git a/inst/tinytest/test-mic.R b/inst/tinytest/test-mic.R index 272a0318..e4b1bbe7 100755 --- a/inst/tinytest/test-mic.R +++ b/inst/tinytest/test-mic.R @@ -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)), mo = "Escherichia coli", ab = "cipr")) if (AMR:::pkg_is_available("ggplot2")) { - expect_inherits(autoplot(as.mic(c(1, 2, 4, 8))), "gg") - expect_inherits(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))), "gg") + expect_inherits(ggplot2::autoplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "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_inherits(summary(as.mic(c(2, 8))), c("summaryDefault", "table")) -if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { - expect_stdout(print(tibble(m = as.mic(2:4)))) +if (AMR:::pkg_is_available("tibble")) { + expect_stdout(print(tibble::tibble(m = as.mic(2:4)))) } # all mathematical operations diff --git a/inst/tinytest/test-mo.R b/inst/tinytest/test-mo.R index 3d17e5e8..1099015e 100644 --- a/inst/tinytest/test-mo.R +++ b/inst/tinytest/test-mo.R @@ -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 = 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 expect_identical( example_isolates %>% @@ -302,9 +302,9 @@ expect_equal( c("F_YEAST", "F_FUNGUS") ) -if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { +if (AMR:::pkg_is_available("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 diff --git a/inst/tinytest/test-mo_property.R b/inst/tinytest/test-mo_property.R index bc4d082c..c66e42b3 100644 --- a/inst/tinytest/test-mo_property.R +++ b/inst/tinytest/test-mo_property.R @@ -198,7 +198,7 @@ expect_equal( mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_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(), 730, tolerance = 0.5 diff --git a/inst/tinytest/test-pca.R b/inst/tinytest/test-pca.R index 02f27eeb..6df1f08d 100644 --- a/inst/tinytest/test-pca.R +++ b/inst/tinytest/test-pca.R @@ -57,7 +57,7 @@ if (AMR:::pkg_is_available("ggplot2")) { 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 %>% group_by( order = mo_order(mo), diff --git a/inst/tinytest/test-proportion.R b/inst/tinytest/test-proportion.R index b80d3e3f..62a2926f 100755 --- a/inst/tinytest/test-proportion.R +++ b/inst/tinytest/test-proportion.R @@ -47,7 +47,7 @@ expect_equal( 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), 0.7626397, tolerance = 0.0001 diff --git a/inst/tinytest/test-resistance_predict.R b/inst/tinytest/test-resistance_predict.R index 658c5ffb..53228ccb 100644 --- a/inst/tinytest/test-resistance_predict.R +++ b/inst/tinytest/test-resistance_predict.R @@ -27,7 +27,7 @@ # 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 %>% filter(mo == "B_ESCHR_COLI") %>% sir_predict( @@ -52,7 +52,7 @@ pdf(NULL) # prevent Rplots.pdf being created expect_silent(plot(x)) if (AMR:::pkg_is_available("ggplot2")) { expect_silent(ggplot_sir_predict(x)) - expect_silent(autoplot(x)) + expect_silent(ggplot2::autoplot(x)) expect_error(ggplot_sir_predict(example_isolates)) } expect_stdout(sir_predict( diff --git a/inst/tinytest/test-rsi.R b/inst/tinytest/test-rsi.R index e4ba121d..d85e01d4 100644 --- a/inst/tinytest/test-rsi.R +++ b/inst/tinytest/test-rsi.R @@ -45,7 +45,7 @@ pdf(NULL) # prevent Rplots.pdf being created 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.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_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.disk(as.disk(16))) 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 expect_equal( example_isolates %>% @@ -88,12 +88,12 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { pull(MEM) %>% 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( skim(example_isolates), "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( example_isolates %>% mutate( @@ -146,7 +146,7 @@ expect_equal( 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")) { +if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) { expect_true(suppressWarnings(example_isolates %>% mutate(amox_mic = as.mic(2)) %>% select(mo, amox_mic) %>% @@ -188,7 +188,7 @@ expect_equal( ), "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 %>% mutate(amox_disk = as.disk(15)) %>% select(mo, amox_disk) %>% diff --git a/inst/tinytest/test-vctrs.R b/inst/tinytest/test-vctrs.R index 76c5de43..4d07482c 100755 --- a/inst/tinytest/test-vctrs.R +++ b/inst/tinytest/test-vctrs.R @@ -28,12 +28,12 @@ # ==================================================================== # # extra tests for {vctrs} pkg support -if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) { - test <- dplyr::tibble(ab = as.ab("CIP"), - mo = as.mo("Escherichia coli"), - mic = as.mic(2), - disk = as.disk(20), - sir = as.sir("S")) +if (AMR:::pkg_is_available("tibble")) { + test <- tibble::tibble(ab = as.ab("CIP"), + mo = as.mo("Escherichia coli"), + mic = as.mic(2), + disk = as.disk(20), + sir = as.sir("S")) check1 <- lapply(test, class) test[1, "ab"] <- "GEN" test[1, "mo"] <- "B_KLBSL_PNMN" @@ -46,8 +46,8 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) { check2 <- lapply(test, class) expect_identical(check1, check2) - test <- dplyr::tibble(cipro = as.sir("S"), - variable = "test") + test <- tibble::tibble(cipro = as.sir("S"), + variable = "test") expect_equal(nrow(test[quinolones() == "S", ]), 1) expect_equal(nrow(test[quinolones() == "R", ]), 0) } diff --git a/inst/tinytest/test-zzz.R b/inst/tinytest/test-zzz.R index cebecfd4..d04d7189 100644 --- a/inst/tinytest/test-zzz.R +++ b/inst/tinytest/test-zzz.R @@ -90,7 +90,7 @@ call_functions <- c( "xlab" = "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, # skimr "inline_hist" = "skimr",