mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 20:46:11 +01:00
(v1.6.0.9041) filter_ab_class() fix
This commit is contained in:
parent
00496e45b7
commit
916df6e90c
5
.github/workflows/check.yaml
vendored
5
.github/workflows/check.yaml
vendored
@ -52,7 +52,7 @@ jobs:
|
||||
config:
|
||||
- {os: macOS-latest, r: 'devel', allowfail: true}
|
||||
- {os: macOS-latest, r: 'release', allowfail: false}
|
||||
- {os: macOS-latest, r: 'oldrel', allowfail: false}
|
||||
- {os: macOS-latest, r: 'oldrel', allowfail: true}
|
||||
|
||||
- {os: windows-latest, r: 'devel', allowfail: false}
|
||||
- {os: windows-latest, r: 'release', allowfail: false}
|
||||
@ -106,8 +106,7 @@ jobs:
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ env.R_LIBS_USER }}
|
||||
key: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-3
|
||||
restore-keys: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-3
|
||||
key: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-v4
|
||||
|
||||
- name: Update AMR package dependencies
|
||||
run: |
|
||||
|
@ -1,5 +1,5 @@
|
||||
Package: AMR
|
||||
Version: 1.6.0.9040
|
||||
Version: 1.6.0.9041
|
||||
Date: 2021-05-16
|
||||
Title: Antimicrobial Resistance Data Analysis
|
||||
Authors@R: c(
|
||||
|
5
NEWS.md
5
NEWS.md
@ -1,4 +1,4 @@
|
||||
# `AMR` 1.6.0.9040
|
||||
# `AMR` 1.6.0.9041
|
||||
## <small>Last updated: 16 May 2021</small>
|
||||
|
||||
### New
|
||||
@ -6,7 +6,7 @@
|
||||
* Function `italicise_taxonomy()` to make taxonomic names within a string italic, with support for markdown and ANSI
|
||||
* Support for all four methods to determine first isolates as summarised by Hindler *et al.* (doi: [10.1086/511864](https://doi.org/10.1086/511864)): isolate-based, patient-based, episode-based and phenotype-based. The last method is now the default.
|
||||
* The `first_isolate()` function gained the argument `method` that has to be "phenotype-based", "episode-based", "patient-based", or "isolate-based". The old behaviour is equal to "episode-based". The new default is "phenotype-based" if antimicrobial test results are available, and "episode-based" otherwise. This new default will yield slightly more isolates for selection (which is a good thing).
|
||||
* Since fungal isolates can also be selected, the functions `key_antibiotics()` and `key_antibiotics_equal()` are now deprecated in favour of the `key_antimicrobials()` and `antimicrobial_equal()` functions. Also, the new `all_antimicrobials()` function works like the old `key_antibiotics()` function, but includes any column with antimicrobial test results. Using `key_antimicrobials()` still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new `antifungal` argument to set antifungal agents (antimycotics).
|
||||
* Since fungal isolates can also be selected, the functions `key_antibiotics()` and `key_antibiotics_equal()` are now deprecated in favour of the `key_antimicrobials()` and `antimicrobials_equal()` functions. Also, the new `all_antimicrobials()` function works like the old `key_antibiotics()` function, but includes any column with antimicrobial test results. Using `key_antimicrobials()` still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new `antifungal` argument to set antifungal agents (antimycotics).
|
||||
* Using `type == "points"` in the `first_isolate()` function for phenotype-based selection will now consider all antimicrobial drugs in the data set, using the new `all_antimicrobials()`
|
||||
* The `first_isolate()` function can now take a vector of values for `col_keyantibiotics` and can have an episode length of `Inf`
|
||||
* Since the phenotype-based method is the new default, `filter_first_isolate()` renders the `filter_first_weighted_isolate()` function redundant. For this reason, `filter_first_weighted_isolate()` is now deprecated.
|
||||
@ -41,6 +41,7 @@
|
||||
* Updated `skimr::skim()` usage for MIC values to also include 25th and 75th percentiles
|
||||
* Fix for plotting missing MIC/disk diffusion values
|
||||
* Updated join functions to always use `dplyr` join functions if the `dplyr` package is installed - now also preserving grouped variables
|
||||
* Fix for filtering on antibiotic classes (such as `filter_cephalosporins()`)
|
||||
|
||||
### Other
|
||||
* All unit tests are now processed by the `tinytest` package, instead of the `testthat` package. The `testthat` package unfortunately requires tons of dependencies that are also heavy and only usable for recent R versions, defeating the purpose to test our package under less recent R versions. On the contrary, the `tinytest` package is very lightweight and dependency-free.
|
||||
|
@ -125,11 +125,11 @@ filter_ab_class <- function(x,
|
||||
group %like% ab_class |
|
||||
atc_group1 %like% ab_class |
|
||||
atc_group2 %like% ab_class)
|
||||
ab_group <- find_ab_group(ab_class)
|
||||
if (ab_group == "") {
|
||||
if (nrow(ab_reference) == 0) {
|
||||
message_("Unknown antimicrobial class '", ab_class.bak, "', data left unchanged.")
|
||||
return(x.bak)
|
||||
}
|
||||
ab_group <- find_ab_group(ab_class.bak)
|
||||
# get the columns with a group names in the chosen ab class
|
||||
agents <- ab_in_data[names(ab_in_data) %in% ab_reference$ab]
|
||||
if (length(agents) == 0) {
|
||||
|
@ -435,7 +435,7 @@ first_isolate <- function(x = NULL,
|
||||
if (length(c(row.start:row.end)) == pm_n_distinct(x[c(row.start:row.end), col_mo, drop = TRUE])) {
|
||||
if (info == TRUE) {
|
||||
message_("=> Found ", font_bold(paste(length(c(row.start:row.end)), "first isolates")),
|
||||
", as all isolates were different microorganisms",
|
||||
", as all isolates were different microbial species",
|
||||
add_fn = font_black,
|
||||
as_note = FALSE)
|
||||
}
|
||||
|
2
R/mdro.R
2
R/mdro.R
@ -306,7 +306,7 @@ mdro <- function(x = NULL,
|
||||
}
|
||||
if (is.null(col_mo) & guideline$code == "tb") {
|
||||
message_("No column found as input for `col_mo`, ",
|
||||
font_bold(paste0("assuming all records contain", font_italic("Mycobacterium tuberculosis"), ".")))
|
||||
font_bold(paste0("assuming all rows contain ", font_italic("Mycobacterium tuberculosis"), ".")))
|
||||
x$mo <- as.mo("Mycobacterium tuberculosis") # consider overkill at all times: MO_lookup[which(MO_lookup$fullname == "Mycobacterium tuberculosis"), "mo", drop = TRUE]
|
||||
col_mo <- "mo"
|
||||
}
|
||||
|
Binary file not shown.
@ -26,7 +26,7 @@
|
||||
pkg_suggests <- AMR:::trimws(unlist(strsplit(packageDescription("AMR")$Suggests, ",(\n)?")))
|
||||
|
||||
to_install <- pkg_suggests[!pkg_suggests %in% rownames(utils::installed.packages())]
|
||||
to_update <- as.data.frame(old.packages(), stringsAsFactors = FALSE)
|
||||
to_update <- as.data.frame(utils::old.packages(repos = "https://cran.rstudio.com/"), stringsAsFactors = FALSE)
|
||||
|
||||
for (i in seq_len(length(to_install))) {
|
||||
cat("Installing package", to_install[i], "\n")
|
||||
@ -37,7 +37,7 @@ for (i in seq_len(length(to_install))) {
|
||||
}
|
||||
|
||||
for (i in seq_len(length(to_update))) {
|
||||
cat("Updating package", to_install[i], "\n")
|
||||
cat("Updating package", to_update[i], "\n")
|
||||
tryCatch(update.packages(to_update[i], repos = "https://cran.rstudio.com/", ask = FALSE),
|
||||
# message = function(m) invisible(),
|
||||
warning = function(w) message(w$message),
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -236,9 +236,9 @@
|
||||
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
|
||||
</div>
|
||||
|
||||
<div id="amr-1609040" class="section level1">
|
||||
<h1 class="page-header" data-toc-text="1.6.0.9040">
|
||||
<a href="#amr-1609040" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9040</h1>
|
||||
<div id="amr-1609041" class="section level1">
|
||||
<h1 class="page-header" data-toc-text="1.6.0.9041">
|
||||
<a href="#amr-1609041" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9041</h1>
|
||||
<div id="last-updated-16-may-2021" class="section level2">
|
||||
<h2 class="hasAnchor">
|
||||
<a href="#last-updated-16-may-2021" class="anchor"></a><small>Last updated: 16 May 2021</small>
|
||||
@ -253,7 +253,7 @@
|
||||
<li>Support for all four methods to determine first isolates as summarised by Hindler <em>et al.</em> (doi: <a href="https://doi.org/10.1086/511864">10.1086/511864</a>): isolate-based, patient-based, episode-based and phenotype-based. The last method is now the default.
|
||||
<ul>
|
||||
<li>The <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function gained the argument <code>method</code> that has to be “phenotype-based”, “episode-based”, “patient-based”, or “isolate-based”. The old behaviour is equal to “episode-based”. The new default is “phenotype-based” if antimicrobial test results are available, and “episode-based” otherwise. This new default will yield slightly more isolates for selection (which is a good thing).</li>
|
||||
<li>Since fungal isolates can also be selected, the functions <code><a href="../reference/AMR-deprecated.html">key_antibiotics()</a></code> and <code><a href="../reference/AMR-deprecated.html">key_antibiotics_equal()</a></code> are now deprecated in favour of the <code><a href="../reference/key_antimicrobials.html">key_antimicrobials()</a></code> and <code>antimicrobial_equal()</code> functions. Also, the new <code><a href="../reference/key_antimicrobials.html">all_antimicrobials()</a></code> function works like the old <code><a href="../reference/AMR-deprecated.html">key_antibiotics()</a></code> function, but includes any column with antimicrobial test results. Using <code><a href="../reference/key_antimicrobials.html">key_antimicrobials()</a></code> still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new <code>antifungal</code> argument to set antifungal agents (antimycotics).</li>
|
||||
<li>Since fungal isolates can also be selected, the functions <code><a href="../reference/AMR-deprecated.html">key_antibiotics()</a></code> and <code><a href="../reference/AMR-deprecated.html">key_antibiotics_equal()</a></code> are now deprecated in favour of the <code><a href="../reference/key_antimicrobials.html">key_antimicrobials()</a></code> and <code><a href="../reference/key_antimicrobials.html">antimicrobials_equal()</a></code> functions. Also, the new <code><a href="../reference/key_antimicrobials.html">all_antimicrobials()</a></code> function works like the old <code><a href="../reference/AMR-deprecated.html">key_antibiotics()</a></code> function, but includes any column with antimicrobial test results. Using <code><a href="../reference/key_antimicrobials.html">key_antimicrobials()</a></code> still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new <code>antifungal</code> argument to set antifungal agents (antimycotics).</li>
|
||||
<li>Using <code>type == "points"</code> in the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function for phenotype-based selection will now consider all antimicrobial drugs in the data set, using the new <code><a href="../reference/key_antimicrobials.html">all_antimicrobials()</a></code>
|
||||
</li>
|
||||
<li>The <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function can now take a vector of values for <code>col_keyantibiotics</code> and can have an episode length of <code>Inf</code>
|
||||
@ -306,6 +306,7 @@
|
||||
<li>Updated <code><a href="https://docs.ropensci.org/skimr/reference/skim.html">skimr::skim()</a></code> usage for MIC values to also include 25th and 75th percentiles</li>
|
||||
<li>Fix for plotting missing MIC/disk diffusion values</li>
|
||||
<li>Updated join functions to always use <code>dplyr</code> join functions if the <code>dplyr</code> package is installed - now also preserving grouped variables</li>
|
||||
<li>Fix for filtering on antibiotic classes (such as <code><a href="../reference/filter_ab_class.html">filter_cephalosporins()</a></code>)</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="other" class="section level3">
|
||||
|
@ -12,7 +12,7 @@ articles:
|
||||
datasets: datasets.html
|
||||
resistance_predict: resistance_predict.html
|
||||
welcome_to_AMR: welcome_to_AMR.html
|
||||
last_built: 2021-05-16T07:24Z
|
||||
last_built: 2021-05-16T08:48Z
|
||||
urls:
|
||||
reference: https://msberends.github.io/AMR//reference
|
||||
article: https://msberends.github.io/AMR//articles
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<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.9040</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9041</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
@ -133,7 +133,7 @@ echo
|
||||
echo "•••••••••••••••••"
|
||||
echo "• Building site •"
|
||||
echo "•••••••••••••••••"
|
||||
Rscript -e "suppressMessages(pkgdown::build_site(lazy = $lazy, examples = FALSE))"
|
||||
Rscript -e "suppressMessages(pkgdown::build_site(lazy = $lazy, examples = FALSE, install = FALSE))"
|
||||
# always rebuild datasets vignette
|
||||
Rscript -e "pkgdown::build_article('datasets', lazy = FALSE, quiet = TRUE)"
|
||||
# add the survey page
|
||||
|
@ -23,33 +23,33 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
expect_equal(percentage(0.25), "25%")
|
||||
expect_equal(percentage(0.5), "50%")
|
||||
expect_equal(percentage(0.500, digits = 1), "50.0%")
|
||||
expect_equal(percentage(0.1234), "12.3%")
|
||||
expect_equal(AMR:::percentage(0.25), "25%")
|
||||
expect_equal(AMR:::percentage(0.5), "50%")
|
||||
expect_equal(AMR:::percentage(0.500, digits = 1), "50.0%")
|
||||
expect_equal(AMR:::percentage(0.1234), "12.3%")
|
||||
# round up 0.5
|
||||
expect_equal(percentage(0.0054), "0.5%")
|
||||
expect_equal(percentage(0.0055), "0.6%")
|
||||
expect_equal(AMR:::percentage(0.0054), "0.5%")
|
||||
expect_equal(AMR:::percentage(0.0055), "0.6%")
|
||||
|
||||
expect_equal(strrep("A", 5), "AAAAA")
|
||||
expect_equal(strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))
|
||||
expect_equal(trimws(" test "), "test")
|
||||
expect_equal(trimws(" test ", "l"), "test ")
|
||||
expect_equal(trimws(" test ", "r"), " test")
|
||||
expect_equal(AMR:::strrep("A", 5), "AAAAA")
|
||||
expect_equal(AMR:::strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))
|
||||
expect_equal(AMR:::trimws(" test "), "test")
|
||||
expect_equal(AMR:::trimws(" test ", "l"), "test ")
|
||||
expect_equal(AMR:::trimws(" test ", "r"), " test")
|
||||
|
||||
expect_warning(generate_warning_abs_missing(c("AMP", "AMX")))
|
||||
expect_warning(generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE))
|
||||
expect_warning(get_column_abx(example_isolates, hard_dependencies = "FUS"))
|
||||
expect_message(get_column_abx(example_isolates, soft_dependencies = "FUS"))
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
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))
|
||||
expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX")))
|
||||
expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE))
|
||||
expect_warning(AMR:::get_column_abx(example_isolates, hard_dependencies = "FUS"))
|
||||
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
|
||||
if (pkg_is_available("dplyr")) {
|
||||
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 implement a test that checks for this:
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
expect_true(is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(example_isolates %>% select(aminoglycosides()) %>% ncol() < ncol(example_isolates))
|
||||
expect_true(example_isolates %>% select(carbapenems()) %>% ncol() < ncol(example_isolates))
|
||||
expect_true(example_isolates %>% select(cephalosporins()) %>% ncol() < ncol(example_isolates))
|
||||
|
@ -25,6 +25,6 @@
|
||||
|
||||
b <- suppressWarnings(bug_drug_combinations(example_isolates))
|
||||
expect_inherits(b, "bug_drug_combinations")
|
||||
expect_stdout(print(b))
|
||||
expect_stdout(suppressMessages(print(b)))
|
||||
expect_true(is.data.frame(format(b)))
|
||||
expect_true(is.data.frame(format(b, combine_IR = TRUE, add_ab_group = FALSE)))
|
||||
|
@ -38,9 +38,9 @@ expect_equal(suppressWarnings(count_S(example_isolates$AMX)) + count_I(example_i
|
||||
|
||||
|
||||
# warning for speed loss
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(count_resistant(as.character(example_isolates$AMC)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(count_resistant(example_isolates$AMC,
|
||||
as.character(example_isolates$GEN)))
|
||||
|
||||
@ -53,7 +53,7 @@ expect_error(count_susceptible("test", as_percent = "test"))
|
||||
expect_error(count_df(c("A", "B", "C")))
|
||||
expect_error(count_df(example_isolates[, "date"]))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
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)
|
||||
|
@ -23,7 +23,7 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
expect_true(check_dataset_integrity()) # in misc.R
|
||||
expect_true(AMR:::check_dataset_integrity()) # in misc.R
|
||||
|
||||
# IDs should always be unique
|
||||
expect_identical(nrow(microorganisms), length(unique(microorganisms$mo)))
|
||||
@ -34,14 +34,14 @@ expect_identical(class(antibiotics$ab), c("ab", "character"))
|
||||
# check cross table reference
|
||||
expect_true(all(microorganisms.codes$mo %in% microorganisms$mo))
|
||||
expect_true(all(example_isolates$mo %in% microorganisms$mo))
|
||||
expect_true(all(microorganisms.translation$mo_new %in% microorganisms$mo))
|
||||
expect_true(all(AMR:::microorganisms.translation$mo_new %in% microorganisms$mo))
|
||||
expect_false(any(AMR:::microorganisms.translation$mo_old %in% microorganisms$mo))
|
||||
expect_true(all(rsi_translation$mo %in% microorganisms$mo))
|
||||
expect_true(all(rsi_translation$ab %in% antibiotics$ab))
|
||||
expect_true(all(intrinsic_resistant$microorganism %in% microorganisms$fullname)) # also important for mo_is_intrinsic_resistant()
|
||||
expect_true(all(intrinsic_resistant$antibiotic %in% antibiotics$name))
|
||||
expect_false(any(is.na(microorganisms.codes$code)))
|
||||
expect_false(any(is.na(microorganisms.codes$mo)))
|
||||
expect_false(any(microorganisms.translation$mo_old %in% microorganisms$mo))
|
||||
expect_true(all(dosage$ab %in% antibiotics$ab))
|
||||
expect_true(all(dosage$name %in% antibiotics$name))
|
||||
|
||||
@ -52,7 +52,7 @@ expect_identical(as.ab(antibiotics$name), antibiotics$ab)
|
||||
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item"]
|
||||
for (i in seq_len(length(datasets))) {
|
||||
dataset <- get(datasets[i], envir = asNamespace("AMR"))
|
||||
expect_identical(dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i])
|
||||
expect_identical(AMR:::dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i])
|
||||
}
|
||||
|
||||
df <- AMR:::MO_lookup
|
||||
@ -76,7 +76,7 @@ expect_stdout(print(catalogue_of_life_version()))
|
||||
uncategorised <- subset(microorganisms,
|
||||
genus == "Staphylococcus" &
|
||||
!species %in% c("", "aureus") &
|
||||
!mo %in% c(MO_CONS, MO_COPS))
|
||||
!mo %in% c(AMR:::MO_CONS, AMR:::MO_COPS))
|
||||
expect_true(NROW(uncategorised) == 0,
|
||||
info = ifelse(NROW(uncategorised) == 0,
|
||||
"All staphylococcal species categorised as CoNS/CoPS.",
|
||||
|
@ -43,13 +43,13 @@ expect_silent(barplot(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)), mo = "esco", ab = "cipr"))
|
||||
if (suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot(as.disk(c(10, 20, 40))), "gg")
|
||||
expect_inherits(ggplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg")
|
||||
expect_inherits(ggplot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr"), "gg")
|
||||
}
|
||||
expect_stdout(print(as.disk(12)))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_stdout(print(tibble(d = as.disk(12))))
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ test_df <- rbind(
|
||||
expect_equal(get_episode(test_df$date, 365),
|
||||
c(1, 1, 2, 2, 2, 3, 3, 4, 1, 2, 2, 2, 3))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
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))
|
||||
|
||||
|
@ -24,15 +24,15 @@
|
||||
# ==================================================================== #
|
||||
|
||||
# thoroughly check input table
|
||||
expect_equal(colnames(eucast_rules_file),
|
||||
expect_equal(colnames(AMR:::eucast_rules_file),
|
||||
c("if_mo_property", "like.is.one_of", "this_value",
|
||||
"and_these_antibiotics", "have_these_values",
|
||||
"then_change_these_antibiotics", "to_value",
|
||||
"reference.rule", "reference.rule_group",
|
||||
"reference.version",
|
||||
"note"))
|
||||
MOs_mentioned <- unique(eucast_rules_file$this_value)
|
||||
MOs_mentioned <- sort(trimws(unlist(strsplit(MOs_mentioned[!is_valid_regex(MOs_mentioned)], ",", fixed = TRUE))))
|
||||
MOs_mentioned <- unique(AMR:::eucast_rules_file$this_value)
|
||||
MOs_mentioned <- sort(trimws(unlist(strsplit(MOs_mentioned[!AMR:::is_valid_regex(MOs_mentioned)], ",", fixed = TRUE))))
|
||||
MOs_test <- suppressWarnings(suppressMessages(mo_name(MOs_mentioned)))
|
||||
expect_true(length(MOs_mentioned[MOs_test != MOs_mentioned]) == 0)
|
||||
|
||||
@ -71,7 +71,7 @@ b <- data.frame(mo = c("Staphylococcus aureus",
|
||||
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
||||
|
||||
# piperacillin must be R in Enterobacteriaceae when tica is R
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_equal(suppressWarnings(
|
||||
example_isolates %>%
|
||||
filter(mo_family(mo) == "Enterobacteriaceae") %>%
|
||||
@ -109,7 +109,7 @@ expect_equal(
|
||||
"S")
|
||||
|
||||
# also test norf
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_stdout(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
|
||||
}
|
||||
|
||||
|
@ -23,22 +23,22 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
expect_true(example_isolates %>% filter_ab_class("carbapenem") %>% nrow() > 0)
|
||||
expect_true(example_isolates %>% filter_aminoglycosides() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_carbapenems() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_1st_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_2nd_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_3rd_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_4th_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_5th_cephalosporins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_fluoroquinolones() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_glycopeptides() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_macrolides() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_oxazolidinones() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_penicillins() %>% ncol() > 0)
|
||||
expect_true(example_isolates %>% filter_tetracyclines() %>% ncol() > 0)
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(example_isolates %>% filter_ab_class("carbapenem") %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_aminoglycosides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_carbapenems() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_1st_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_2nd_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_3rd_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_4th_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_5th_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_fluoroquinolones() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_glycopeptides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_macrolides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_oxazolidinones() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_penicillins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_tetracyclines() %>% nrow() < nrow(example_isolates))
|
||||
|
||||
expect_true(example_isolates %>% filter_carbapenems("R", "all") %>% nrow() > 0)
|
||||
|
||||
|
@ -110,7 +110,7 @@ expect_error(first_isolate(example_isolates,
|
||||
col_date = "non-existing col",
|
||||
col_mo = "mo"))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
# if mo is not an mo class, result should be the same
|
||||
expect_identical(example_isolates %>%
|
||||
mutate(mo = as.character(mo)) %>%
|
||||
@ -174,9 +174,7 @@ expect_identical(filter_first_isolate(example_isolates),
|
||||
|
||||
|
||||
# notice that all mo's are distinct, so all are TRUE
|
||||
expect_true(all(example_isolates %pm>%
|
||||
pm_distinct(mo, .keep_all = TRUE) %pm>%
|
||||
first_isolate(info = TRUE) == TRUE))
|
||||
expect_true(all(first_isolate(AMR:::pm_distinct(example_isolates, mo, .keep_all = TRUE), info = TRUE) == TRUE))
|
||||
|
||||
# only one isolate, so return fast
|
||||
expect_true(first_isolate(data.frame(mo = "Escherichia coli", date = Sys.Date(), patient = "patient"), info = TRUE))
|
||||
|
@ -23,7 +23,7 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (suppressWarnings(require("dplyr")) & suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("dplyr") & pkg_is_available("ggplot2")) {
|
||||
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
|
||||
|
@ -27,7 +27,7 @@ expect_identical(italicise_taxonomy("test for E. coli"),
|
||||
"test for *E. coli*")
|
||||
expect_identical(italicise_taxonomy("test for E. coli"),
|
||||
italicize_taxonomy("test for E. coli"))
|
||||
if (has_colour()) {
|
||||
if (AMR:::has_colour()) {
|
||||
expect_identical(italicise_taxonomy("test for E. coli", type = "ansi"),
|
||||
"test for \033[3mE. coli\033[23m")
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ expect_warning(mdro(example_isolates,
|
||||
info = FALSE))
|
||||
|
||||
# print groups
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
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))
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ expect_silent(barplot(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)), mo = "esco", ab = "cipr"))
|
||||
if (suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("ggplot2")) {
|
||||
expect_inherits(ggplot(as.mic(c(1, 2, 4, 8))), "gg")
|
||||
expect_inherits(ggplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg")
|
||||
expect_inherits(ggplot(as.mic(c(1, 2, 4, 8, 32)), mo = "esco", ab = "cipr"), "gg")
|
||||
@ -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"))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_stdout(print(tibble(m = as.mic(2:4))))
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,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 = TRUE)), "B_STRPT_GRPK") # group K
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
# select with one column
|
||||
expect_identical(
|
||||
example_isolates[1:10, ] %>%
|
||||
@ -273,7 +273,7 @@ expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))),
|
||||
expect_equal(suppressWarnings(as.character(as.mo(c("yeasts", "fungi")))),
|
||||
c("F_YEAST", "F_FUNGUS"))
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
# print tibble
|
||||
expect_stdout(print(tibble(mo = as.mo("B_ESCHR_COLI"))))
|
||||
}
|
||||
@ -292,6 +292,6 @@ expect_equal(as.character(as.mo(c("E. coli", "E. coli ignorethis"), ignore_patte
|
||||
c("B_ESCHR_COLI", NA))
|
||||
|
||||
# frequency tables
|
||||
if (suppressWarnings(require("cleaner"))) {
|
||||
if (pkg_is_available("cleaner")) {
|
||||
expect_inherits(cleaner::freq(example_isolates$mo), "freq")
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ expect_equal(mo_is_intrinsic_resistant(c("Escherichia coli", "Staphylococcus aur
|
||||
# with reference data
|
||||
expect_equal(mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
|
||||
"Escherichia coli")
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
|
||||
730)
|
||||
expect_equal(example_isolates %>% filter(mo_is_gram_positive()) %>% nrow(),
|
||||
|
@ -42,12 +42,12 @@ expect_inherits(pca_model, "pca")
|
||||
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
|
||||
if (suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("ggplot2")) {
|
||||
ggplot_pca(pca_model, ellipse = TRUE)
|
||||
ggplot_pca(pca_model, arrows_textangled = FALSE)
|
||||
}
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
resistance_data <- example_isolates %>%
|
||||
group_by(order = mo_order(mo),
|
||||
genus = mo_genus(mo)) %>%
|
||||
@ -56,7 +56,7 @@ if (suppressWarnings(require("dplyr"))) {
|
||||
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT")
|
||||
expect_inherits(pca_result, "prcomp")
|
||||
|
||||
if (suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("ggplot2")) {
|
||||
ggplot_pca(pca_result, ellipse = TRUE)
|
||||
ggplot_pca(pca_result, ellipse = FALSE, arrows_textangled = FALSE, scale = FALSE)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ expect_equal(example_isolates %>% proportion_SI(AMC, GEN, only_all_tested = TRUE
|
||||
0.9382647,
|
||||
tolerance = 0.0001)
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
# percentages
|
||||
expect_equal(example_isolates %>%
|
||||
group_by(hospital_id) %>%
|
||||
@ -88,14 +88,14 @@ if (suppressWarnings(require("dplyr"))) {
|
||||
example_isolates$AMX %>% proportion_R())
|
||||
)
|
||||
}
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_R(as.character(example_isolates$AMC)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(as.character(example_isolates$AMC)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(n_rsi(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
|
||||
@ -120,11 +120,11 @@ expect_identical(suppressWarnings(proportion_S(example_isolates$AMX, minimum = n
|
||||
NA_real_)
|
||||
|
||||
# warning for speed loss
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_R(as.character(example_isolates$GEN)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_I(as.character(example_isolates$GEN)))
|
||||
reset_all_thrown_messages()
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
|
||||
expect_error(proportion_df(c("A", "B", "C")))
|
||||
expect_error(proportion_df(example_isolates[, "date"]))
|
||||
|
@ -23,7 +23,7 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_stdout(AMX_R <- example_isolates %>%
|
||||
filter(mo == "B_ESCHR_COLI") %>%
|
||||
rsi_predict(col_ab = "AMX",
|
||||
@ -43,7 +43,7 @@ expect_stdout(x <- suppressMessages(resistance_predict(example_isolates,
|
||||
info = TRUE)))
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(plot(x))
|
||||
if (suppressWarnings(require("ggplot2"))) {
|
||||
if (pkg_is_available("ggplot2")) {
|
||||
expect_silent(ggplot_rsi_predict(x))
|
||||
expect_silent(ggplot(x))
|
||||
expect_error(ggplot_rsi_predict(example_isolates))
|
||||
|
@ -34,7 +34,7 @@ expect_inherits(unique(x[1], x[9]), "rsi")
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(barplot(as.rsi(c("S", "I", "R"))))
|
||||
expect_silent(plot(as.rsi(c("S", "I", "R"))))
|
||||
if (suppressWarnings(require("ggplot2"))) expect_inherits(ggplot(as.rsi(c("S", "I", "R"))), "gg")
|
||||
if (pkg_is_available("ggplot2")) expect_inherits(ggplot(as.rsi(c("S", "I", "R"))), "gg")
|
||||
expect_stdout(print(as.rsi(c("S", "I", "R"))))
|
||||
expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R"))
|
||||
expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA)
|
||||
@ -49,7 +49,7 @@ expect_identical(as.logical(lapply(example_isolates, is.rsi.eligible)),
|
||||
expect_error(as.rsi.mic(as.mic(16)))
|
||||
expect_error(as.rsi.disk(as.disk(16)))
|
||||
expect_error(get_guideline("this one does not exist"))
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
# 40 rsi columns
|
||||
expect_equal(example_isolates %>%
|
||||
mutate_at(vars(PEN:RIF), as.character) %>%
|
||||
@ -61,10 +61,10 @@ if (suppressWarnings(require("dplyr"))) {
|
||||
|
||||
expect_stdout(print(tibble(ab = as.rsi("S"))))
|
||||
}
|
||||
if (suppressWarnings(require("skimr"))) {
|
||||
if (pkg_is_available("skimr")) {
|
||||
expect_inherits(skim(example_isolates),
|
||||
"data.frame")
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_inherits(example_isolates %>%
|
||||
mutate(m = as.mic(2),
|
||||
d = as.disk(20)) %>%
|
||||
@ -94,7 +94,7 @@ expect_equal(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020
|
||||
as.rsi("S"))
|
||||
expect_equal(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020"),
|
||||
as.rsi("R"))
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(suppressWarnings(example_isolates %>%
|
||||
mutate(amox_mic = as.mic(2)) %>%
|
||||
select(mo, amox_mic) %>%
|
||||
@ -121,7 +121,7 @@ expect_equal(as.character(
|
||||
ab = "ERY",
|
||||
guideline = "CLSI")),
|
||||
"R")
|
||||
if (suppressWarnings(require("dplyr"))) {
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(example_isolates %>%
|
||||
mutate(amox_disk = as.disk(15)) %>%
|
||||
select(mo, amox_disk) %>%
|
||||
@ -130,7 +130,7 @@ if (suppressWarnings(require("dplyr"))) {
|
||||
is.rsi())
|
||||
}
|
||||
# frequency tables
|
||||
if (suppressWarnings(require("cleaner"))) {
|
||||
if (pkg_is_available("cleaner")) {
|
||||
expect_inherits(cleaner::freq(example_isolates$AMX), "freq")
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ for (i in seq_len(length(import_functions))) {
|
||||
pkg <- unname(import_functions[i])
|
||||
# function should exist in foreign pkg namespace
|
||||
if (pkg %in% rownames(installed.packages())) {
|
||||
tst <- !is.null(import_fn(name = fn, pkg = pkg, error_on_fail = FALSE))
|
||||
tst <- !is.null(AMR:::import_fn(name = fn, pkg = pkg, error_on_fail = FALSE))
|
||||
expect_true(tst,
|
||||
info = ifelse(tst,
|
||||
"All external function references exist.",
|
||||
|
@ -27,8 +27,18 @@
|
||||
if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) {
|
||||
# env var 'R_LIBS_USER' got overwritten during 'R CMD check' in GitHub Actions, so:
|
||||
.libPaths(c(Sys.getenv("R_LIBS_USER_GH_ACTIONS"), .libPaths()))
|
||||
print(.libPaths())
|
||||
library(tinytest)
|
||||
library(AMR)
|
||||
test_package("AMR")
|
||||
# helper function
|
||||
pkg_is_available <- function(pkg, also_load = TRUE) {
|
||||
if (also_load == TRUE) {
|
||||
out <- suppressWarnings(require(pkg, character.only = TRUE, warn.conflicts = FALSE, quietly = TRUE))
|
||||
} else {
|
||||
out <- requireNamespace(pkg, quietly = TRUE)
|
||||
}
|
||||
isTRUE(out)
|
||||
}
|
||||
|
||||
if (pkg_is_available("tinytest")) {
|
||||
library(AMR)
|
||||
out <- test_package("AMR")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user