1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 18:46:11 +01:00

(v1.7.1.9049) unit tests

This commit is contained in:
dr. M.S. (Matthijs) Berends 2021-10-05 09:58:08 +02:00
parent d1b16ce641
commit 2bcf28281d
28 changed files with 64 additions and 44 deletions

View File

@ -88,6 +88,8 @@ jobs:
- uses: r-lib/actions/setup-r@v1 - uses: r-lib/actions/setup-r@v1
with: with:
r-version: ${{ matrix.config.r }} r-version: ${{ matrix.config.r }}
- uses: r-lib/actions/setup-pandoc@v1
- name: Install Linux dependencies - name: Install Linux dependencies
if: runner.os == 'Linux' if: runner.os == 'Linux'
@ -95,7 +97,7 @@ jobs:
# we don't want to depend on the sysreqs pkg here, as it requires quite a recent R version # we don't want to depend on the sysreqs pkg here, as it requires quite a recent R version
# as of May 2021: https://sysreqs.r-hub.io/pkg/AMR,R,cleaner,curl,dplyr,ggplot2,ggtext,knitr,microbenchmark,pillar,readxl,rmarkdown,rstudioapi,rvest,skimr,tidyr,tinytest,xml2,backports,crayon,rlang,vctrs,evaluate,highr,markdown,stringr,yaml,xfun,cli,ellipsis,fansi,lifecycle,utf8,glue,mime,magrittr,stringi,generics,R6,tibble,tidyselect,pkgconfig,purrr,digest,gtable,isoband,MASS,mgcv,scales,withr,nlme,Matrix,farver,labeling,munsell,RColorBrewer,viridisLite,lattice,colorspace,gridtext,Rcpp,RCurl,png,jpeg,bitops,cellranger,progress,rematch,hms,prettyunits,htmltools,jsonlite,tinytex,base64enc,httr,selectr,openssl,askpass,sys,repr,cpp11 # as of May 2021: https://sysreqs.r-hub.io/pkg/AMR,R,cleaner,curl,dplyr,ggplot2,ggtext,knitr,microbenchmark,pillar,readxl,rmarkdown,rstudioapi,rvest,skimr,tidyr,tinytest,xml2,backports,crayon,rlang,vctrs,evaluate,highr,markdown,stringr,yaml,xfun,cli,ellipsis,fansi,lifecycle,utf8,glue,mime,magrittr,stringi,generics,R6,tibble,tidyselect,pkgconfig,purrr,digest,gtable,isoband,MASS,mgcv,scales,withr,nlme,Matrix,farver,labeling,munsell,RColorBrewer,viridisLite,lattice,colorspace,gridtext,Rcpp,RCurl,png,jpeg,bitops,cellranger,progress,rematch,hms,prettyunits,htmltools,jsonlite,tinytex,base64enc,httr,selectr,openssl,askpass,sys,repr,cpp11
run: | run: |
sudo apt install -y libssl-dev pandoc pandoc-citeproc libxml2-dev libicu-dev libcurl4-openssl-dev libpng-dev sudo apt install -y libssl-dev libxml2-dev libicu-dev libcurl4-openssl-dev libpng-dev
- name: Restore cached R packages - name: Restore cached R packages
# this step will add the step 'Post Restore cached R packages' on a succesful run # this step will add the step 'Post Restore cached R packages' on a succesful run
if: runner.os != 'Windows' if: runner.os != 'Windows'

View File

@ -45,8 +45,10 @@ jobs:
- uses: r-lib/actions/setup-r@v1 - uses: r-lib/actions/setup-r@v1
with: with:
r-version: release r-version: release
- uses: r-lib/actions/setup-pandoc@master - uses: r-lib/actions/setup-pandoc@v1
# with:
# pandoc-version: '2.7.3' # The pandoc version to download (if necessary) and use.
- name: Query dependencies - name: Query dependencies
# this will change once a week, so it will cache dependency updates # this will change once a week, so it will cache dependency updates

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.7.1.9048 Version: 1.7.1.9049
Date: 2021-10-04 Date: 2021-10-05
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)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@ -1,5 +1,5 @@
# `AMR` 1.7.1.9048 # `AMR` 1.7.1.9049
## <small>Last updated: 4 October 2021</small> ## <small>Last updated: 5 October 2021</small>
### Breaking changes ### Breaking changes
* Removed `p_symbol()` and all `filter_*()` functions (except for `filter_first_isolate()`), which were all deprecated in a previous package version * Removed `p_symbol()` and all `filter_*()` functions (except for `filter_first_isolate()`), which were all deprecated in a previous package version

View File

@ -296,12 +296,15 @@ stop_ifnot_installed <- function(package) {
return(invisible()) return(invisible())
} }
pkg_is_available <- function(pkg, also_load = TRUE) { pkg_is_available <- function(pkg, also_load = TRUE, 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 {
out <- requireNamespace(pkg, quietly = TRUE) out <- requireNamespace(pkg, quietly = TRUE)
} }
if (!is.null(min_version)) {
out <- out && packageVersion(pkg) >= min_version
}
isTRUE(out) isTRUE(out)
} }

12
R/mo.R
View File

@ -372,7 +372,7 @@ exec_as.mo <- function(x,
# Laboratory systems: remove (translated) entries like "no growth", etc. # Laboratory systems: remove (translated) entries like "no growth", etc.
x[trimws2(x) %like% translate_AMR("no .*growth", language = language)] <- NA_character_ x[trimws2(x) %like% translate_AMR("no .*growth", language = language)] <- NA_character_
x[trimws2(x) %like% paste0("^(", translate_AMR("no|not", language = language), ") [a-z]+")] <- "UNKNOWN" x[trimws2(x) %like% paste0("^(", translate_AMR("no|not", language = language), ") [a-z]+")] <- "UNKNOWN"
if (initial_search == TRUE) { if (initial_search == TRUE) {
# keep track of time - give some hints to improve speed if it takes a long time # keep track of time - give some hints to improve speed if it takes a long time
start_time <- Sys.time() start_time <- Sys.time()
@ -495,9 +495,13 @@ exec_as.mo <- function(x,
# Fill in fullnames and MO codes directly # Fill in fullnames and MO codes directly
known_names <- tolower(x_backup) %in% MO_lookup$fullname_lower known_names <- tolower(x_backup) %in% MO_lookup$fullname_lower
x[known_names] <- MO_lookup[match(tolower(x_backup)[known_names], MO_lookup$fullname_lower), property, drop = TRUE] x[known_names] <- MO_lookup[match(tolower(x_backup)[known_names], MO_lookup$fullname_lower), property, drop = TRUE]
known_codes <- toupper(x_backup) %in% MO_lookup$mo known_codes_mo <- toupper(x_backup) %in% MO_lookup$mo
x[known_codes] <- MO_lookup[match(toupper(x_backup)[known_codes], MO_lookup$mo), property, drop = TRUE] x[known_codes_mo] <- MO_lookup[match(toupper(x_backup)[known_codes_mo], MO_lookup$mo), property, drop = TRUE]
already_known <- known_names | known_codes known_codes_lis <- toupper(x_backup) %in% microorganisms.codes$code
x[known_codes_lis] <- MO_lookup[match(microorganisms.codes[match(toupper(x_backup)[known_codes_lis],
microorganisms.codes$code), "mo", drop = TRUE],
MO_lookup$mo), property, drop = TRUE]
already_known <- known_names | known_codes_mo | known_codes_lis
# now only continue where the right taxonomic output is not already known # now only continue where the right taxonomic output is not already known
if (any(!already_known)) { if (any(!already_known)) {

View File

@ -25,7 +25,7 @@
codecov: codecov:
require_ci_to_pass: no # allow fail require_ci_to_pass: no # allow fail
branch: master branch: main
comment: no comment: no

Binary file not shown.

View File

@ -44,7 +44,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.7.1.9048</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.7.1.9049</span>
</span> </span>
</div> </div>
@ -190,7 +190,7 @@
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>Data sets for download / own use</h1> <h1 data-toc-skip>Data sets for download / own use</h1>
<h4 data-toc-skip class="date">04 October 2021</h4> <h4 data-toc-skip class="date">05 October 2021</h4>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/master/vignettes/datasets.Rmd" class="external-link"><code>vignettes/datasets.Rmd</code></a></small> <small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/master/vignettes/datasets.Rmd" class="external-link"><code>vignettes/datasets.Rmd</code></a></small>
<div class="hidden name"><code>datasets.Rmd</code></div> <div class="hidden name"><code>datasets.Rmd</code></div>

View File

@ -92,7 +92,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.7.1.9048</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.7.1.9049</span>
</span> </span>
</div> </div>
@ -240,12 +240,12 @@
<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-1719048" class="section level1"> <div id="amr-1719049" class="section level1">
<h1 class="page-header" data-toc-text="1.7.1.9048"> <h1 class="page-header" data-toc-text="1.7.1.9049">
<a href="#amr-1719048" class="anchor" aria-hidden="true"></a><small> Unreleased </small><code>AMR</code> 1.7.1.9048</h1> <a href="#amr-1719049" class="anchor" aria-hidden="true"></a><small> Unreleased </small><code>AMR</code> 1.7.1.9049</h1>
<div id="last-updated-4-october-2021" class="section level2"> <div id="last-updated-5-october-2021" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-4-october-2021" class="anchor" aria-hidden="true"></a><small>Last updated: 4 October 2021</small> <a href="#last-updated-5-october-2021" class="anchor" aria-hidden="true"></a><small>Last updated: 5 October 2021</small>
</h2> </h2>
<div id="breaking-changes" class="section level3"> <div id="breaking-changes" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">

View File

@ -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_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")) { 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 = 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 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 (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))) expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
} }

View File

@ -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): # 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[any(carbapenems()), ]), 962, tolerance = 0.5)
expect_equal(nrow(example_isolates[all(carbapenems()), ]), 756, 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() # filter with multiple antibiotic selectors using c()
expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]), 26, tolerance = 0.5) 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(nrow(example_isolates[any(carbapenems() == "R"), penicillins()]), 55, tolerance = 0.5)
expect_equal(ncol(example_isolates[any(carbapenems() == "R"), penicillins()]), 7, 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)))
}

View File

@ -69,7 +69,7 @@ expect_identical(colnames(set_ab_names(example_isolates[, 20:25], language = "nl
c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine")) c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine"))
expect_identical(colnames(set_ab_names(example_isolates[, 20:25], "atc")), expect_identical(colnames(set_ab_names(example_isolates[, 20:25], "atc")),
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")) 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(), expect_identical(example_isolates %>% set_ab_names(),
example_isolates %>% rename_with(set_ab_names)) example_isolates %>% rename_with(set_ab_names))
} }

View File

@ -28,7 +28,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, combine_IR = TRUE, add_ab_group = FALSE))) 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 %>% expect_true(example_isolates %>%
group_by(hospital_id) %>% group_by(hospital_id) %>%
bug_drug_combinations(FUN = mo_gramstain) %>% bug_drug_combinations(FUN = mo_gramstain) %>%

View File

@ -51,7 +51,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"])) 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), 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

@ -50,6 +50,6 @@ if (AMR:::pkg_is_available("ggplot2")) {
} }
expect_stdout(print(as.disk(12))) 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)))) expect_stdout(print(tibble(d = as.disk(12))))
} }

View File

@ -36,7 +36,7 @@ test_df <- rbind(
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 (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), 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

@ -72,7 +72,7 @@ b <- data.frame(mo = c("Staphylococcus aureus",
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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_equal(suppressWarnings( expect_equal(suppressWarnings(
example_isolates %>% example_isolates %>%
filter(mo_family(mo) == "Enterobacteriaceae") %>% filter(mo_family(mo) == "Enterobacteriaceae") %>%
@ -110,7 +110,7 @@ expect_equal(
"S") "S")
# also test norf # 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))) expect_stdout(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
} }

View File

@ -110,7 +110,7 @@ expect_error(first_isolate(example_isolates,
col_date = "non-existing col", col_date = "non-existing col",
col_mo = "mo")) 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 # 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)) %>%

View File

@ -23,7 +23,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") & 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 pdf(NULL) # prevent Rplots.pdf being created

View File

@ -232,7 +232,7 @@ expect_warning(mdro(example_isolates,
info = FALSE)) info = FALSE))
# print groups # 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), info = TRUE))
expect_stdout(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE)) expect_stdout(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE))
} }

View File

@ -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")) 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)))) expect_stdout(print(tibble(m = as.mic(2:4))))
} }

View File

@ -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 = 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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# select with one column # select with one column
expect_identical( expect_identical(
example_isolates[1:10, ] %>% 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")))), expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))),
c("F_YEAST", "F_FUNGUS")) c("F_YEAST", "F_FUNGUS"))
if (AMR:::pkg_is_available("dplyr")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# print tibble # print tibble
expect_stdout(print(tibble(mo = as.mo("B_ESCHR_COLI")))) expect_stdout(print(tibble(mo = as.mo("B_ESCHR_COLI"))))
} }

View File

@ -119,7 +119,7 @@ expect_equal(mo_is_intrinsic_resistant(c("Escherichia coli", "Staphylococcus aur
# with reference data # with reference data
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 (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(), expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
730, tolerance = 0.5) 730, tolerance = 0.5)
expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(), expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(),

View File

@ -47,7 +47,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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
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)) %>%

View File

@ -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), expect_equal(proportion_S(example_isolates$AMX) + proportion_I(example_isolates$AMX),
proportion_SI(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), expect_equal(example_isolates %>% proportion_SI(AMC),
0.7626397, 0.7626397,
tolerance = 0.0001) tolerance = 0.0001)

View File

@ -23,7 +23,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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_stdout(AMX_R <- example_isolates %>% expect_stdout(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

@ -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.mic(as.mic(16)))
expect_error(as.rsi.disk(as.disk(16))) expect_error(as.rsi.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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
# 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) %>%
@ -66,7 +66,7 @@ if (AMR:::pkg_is_available("dplyr")) {
if (AMR:::pkg_is_available("skimr")) { if (AMR:::pkg_is_available("skimr")) {
expect_inherits(skim(example_isolates), expect_inherits(skim(example_isolates),
"data.frame") "data.frame")
if (AMR:::pkg_is_available("dplyr")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_inherits(example_isolates %>% expect_inherits(example_isolates %>%
mutate(m = as.mic(2), mutate(m = as.mic(2),
d = as.disk(20)) %>% d = as.disk(20)) %>%
@ -96,7 +96,7 @@ expect_equal(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020
as.rsi("S")) as.rsi("S"))
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 (AMR:::pkg_is_available("dplyr")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
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) %>%
@ -123,7 +123,7 @@ expect_equal(as.character(
ab = "ERY", ab = "ERY",
guideline = "CLSI")), guideline = "CLSI")),
"R") "R")
if (AMR:::pkg_is_available("dplyr")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
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) %>%