(v1.6.0.9028) new unit test flow

This commit is contained in:
dr. M.S. (Matthijs) Berends 2021-05-13 22:44:11 +02:00
parent 5b9fb8daf4
commit 9ed2f6490f
31 changed files with 108 additions and 99 deletions

View File

@ -78,8 +78,8 @@ jobs:
- {os: ubuntu-16.04, r: '3.5', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.5', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.4', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.4', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.3', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.3', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
# - {os: ubuntu-16.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
# - {os: ubuntu-16.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.1', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
env: env:
@ -161,14 +161,12 @@ jobs:
run: | run: |
tar -xf data-raw/AMR_latest.tar.gz tar -xf data-raw/AMR_latest.tar.gz
rm -rf AMR/vignettes rm -rf AMR/vignettes
Rscript -e "utils::installed.packages()" R CMD check AMR --no-manual --as-cran --no-vignettes --library='/Users/runner/work/_temp/Library'
R CMD check AMR --no-manual --as-cran
shell: bash shell: bash
- name: Show testthat output - name: Show testthat output
if: always() if: always()
run: | run: |
ls -lh
find . -name 'testthat.Rout*' -exec cat '{}' \; || true find . -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash shell: bash
@ -177,4 +175,4 @@ jobs:
uses: actions/upload-artifact@master uses: actions/upload-artifact@master
with: with:
name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results
path: check path: *.Rcheck

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 1.6.0.9027 Version: 1.6.0.9028
Date: 2021-05-13 Date: 2021-05-13
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Authors@R: c( Authors@R: c(

View File

@ -1,4 +1,4 @@
# `AMR` 1.6.0.9027 # `AMR` 1.6.0.9028
## <small>Last updated: 13 May 2021</small> ## <small>Last updated: 13 May 2021</small>
### New ### New

Binary file not shown.

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.io/AMR//index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.github.io/AMR//index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -42,7 +42,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>
@ -236,9 +236,9 @@
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small> <small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div> </div>
<div id="amr-1609027" class="section level1"> <div id="amr-1609028" class="section level1">
<h1 class="page-header" data-toc-text="1.6.0.9027"> <h1 class="page-header" data-toc-text="1.6.0.9028">
<a href="#amr-1609027" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9027</h1> <a href="#amr-1609028" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9028</h1>
<div id="last-updated-13-may-2021" class="section level2"> <div id="last-updated-13-may-2021" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-13-may-2021" class="anchor"></a><small>Last updated: 13 May 2021</small> <a href="#last-updated-13-may-2021" class="anchor"></a><small>Last updated: 13 May 2021</small>

View File

@ -12,7 +12,7 @@ articles:
datasets: datasets.html datasets: datasets.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
welcome_to_AMR: welcome_to_AMR.html welcome_to_AMR: welcome_to_AMR.html
last_built: 2021-05-13T19:35Z last_built: 2021-05-13T20:43Z
urls: urls:
reference: https://msberends.github.io/AMR//reference reference: https://msberends.github.io/AMR//reference
article: https://msberends.github.io/AMR//articles article: https://msberends.github.io/AMR//articles

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9027</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9028</span>
</span> </span>
</div> </div>

View File

@ -51,15 +51,17 @@ test_that("looking up ab columns works", {
expect_warning(generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE)) expect_warning(generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE))
expect_warning(get_column_abx(example_isolates, hard_dependencies = "FUS")) expect_warning(get_column_abx(example_isolates, hard_dependencies = "FUS"))
expect_message(get_column_abx(example_isolates, soft_dependencies = "FUS")) expect_message(get_column_abx(example_isolates, soft_dependencies = "FUS"))
expect_warning(get_column_abx(dplyr::rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = TRUE)) if (suppressWarnings(require("dplyr"))) {
expect_warning(get_column_abx(dplyr::rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = FALSE)) expect_warning(get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = TRUE))
expect_warning(get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = FALSE))
}
}) })
test_that("looking up ab columns works", { test_that("looking up ab columns works", {
skip_on_cran() skip_on_cran()
# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this: # we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this:
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_true(is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id))) expect_true(is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
} }

View File

@ -28,19 +28,20 @@ context("ab_class_selectors.R")
test_that("Antibiotic class selectors work", { test_that("Antibiotic class selectors work", {
skip_on_cran() skip_on_cran()
expect_lt(example_isolates %>% dplyr::select(aminoglycosides()) %>% ncol(), ncol(example_isolates)) if (suppressWarnings(require("dplyr"))) {
expect_lt(example_isolates %>% dplyr::select(carbapenems()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(aminoglycosides()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(carbapenems()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins_1st()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins_2nd()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins_1st()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins_3rd()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins_2nd()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins_4th()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins_3rd()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(cephalosporins_5th()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins_4th()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(fluoroquinolones()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(cephalosporins_5th()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(glycopeptides()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(fluoroquinolones()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(macrolides()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(glycopeptides()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(oxazolidinones()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(macrolides()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(penicillins()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(oxazolidinones()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(tetracyclines()) %>% ncol(), ncol(example_isolates)) expect_lt(example_isolates %>% select(penicillins()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% select(tetracyclines()) %>% ncol(), ncol(example_isolates))
}
}) })

View File

@ -58,7 +58,7 @@ test_that("counts work", {
expect_error(count_df(c("A", "B", "C"))) expect_error(count_df(c("A", "B", "C")))
expect_error(count_df(example_isolates[, "date"])) expect_error(count_df(example_isolates[, "date"]))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
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)

View File

@ -47,14 +47,14 @@ test_that("disk works", {
expect_silent(plot(as.disk(c(10, 20, 40)))) 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 = "esco", ab = "cipr")) expect_silent(plot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr"))
if (require("ggplot2")) { if (suppressWarnings(require("ggplot2"))) {
expect_s3_class(ggplot(as.disk(c(10, 20, 40))), "gg") expect_s3_class(ggplot(as.disk(c(10, 20, 40))), "gg")
expect_s3_class(ggplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg") expect_s3_class(ggplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg")
expect_s3_class(ggplot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr"), "gg") expect_s3_class(ggplot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr"), "gg")
} }
expect_output(print(as.disk(12))) expect_output(print(as.disk(12)))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_output(print(tibble(d = as.disk(12)))) expect_output(print(tibble(d = as.disk(12))))
} }

View File

@ -41,7 +41,7 @@ test_that("episodes work", {
expect_equal(get_episode(test_df$date, 365), expect_equal(get_episode(test_df$date, 365),
c(1, 1, 2, 2, 2, 3, 3, 4, 1, 2, 2, 2, 3)) c(1, 1, 2, 2, 2, 3, 3, 4, 1, 2, 2, 2, 3))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_identical(test_df %>% group_by(patient_id) %>% mutate(f = is_new_episode(date, 365)) %>% pull(f), 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)) c(TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE))

View File

@ -77,7 +77,7 @@ test_that("EUCAST rules work", {
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 (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_equal(suppressWarnings( expect_equal(suppressWarnings(
example_isolates %>% example_isolates %>%
filter(mo_family(mo) == "Enterobacteriaceae") %>% filter(mo_family(mo) == "Enterobacteriaceae") %>%
@ -115,7 +115,7 @@ test_that("EUCAST rules work", {
"S") "S")
# also test norf # also test norf
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_output(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE))) expect_output(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
} }

View File

@ -28,7 +28,7 @@ context("filter_ab_class.R")
test_that("ATC-group filtering works", { test_that("ATC-group filtering works", {
skip_on_cran() skip_on_cran()
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_gt(example_isolates %>% filter_ab_class("carbapenem") %>% nrow(), 0) expect_gt(example_isolates %>% filter_ab_class("carbapenem") %>% nrow(), 0)
expect_gt(example_isolates %>% filter_aminoglycosides() %>% ncol(), 0) expect_gt(example_isolates %>% filter_aminoglycosides() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_carbapenems() %>% ncol(), 0) expect_gt(example_isolates %>% filter_carbapenems() %>% ncol(), 0)

View File

@ -121,28 +121,34 @@ test_that("first isolates work", {
col_date = "non-existing col", col_date = "non-existing col",
col_mo = "mo")) col_mo = "mo"))
require("dplyr") if (suppressWarnings(require("dplyr"))) {
# 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(example_isolates %>%
expect_identical(example_isolates %>% mutate(mo = as.character(mo)) %>%
mutate(mo = as.character(mo)) %>% first_isolate(col_date = "date",
first_isolate(col_date = "date", col_mo = "mo",
col_mo = "mo", col_patient_id = "patient_id",
col_patient_id = "patient_id", info = FALSE),
info = FALSE), example_isolates %>%
example_isolates %>% first_isolate(col_date = "date",
first_isolate(col_date = "date", col_mo = "mo",
col_mo = "mo", col_patient_id = "patient_id",
col_patient_id = "patient_id", info = FALSE))
info = FALSE))
# support for WHONET
# support for WHONET expect_message(example_isolates %>%
expect_message(example_isolates %>% select(-patient_id) %>%
select(-patient_id) %>% mutate(`First name` = "test",
mutate(`First name` = "test", `Last name` = "test",
`Last name` = "test", Sex = "Female") %>%
Sex = "Female") %>% first_isolate(info = TRUE))
first_isolate(info = TRUE))
# groups
x <- example_isolates %>% group_by(ward_icu) %>% mutate(first = first_isolate())
y <- example_isolates %>% group_by(ward_icu) %>% mutate(first = first_isolate(.))
expect_identical(x, y)
}
# missing dates should be no problem # missing dates should be no problem
df <- example_isolates df <- example_isolates
@ -185,10 +191,4 @@ test_that("first isolates work", {
# only one isolate, so return fast # only one isolate, so return fast
expect_true(first_isolate(data.frame(mo = "Escherichia coli", date = Sys.Date(), patient = "patient"), info = TRUE)) expect_true(first_isolate(data.frame(mo = "Escherichia coli", date = Sys.Date(), patient = "patient"), info = TRUE))
# groups
x <- example_isolates %>% group_by(ward_icu) %>% mutate(first = first_isolate())
y <- example_isolates %>% group_by(ward_icu) %>% mutate(first = first_isolate(.))
expect_identical(x, y)
}) })

View File

@ -32,7 +32,7 @@ test_that("ggplot_rsi works", {
skip_if_not_installed("ggplot2") skip_if_not_installed("ggplot2")
skip_if_not_installed("dplyr") skip_if_not_installed("dplyr")
if (require("dplyr") & require("ggplot2")) { if (suppressWarnings(require("dplyr")) & suppressWarnings(require("ggplot2"))) {
pdf(NULL) # prevent Rplots.pdf being created pdf(NULL) # prevent Rplots.pdf being created

View File

@ -244,7 +244,7 @@ test_that("mdro works", {
info = FALSE)) info = FALSE))
# print groups # print groups
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), info = TRUE)) expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), info = TRUE))
expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE)) expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE))
} }

View File

@ -53,7 +53,7 @@ test_that("mic works", {
expect_silent(plot(as.mic(c(1, 2, 4, 8)))) 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 = "esco", ab = "cipr")) expect_silent(plot(as.mic(c(1, 2, 4, 8)), mo = "esco", ab = "cipr"))
if (require("ggplot2")) { if (suppressWarnings(require("ggplot2"))) {
expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8))), "gg") expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8))), "gg")
expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg") expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg")
expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8, 32)), mo = "esco", ab = "cipr"), "gg") expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8, 32)), mo = "esco", ab = "cipr"), "gg")
@ -62,7 +62,7 @@ test_that("mic works", {
expect_s3_class(summary(as.mic(c(2, 8))), c("summaryDefault", "table")) expect_s3_class(summary(as.mic(c(2, 8))), c("summaryDefault", "table"))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_output(print(tibble(m = as.mic(2:4)))) expect_output(print(tibble(m = as.mic(2:4))))
} }
}) })

View File

@ -150,7 +150,7 @@ test_that("as.mo works", {
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 (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
# select with one column # select with one column
expect_identical( expect_identical(
example_isolates[1:10, ] %>% example_isolates[1:10, ] %>%
@ -282,8 +282,10 @@ test_that("as.mo works", {
expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))), expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))),
c("F_YEAST", "F_FUNGUS")) c("F_YEAST", "F_FUNGUS"))
# print tibble if (suppressWarnings(require("dplyr"))) {
expect_output(print(tibble(mo = as.mo("B_ESCHR_COLI")))) # print tibble
expect_output(print(tibble(mo = as.mo("B_ESCHR_COLI"))))
}
# assigning and subsetting # assigning and subsetting
x <- example_isolates$mo x <- example_isolates$mo
@ -299,7 +301,7 @@ test_that("as.mo works", {
c("B_ESCHR_COLI", NA)) c("B_ESCHR_COLI", NA))
# frequency tables # frequency tables
if (require("cleaner")) { if (suppressWarnings(require("cleaner"))) {
expect_s3_class(cleaner::freq(example_isolates$mo), "freq") expect_s3_class(cleaner::freq(example_isolates$mo), "freq")
} }

View File

@ -131,7 +131,7 @@ test_that("mo_property works", {
expect_equal(mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")), expect_equal(mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
"Escherichia coli") "Escherichia coli")
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(), expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
730) 730)
expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(), expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(),

View File

@ -49,10 +49,12 @@ test_that("PCA works", {
expect_s3_class(pca_model, "pca") expect_s3_class(pca_model, "pca")
pdf(NULL) # prevent Rplots.pdf being created pdf(NULL) # prevent Rplots.pdf being created
ggplot_pca(pca_model, ellipse = TRUE) if (suppressWarnings(require("ggplot2"))) {
ggplot_pca(pca_model, arrows_textangled = FALSE) ggplot_pca(pca_model, ellipse = TRUE)
ggplot_pca(pca_model, arrows_textangled = FALSE)
}
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
resistance_data <- example_isolates %>% resistance_data <- example_isolates %>%
group_by(order = mo_order(mo), group_by(order = mo_order(mo),
genus = mo_genus(mo)) %>% genus = mo_genus(mo)) %>%
@ -60,7 +62,9 @@ test_that("PCA works", {
pca_result <- resistance_data %>% pca_result <- resistance_data %>%
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT") pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT")
expect_s3_class(pca_result, "prcomp") expect_s3_class(pca_result, "prcomp")
ggplot_pca(pca_result, ellipse = TRUE) if (suppressWarnings(require("ggplot2"))) {
ggplot_pca(pca_result, ellipse = FALSE, arrows_textangled = FALSE, scale = FALSE) ggplot_pca(pca_result, ellipse = TRUE)
ggplot_pca(pca_result, ellipse = FALSE, arrows_textangled = FALSE, scale = FALSE)
}
} }
}) })

View File

@ -52,7 +52,7 @@ test_that("proportions works", {
0.9382647, 0.9382647,
tolerance = 0.0001) tolerance = 0.0001)
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
# percentages # percentages
expect_equal(example_isolates %>% expect_equal(example_isolates %>%
group_by(hospital_id) %>% group_by(hospital_id) %>%

View File

@ -28,7 +28,7 @@ context("resistance_predict.R")
test_that("prediction of rsi works", { test_that("prediction of rsi works", {
skip_on_cran() skip_on_cran()
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_output(AMX_R <- example_isolates %>% expect_output(AMX_R <- example_isolates %>%
filter(mo == "B_ESCHR_COLI") %>% filter(mo == "B_ESCHR_COLI") %>%
rsi_predict(col_ab = "AMX", rsi_predict(col_ab = "AMX",

View File

@ -42,7 +42,7 @@ test_that("rsi works", {
pdf(NULL) # prevent Rplots.pdf being created pdf(NULL) # prevent Rplots.pdf being created
expect_silent(barplot(as.rsi(c("S", "I", "R")))) expect_silent(barplot(as.rsi(c("S", "I", "R"))))
expect_silent(plot(as.rsi(c("S", "I", "R")))) expect_silent(plot(as.rsi(c("S", "I", "R"))))
if (require("ggplot2")) expect_s3_class(ggplot(as.rsi(c("S", "I", "R"))), "gg") if (suppressWarnings(require("ggplot2"))) expect_s3_class(ggplot(as.rsi(c("S", "I", "R"))), "gg")
expect_output(print(as.rsi(c("S", "I", "R")))) expect_output(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"))
@ -64,7 +64,7 @@ test_that("rsi works", {
expect_error(get_guideline("this one does not exist")) expect_error(get_guideline("this one does not exist"))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
# 40 rsi columns # 40 rsi columns
expect_equal(example_isolates %>% expect_equal(example_isolates %>%
mutate_at(vars(PEN:RIF), as.character) %>% mutate_at(vars(PEN:RIF), as.character) %>%
@ -77,10 +77,10 @@ test_that("rsi works", {
expect_output(print(tibble(ab = as.rsi("S")))) expect_output(print(tibble(ab = as.rsi("S"))))
} }
if (require("skimr")) { if (suppressWarnings(require("skimr"))) {
expect_s3_class(skim(example_isolates), expect_s3_class(skim(example_isolates),
"data.frame") "data.frame")
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
expect_s3_class(example_isolates %>% expect_s3_class(example_isolates %>%
mutate(m = as.mic(2), mutate(m = as.mic(2),
d = as.disk(20)) %>% d = as.disk(20)) %>%
@ -116,7 +116,7 @@ test_that("mic2rsi works", {
expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"), expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"),
as.rsi("R")) as.rsi("R"))
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
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) %>%
@ -149,7 +149,7 @@ test_that("disk2rsi works", {
guideline = "CLSI")), guideline = "CLSI")),
"R") "R")
if (require("dplyr")) { if (suppressWarnings(require("dplyr"))) {
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) %>%
@ -159,7 +159,7 @@ test_that("disk2rsi works", {
} }
# frequency tables # frequency tables
if (require("cleaner")) { if (suppressWarnings(require("cleaner"))) {
expect_s3_class(cleaner::freq(example_isolates$AMX), "freq") expect_s3_class(cleaner::freq(example_isolates$AMX), "freq")
} }
}) })

View File

@ -109,7 +109,9 @@ test_that("imports work", {
fn <- names(import_functions)[i] fn <- names(import_functions)[i]
pkg <- unname(import_functions[i]) pkg <- unname(import_functions[i])
# function should exist in foreign pkg namespace # function should exist in foreign pkg namespace
expect(!is.null(import_fn(name = fn, pkg = pkg, error_on_fail = FALSE)), if (pkg %in% rownames(installed.packages())) {
failure_message = paste0("Function ", pkg, "::", fn, "() does not exist anymore")) expect(!is.null(import_fn(name = fn, pkg = pkg, error_on_fail = FALSE)),
failure_message = paste0("Function ", pkg, "::", fn, "() does not exist anymore"))
}
} }
}) })