Browse Source

(v1.6.0.9031) tinytest unit tests

main
parent
commit
d8c91d5876
  1. 46
      .github/workflows/check.yaml
  2. 8
      DESCRIPTION
  3. 9
      NEWS.md
  4. BIN
      data-raw/AMR_latest.tar.gz
  5. 47
      data-raw/_install_deps.R
  6. 2
      docs/404.html
  7. 2
      docs/LICENSE-text.html
  8. 2
      docs/articles/index.html
  9. 2
      docs/authors.html
  10. 2
      docs/index.html
  11. 85
      docs/news/index.html
  12. 2
      docs/pkgdown.yml
  13. 2
      docs/reference/index.html
  14. 2
      docs/survey.html
  15. 23
      inst/tinytest/test-_deprecated.R
  16. 59
      inst/tinytest/test-_misc.R
  17. 75
      inst/tinytest/test-ab.R
  18. 36
      inst/tinytest/test-ab_class_selectors.R
  19. 33
      inst/tinytest/test-ab_from_text.R
  20. 63
      inst/tinytest/test-ab_property.R
  21. 61
      inst/tinytest/test-age.R
  22. 12
      inst/tinytest/test-atc_online.R
  23. 9
      inst/tinytest/test-availability.R
  24. 19
      inst/tinytest/test-bug_drug_combinations.R
  25. 99
      inst/tinytest/test-count.R
  26. 84
      inst/tinytest/test-data.R
  27. 58
      inst/tinytest/test-disk.R
  28. 43
      inst/tinytest/test-episode.R
  29. 158
      inst/tinytest/test-eucast_rules.R
  30. 48
      inst/tinytest/test-filter_ab_class.R
  31. 182
      inst/tinytest/test-first_isolate.R
  32. 54
      inst/tinytest/test-g.test.R
  33. 34
      inst/tinytest/test-get_locale.R
  34. 112
      inst/tinytest/test-ggplot_rsi.R
  35. 29
      inst/tinytest/test-guess_ab_col.R
  36. 33
      inst/tinytest/test-italicise_taxonomy.R
  37. 52
      inst/tinytest/test-join_microorganisms.R
  38. 33
      inst/tinytest/test-key_antimicrobials.R
  39. 42
      inst/tinytest/test-kurtosis.R
  40. 40
      inst/tinytest/test-like.R
  41. 238
      inst/tinytest/test-mdro.R
  42. 136
      inst/tinytest/test-mic.R
  43. 297
      inst/tinytest/test-mo.R
  44. 129
      inst/tinytest/test-mo_property.R
  45. 63
      inst/tinytest/test-pca.R
  46. 130
      inst/tinytest/test-proportion.R
  47. 22
      inst/tinytest/test-random.R
  48. 95
      inst/tinytest/test-resistance_predict.R
  49. 157
      inst/tinytest/test-rsi.R
  50. 20
      inst/tinytest/test-skewness.R
  51. 112
      inst/tinytest/test-zzz.R
  52. 68
      tests/testthat/test-_misc.R
  53. 78
      tests/testthat/test-ab.R
  54. 47
      tests/testthat/test-ab_class_selectors.R
  55. 69
      tests/testthat/test-ab_property.R
  56. 77
      tests/testthat/test-age.R
  57. 106
      tests/testthat/test-count.R
  58. 98
      tests/testthat/test-data.R
  59. 168
      tests/testthat/test-eucast_rules.R
  60. 54
      tests/testthat/test-filter_ab_class.R
  61. 194
      tests/testthat/test-first_isolate.R
  62. 90
      tests/testthat/test-ggplot_rsi.R
  63. 251
      tests/testthat/test-mdro.R
  64. 143
      tests/testthat/test-mic.R
  65. 308
      tests/testthat/test-mo.R
  66. 142
      tests/testthat/test-mo_property.R
  67. 70
      tests/testthat/test-pca.R
  68. 140
      tests/testthat/test-proportion.R
  69. 44
      tests/testthat/test-random.R
  70. 102
      tests/testthat/test-resistance_predict.R
  71. 192
      tests/testthat/test-rsi.R
  72. 117
      tests/testthat/test-zzz.R
  73. 31
      tests/tinytest.R

46
.github/workflows/check.yaml

@ -81,7 +81,7 @@ jobs: @@ -81,7 +81,7 @@ jobs:
- {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.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
@ -93,29 +93,14 @@ jobs: @@ -93,29 +93,14 @@ jobs:
with:
r-version: ${{ matrix.config.r }}
- uses: r-lib/actions/setup-pandoc@master
# - uses: r-lib/actions/setup-pandoc@master
- name: Install remotes package
if: matrix.config.r != '3.0'
run: |
install.packages('remotes')
shell: Rscript {0}
- name: Query dependencies
if: matrix.config.r != '3.0'
run: |
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}
# - name: Query dependencies
# if: matrix.config.r != '3.0'
# run: |
# saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
# shell: Rscript {0}
- name: Cache R packages
if: runner.os != 'Windows' && matrix.config.r != '3.0'
# && matrix.config.r != '3.0' && matrix.config.r != '3.1' && matrix.config.r != '3.2'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-3-
- name: Install Linux dependencies
if: runner.os == 'Linux'
# update the below with sysreqs::sysreqs("DESCRIPTION") and check the "DEB" entries (for Ubuntu).
@ -123,11 +108,18 @@ jobs: @@ -123,11 +108,18 @@ jobs:
run: |
sudo apt install -y libssl-dev pandoc pandoc-citeproc libxml2-dev libicu-dev libcurl4-openssl-dev
- name: Update package dependencies using remotes package
if: matrix.config.r != '3.0'
- name: Update package dependencies
run: |
remotes::install_deps(dependencies = TRUE)
source("data-raw/_install_deps.R")
shell: Rscript {0}
- name: Cache R packages
# if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ matrix.config.os }}-r-${{ matrix.config.r }} # -${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ matrix.config.os }}-r-${{ matrix.config.r }}
- name: Session info
run: |
@ -145,12 +137,13 @@ jobs: @@ -145,12 +137,13 @@ jobs:
_R_CHECK_LENGTH_1_CONDITION_: verbose
_R_CHECK_LENGTH_1_LOGIC2_: verbose
R_LIBS_USER: ${{ env.R_LIBS_USER }}
R_TINYTEST: true
run: |
tar -xf data-raw/AMR_latest.tar.gz
rm -rf AMR/vignettes
R CMD check AMR
shell: bash
- name: Run R CMD check on Linux and macOS
if: runner.os != 'Windows'
env:
@ -160,6 +153,7 @@ jobs: @@ -160,6 +153,7 @@ jobs:
_R_CHECK_LENGTH_1_CONDITION_: verbose
_R_CHECK_LENGTH_1_LOGIC2_: verbose
R_LIBS_USER: ${{ env.R_LIBS_USER }}
R_TINYTEST: true
run: |
tar -xf data-raw/AMR_latest.tar.gz
rm -rf AMR/vignettes

8
DESCRIPTION

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
Package: AMR
Version: 1.6.0.9030
Date: 2021-05-13
Version: 1.6.0.9031
Date: 2021-05-15
Title: Antimicrobial Resistance Data Analysis
Authors@R: c(
person(role = c("aut", "cre"),
@ -55,9 +55,9 @@ Suggests: @@ -55,9 +55,9 @@ Suggests:
rstudioapi,
rvest,
skimr,
testthat,
tidyr,
xml2
tinytest,
xml2,
VignetteBuilder: knitr,rmarkdown
URL: https://msberends.github.io/AMR/, https://github.com/msberends/AMR
BugReports: https://github.com/msberends/AMR/issues

9
NEWS.md

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
# `AMR` 1.6.0.9030
## <small>Last updated: 13 May 2021</small>
# `AMR` 1.6.0.9031
## <small>Last updated: 15 May 2021</small>
### New
* Function `custom_eucast_rules()` that brings support for custom AMR rules in `eucast_rules()`
@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
* Altered the RStudio addin, so it now iterates over `%like%` -> `%unlike%` -> `%like_case%` -> `%unlike_case%` if you keep pressing your keyboard shortcut
* Fixed an installation error on R-3.0
* Added `info` argument to `as.mo()` to turn on/off the progress bar
* Fixed a bug that `col_mo` for some functions (esp. `eucast_rules()` and `mdro()`) could not be column names of the `microorganisms` data set as it would throw an error
* Fixed a bug where `col_mo` in some functions (esp. `eucast_rules()` and `mdro()`) could not be a column name of the `microorganisms` data set as it would throw an error
* Fix for transforming numeric values to RSI (`as.rsi()`) when the `vctrs` package is loaded (i.e., when using tidyverse)
* Colour fix for using `barplot()` on an RSI class
* Added 25 common system codes for bacteria to the `microorganisms.codes` data set
@ -42,6 +42,9 @@ @@ -42,6 +42,9 @@
* 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
### 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.
# `AMR` 1.6.0

BIN
data-raw/AMR_latest.tar.gz

Binary file not shown.

47
data-raw/_install_deps.R

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Data Analysis for R #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2021 Berends MS, Luz CF et al. #
# Developed at the University of Groningen, the Netherlands, in #
# collaboration with non-profit organisations Certe Medical #
# Diagnostics & Advice, and University Medical Center Groningen. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
pkg_suggests <- 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)
for (i in seq_len(length(to_install))) {
cat("Installing package", to_install[i], "\n")
tryCatch(install.packages(to_install[i], repos = "https://cran.rstudio.com/", dependencies = TRUE, quiet = TRUE),
message = function(m) invisible(),
warning = function(w) message(w$message),
error = function(e) message(e$message))
}
for (i in seq_len(length(to_update))) {
cat("Updating package", to_install[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),
error = function(e) message(e$message))
}
# saveRDS(to_update, ".github/depends.Rds", version = 2)

2
docs/404.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

2
docs/LICENSE-text.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

2
docs/articles/index.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

2
docs/authors.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

2
docs/index.html

@ -42,7 +42,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

85
docs/news/index.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>
@ -236,12 +236,12 @@ @@ -236,12 +236,12 @@
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div>
<div id="amr-1609030" class="section level1">
<h1 class="page-header" data-toc-text="1.6.0.9030">
<a href="#amr-1609030" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9030</h1>
<div id="last-updated-13-may-2021" class="section level2">
<div id="amr-1609031" class="section level1">
<h1 class="page-header" data-toc-text="1.6.0.9031">
<a href="#amr-1609031" class="anchor"></a><small> Unreleased </small><code>AMR</code> 1.6.0.9031</h1>
<div id="last-updated-15-may-2021" class="section level2">
<h2 class="hasAnchor">
<a href="#last-updated-13-may-2021" class="anchor"></a><small>Last updated: 13 May 2021</small>
<a href="#last-updated-15-may-2021" class="anchor"></a><small>Last updated: 15 May 2021</small>
</h2>
<div id="new" class="section level3">
<h3 class="hasAnchor">
@ -297,7 +297,7 @@ @@ -297,7 +297,7 @@
</li>
<li>Fixed an installation error on R-3.0</li>
<li>Added <code>info</code> argument to <code><a href="../reference/as.mo.html">as.mo()</a></code> to turn on/off the progress bar</li>
<li>Fixed a bug that <code>col_mo</code> for some functions (esp. <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> and <code><a href="../reference/mdro.html">mdro()</a></code>) could not be column names of the <code>microorganisms</code> data set as it would throw an error</li>
<li>Fixed a bug where <code>col_mo</code> in some functions (esp. <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> and <code><a href="../reference/mdro.html">mdro()</a></code>) could not be a column name of the <code>microorganisms</code> data set as it would throw an error</li>
<li>Fix for transforming numeric values to RSI (<code><a href="../reference/as.rsi.html">as.rsi()</a></code>) when the <code>vctrs</code> package is loaded (i.e., when using tidyverse)</li>
<li>Colour fix for using <code><a href="https://rdrr.io/r/graphics/barplot.html">barplot()</a></code> on an RSI class</li>
<li>Added 25 common system codes for bacteria to the <code>microorganisms.codes</code> data set</li>
@ -308,6 +308,13 @@ @@ -308,6 +308,13 @@
<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>
</ul>
</div>
<div id="other" class="section level3">
<h3 class="hasAnchor">
<a href="#other" class="anchor"></a>Other</h3>
<ul>
<li>All unit tests are now processed by the <code>tinytest</code> package, instead of the <code>testthat</code> package. The <code>testthat</code> 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 <code>tinytest</code> package is very lightweight and dependency-free.</li>
</ul>
</div>
</div>
</div>
<div id="amr-160" class="section level1">
@ -438,9 +445,9 @@ @@ -438,9 +445,9 @@
<li>Added argument <code>include_untested_rsi</code> to the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> functions (defaults to <code>TRUE</code> to keep existing behaviour), to be able to exclude rows where all R/SI values (class <code>&lt;rsi&gt;</code>, see <code><a href="../reference/as.rsi.html">as.rsi()</a></code>) are empty</li>
</ul>
</div>
<div id="other" class="section level3">
<div id="other-1" class="section level3">
<h3 class="hasAnchor">
<a href="#other" class="anchor"></a>Other</h3>
<a href="#other-1" class="anchor"></a>Other</h3>
<ul>
<li>Big documentation updates</li>
<li>Loading the package (i.e., <code><a href="https://msberends.github.io/AMR/">library(AMR)</a></code>) now is ~50 times faster than before, in costs of package size (which increased by ~3 MB)</li>
@ -545,9 +552,9 @@ @@ -545,9 +552,9 @@
<li><p>If <code><a href="../reference/as.mo.html">as.mo()</a></code> takes more than 30 seconds, some suggestions will be done to improve speed</p></li>
</ul>
</div>
<div id="other-1" class="section level3">
<div id="other-2" class="section level3">
<h3 class="hasAnchor">
<a href="#other-1" class="anchor"></a>Other</h3>
<a href="#other-2" class="anchor"></a>Other</h3>
<ul>
<li>All messages and warnings thrown by this package now break sentences on whole words</li>
<li>More extensive unit tests</li>
@ -652,9 +659,9 @@ @@ -652,9 +659,9 @@
<li><p>Added argument <code>excess</code> to the <code><a href="../reference/kurtosis.html">kurtosis()</a></code> function (defaults to <code>FALSE</code>), to return the <em>excess kurtosis</em>, defined as the kurtosis minus three.</p></li>
</ul>
</div>
<div id="other-2" class="section level3">
<div id="other-3" class="section level3">
<h3 class="hasAnchor">
<a href="#other-2" class="anchor"></a>Other</h3>
<a href="#other-3" class="anchor"></a>Other</h3>
<ul>
<li>Removed functions <code>portion_R()</code>, <code>portion_S()</code> and <code>portion_I()</code> that were deprecated since version 0.9.0 (November 2019) and were replaced with <code><a href="../reference/proportion.html">proportion_R()</a></code>, <code><a href="../reference/proportion.html">proportion_S()</a></code> and <code><a href="../reference/proportion.html">proportion_I()</a></code>
</li>
@ -737,9 +744,9 @@ @@ -737,9 +744,9 @@
<li><p>Fixed a bug where <code><a href="../reference/as.mic.html">as.mic()</a></code> could not handle dots without a leading zero (like <code>"&lt;=.25</code>)</p></li>
</ul>
</div>
<div id="other-3" class="section level3">
<div id="other-4" class="section level3">
<h3 class="hasAnchor">
<a href="#other-3" class="anchor"></a>Other</h3>
<a href="#other-4" class="anchor"></a>Other</h3>
<ul>
<li>Moved primary location of this project from GitLab to <a href="https://github.com/msberends/AMR">GitHub</a>, giving us native support for automated syntax checking without being dependent on external services such as AppVeyor and Travis CI.</li>
</ul>
@ -798,9 +805,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -798,9 +805,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>Added abbreviation “cfsc” for Cefoxitin and “cfav” for Ceftazidime/avibactam</li>
</ul>
</div>
<div id="other-4" class="section level3">
<div id="other-5" class="section level3">
<h3 class="hasAnchor">
<a href="#other-4" class="anchor"></a>Other</h3>
<a href="#other-5" class="anchor"></a>Other</h3>
<ul>
<li>Removed previously deprecated function <code>p.symbol()</code> - it was replaced with <code><a href="../reference/AMR-deprecated.html">p_symbol()</a></code>
</li>
@ -839,9 +846,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -839,9 +846,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>Added generic CLSI rules for R/SI interpretation using <code><a href="../reference/as.rsi.html">as.rsi()</a></code> for years 2010-2019 (thanks to Anthony Underwood)</li>
</ul>
</div>
<div id="other-5" class="section level3">
<div id="other-6" class="section level3">
<h3 class="hasAnchor">
<a href="#other-5" class="anchor"></a>Other</h3>
<a href="#other-6" class="anchor"></a>Other</h3>
<ul>
<li>Support for the upcoming <code>dplyr</code> version 1.0.0</li>
<li>More robust assigning for classes <code>rsi</code> and <code>mic</code>
@ -941,9 +948,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -941,9 +948,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
</ul>
</div>
<div id="other-6" class="section level3">
<div id="other-7" class="section level3">
<h3 class="hasAnchor">
<a href="#other-6" class="anchor"></a>Other</h3>
<a href="#other-7" class="anchor"></a>Other</h3>
<ul>
<li>Add a <code>CITATION</code> file</li>
<li>Full support for the upcoming R 4.0</li>
@ -1048,9 +1055,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1048,9 +1055,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
</ul>
</div>
<div id="other-7" class="section level3">
<div id="other-8" class="section level3">
<h3 class="hasAnchor">
<a href="#other-7" class="anchor"></a>Other</h3>
<a href="#other-8" class="anchor"></a>Other</h3>
<ul>
<li>Rewrote the complete documentation to markdown format, to be able to use the very latest version of the great <a href="https://roxygen2.r-lib.org/index.html">Roxygen2</a>, released in November 2019. This tremously improved the documentation quality, since the rewrite forced us to go over all texts again and make changes where needed.</li>
<li>Change dependency on <code>clean</code> to <code>cleaner</code>, as this package was renamed accordingly upon CRAN request</li>
@ -1213,9 +1220,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1213,9 +1220,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>Added more MIC factor levels (<code><a href="../reference/as.mic.html">as.mic()</a></code>)</li>
</ul>
<div id="other-8" class="section level4">
<div id="other-9" class="section level4">
<h4 class="hasAnchor">
<a href="#other-8" class="anchor"></a>Other</h4>
<a href="#other-9" class="anchor"></a>Other</h4>
<ul>
<li>Added Prof. Dr. Casper Albers as doctoral advisor and added Dr. Judith Fonville, Eric Hazenberg, Dr. Bart Meijer, Dr. Dennis Souverein and Annick Lenglet as contributors</li>
<li>Cleaned the coding style of every single syntax line in this package with the help of the <code>lintr</code> package</li>
@ -1299,9 +1306,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1299,9 +1306,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
</ul>
</div>
<div id="other-9" class="section level4">
<div id="other-10" class="section level4">
<h4 class="hasAnchor">
<a href="#other-9" class="anchor"></a>Other</h4>
<a href="#other-10" class="anchor"></a>Other</h4>
<ul>
<li>Fixed a note thrown by CRAN tests</li>
</ul>
@ -1394,9 +1401,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1394,9 +1401,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>Fix for <code><a href="../reference/mo_property.html">mo_shortname()</a></code> where species would not be determined correctly</li>
</ul>
</div>
<div id="other-10" class="section level4">
<div id="other-11" class="section level4">
<h4 class="hasAnchor">
<a href="#other-10" class="anchor"></a>Other</h4>
<a href="#other-11" class="anchor"></a>Other</h4>
<ul>
<li>Support for R 3.6.0 and later by providing support for <a href="https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html">staged install</a>
</li>
@ -1659,9 +1666,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1659,9 +1666,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>if using different lengths of pattern and x in <code><a href="../reference/like.html">%like%</a></code>, it will now return the call</li>
</ul>
</div>
<div id="other-11" class="section level4">
<div id="other-12" class="section level4">
<h4 class="hasAnchor">
<a href="#other-11" class="anchor"></a>Other</h4>
<a href="#other-12" class="anchor"></a>Other</h4>
<ul>
<li>Updated licence text to emphasise GPL 2.0 and that this is an R package.</li>
</ul>
@ -1780,9 +1787,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1780,9 +1787,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Percentages will now will rounded more logically (e.g. in <code>freq</code> function)</p></li>
</ul>
</div>
<div id="other-12" class="section level4">
<div id="other-13" class="section level4">
<h4 class="hasAnchor">
<a href="#other-12" class="anchor"></a>Other</h4>
<a href="#other-13" class="anchor"></a>Other</h4>
<ul>
<li>New dependency on package <code>crayon</code>, to support formatted text in the console</li>
<li>Dependency <code>tidyr</code> is now mandatory (went to <code>Import</code> field) since <code>portion_df</code> and <code>count_df</code> rely on it</li>
@ -1930,9 +1937,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -1930,9 +1937,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
</ul>
</div>
<div id="other-13" class="section level4">
<div id="other-14" class="section level4">
<h4 class="hasAnchor">
<a href="#other-13" class="anchor"></a>Other</h4>
<a href="#other-14" class="anchor"></a>Other</h4>
<ul>
<li>More unit tests to ensure better integrity of functions</li>
</ul>
@ -2058,9 +2065,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -2058,9 +2065,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>Other small fixes</li>
</ul>
</div>
<div id="other-14" class="section level4">
<div id="other-15" class="section level4">
<h4 class="hasAnchor">
<a href="#other-14" class="anchor"></a>Other</h4>
<a href="#other-15" class="anchor"></a>Other</h4>
<ul>
<li>Added integration tests (check if everything works as expected) for all releases of R 3.1 and higher
<ul>
@ -2119,9 +2126,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ @@ -2119,9 +2126,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>Functions <code>as.rsi</code> and <code>as.mic</code> now add the package name and version as attributes</li>
</ul>
</div>
<div id="other-15" class="section level4">
<div id="other-16" class="section level4">
<h4 class="hasAnchor">
<a href="#other-15" class="anchor"></a>Other</h4>
<a href="#other-16" class="anchor"></a>Other</h4>
<ul>
<li>Expanded <code>README.md</code> with more examples</li>
<li>Added <a href="https://orcid.org">ORCID</a> of authors to DESCRIPTION file</li>

2
docs/pkgdown.yml

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

2
docs/reference/index.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

2
docs/survey.html

@ -81,7 +81,7 @@ @@ -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.9030</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9031</span>
</span>
</div>

23
tests/testthat/test-get_locale.R → inst/tinytest/test-_deprecated.R

@ -23,18 +23,17 @@ @@ -23,18 +23,17 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("get_locale.R")
expect_identical(suppressWarnings(p_symbol(c(0.001, 0.01, 0.05, 0.1, 1, NA, 3))),
c("***", "**", "*", ".", " ", NA, NA))
test_that("get_locale works", {
skip_on_cran()
expect_identical(mo_genus("B_GRAMP", language = "pt"),
"(Gram positivos desconhecidos)")
expect_warning(key_antibiotics(example_isolates))
expect_identical(suppressWarnings(key_antibiotics(example_isolates)),
key_antimicrobials(example_isolates, antifungal = NULL))
expect_identical(mo_fullname("CoNS", "en"), "Coagulase-negative Staphylococcus (CoNS)")
expect_identical(mo_fullname("CoNS", "de"), "Koagulase-negative Staphylococcus (KNS)")
expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)")
expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (SCN)")
expect_identical(mo_fullname("CoNS", "it"), "Staphylococcus negativo coagulasi (CoNS)")
expect_identical(mo_fullname("CoNS", "pt"), "Staphylococcus coagulase negativo (CoNS)")
expect_warning(key_antibiotics_equal("S", "S"))
expect_identical(suppressWarnings(key_antibiotics_equal("S", "S")),
antimicrobials_equal("S", "S", type = "keyantimicrobials"))
})
expect_warning(filter_first_weighted_isolate(example_isolates))
expect_identical(suppressWarnings(filter_first_weighted_isolate(example_isolates)),
filter_first_isolate(example_isolates))

59
tests/testthat/test-episode.R → inst/tinytest/test-_misc.R

@ -22,37 +22,34 @@ @@ -22,37 +22,34 @@
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("episode.R")
test_that("episodes work", {
skip_on_cran()
test_df <- rbind(
data.frame(
date = as.Date(c("2015-01-01", "2015-10-01", "2016-02-04", "2016-12-31", "2017-01-01", "2017-02-01", "2017-02-05", "2020-01-01")),
patient_id = "A"
),
data.frame(
date = as.Date(c("2015-01-01", "2016-02-01", "2016-12-31", "2017-01-01", "2017-02-03")),
patient_id = "B"
))
expect_equal(get_episode(test_df$date, 365),
c(1, 1, 2, 2, 2, 3, 3, 4, 1, 2, 2, 2, 3))
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%")
# round up 0.5
expect_equal(percentage(0.0054), "0.5%")
expect_equal(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_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))
}
# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this:
if (suppressWarnings(require("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))
suppressMessages(
x <- example_isolates %>%
mutate(out = first_isolate(., include_unknown = TRUE, method = "episode-based", info = FALSE))
)
y <- example_isolates %>%
group_by(patient_id, mo) %>%
mutate(out = is_new_episode(date, 365))
expect_identical(which(x$out), which(y$out))
expect_true(is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
}
})

75
tests/testthat/test-g.test.R → inst/tinytest/test-ab.R

@ -23,49 +23,50 @@ @@ -23,49 +23,50 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("g.test.R")
expect_equal(as.character(as.ab(c("J01FA01",
"J 01 FA 01",
"Erythromycin",
"eryt",
" eryt 123",
"ERYT",
"ERY",
"erytromicine",
"Erythrocin",
"Romycin"))),
rep("ERY", 10))
test_that("G-test works", {
skip_on_cran()
expect_identical(class(as.ab("amox")), c("ab", "character"))
expect_identical(class(antibiotics$ab), c("ab", "character"))
expect_true(is.ab(as.ab("amox")))
expect_stdout(print(as.ab("amox")))
expect_stdout(print(data.frame(a = as.ab("amox"))))
# GOODNESS-OF-FIT
expect_warning(as.ab("J00AA00")) # ATC not yet available in data set
expect_warning(as.ab("UNKNOWN"))
expect_warning(as.ab(""))
# example 1: clearfield rice vs. red rice
x <- c(772, 1611, 737)
expect_equal(g.test(x, p = c(0.25, 0.50, 0.25))$p.value,
expected = 0.12574,
tolerance = 0.00001)
expect_stdout(print(as.ab("amox")))
# example 2: red crossbills
x <- c(1752, 1895)
expect_equal(g.test(x)$p.value,
expected = 0.01787343,
tolerance = 0.00000001)
expect_equal(as.character(as.ab("Phloxapen")),
"FLC")
expect_error(g.test(0))
expect_error(g.test(c(0, 1), 0))
expect_error(g.test(c(1, 2, 3, 4), p = c(0.25, 0.25)))
expect_error(g.test(c(1, 2, 3, 4), p = c(0.25, 0.25, 0.25, 0.24)))
expect_warning(g.test(c(1, 2, 3, 4), p = c(0.25, 0.25, 0.25, 0.24), rescale.p = TRUE))
expect_equal(suppressWarnings(as.character(as.ab(c("Bacteria", "Bacterial")))),
c(NA, "TMP"))
# INDEPENDENCE
expect_equal(as.character(as.ab("Amoxy + clavulaanzuur")),
"AMC")
x <- as.data.frame(
matrix(data = round(runif(4) * 100000, 0),
ncol = 2,
byrow = TRUE)
)
# fisher.test() is always better for 2x2 tables:
expect_warning(g.test(x))
expect_lt(suppressWarnings(g.test(x)$p.value),
1)
expect_equal(as.character(as.ab(c("mreopenem", "co-maoxiclav"))),
c("MEM", "AMC"))
expect_warning(g.test(x = c(772, 1611, 737),
y = c(780, 1560, 780),
rescale.p = TRUE))
expect_message(as.ab("cipro mero"))
expect_error(g.test(matrix(data = c(-1, -2, -3, -4), ncol = 2, byrow = TRUE)))
expect_error(g.test(matrix(data = c(0, 0, 0, 0), ncol = 2, byrow = TRUE)))
})
# assigning and subsetting
x <- antibiotics$ab
expect_inherits(x[1], "ab")
expect_inherits(x[[1]], "ab")
expect_inherits(c(x[1], x[9]), "ab")
expect_inherits(unique(x[1], x[9]), "ab")
expect_warning(x[1] <- "invalid code")
expect_warning(x[[1]] <- "invalid code")
expect_warning(c(x[1], "test"))

36
tests/testthat/test-ab_from_text.R → inst/tinytest/test-ab_class_selectors.R

@ -23,24 +23,20 @@ @@ -23,24 +23,20 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("ab_from_text.R")
if (suppressWarnings(require("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))
expect_true(example_isolates %>% select(cephalosporins_1st()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(cephalosporins_2nd()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(cephalosporins_3rd()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(cephalosporins_4th()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(cephalosporins_5th()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(fluoroquinolones()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(glycopeptides()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(macrolides()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(oxazolidinones()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(penicillins()) %>% ncol() < ncol(example_isolates))
expect_true(example_isolates %>% select(tetracyclines()) %>% ncol() < ncol(example_isolates))
}
test_that("ab_from_text works", {
skip_on_cran()
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds")[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = TRUE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = FALSE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]],
"Amoxicillin")
expect_identical(ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]],
"AMC, CIP")
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", type = "dose")[[1]],
500)
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", type = "admin")[[1]],
"oral")
})

33
tests/testthat/test-_deprecated.R → inst/tinytest/test-ab_from_text.R

@ -23,23 +23,18 @@ @@ -23,23 +23,18 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("deprecated.R")
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds")[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = TRUE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = FALSE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]],
"Amoxicillin")
expect_identical(ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]],
"AMC, CIP")
test_that("deprecated functions work", {
skip_on_cran()
expect_identical(suppressWarnings(p_symbol(c(0.001, 0.01, 0.05, 0.1, 1, NA, 3))),
c("***", "**", "*", ".", " ", NA, NA))
expect_warning(key_antibiotics(example_isolates))
expect_identical(suppressWarnings(key_antibiotics(example_isolates)),
key_antimicrobials(example_isolates, antifungal = NULL))
expect_warning(key_antibiotics_equal("S", "S"))
expect_identical(suppressWarnings(key_antibiotics_equal("S", "S")),
antimicrobials_equal("S", "S", type = "keyantimicrobials"))
expect_warning(filter_first_weighted_isolate(example_isolates))
expect_identical(suppressWarnings(filter_first_weighted_isolate(example_isolates)),
filter_first_isolate(example_isolates))
})
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", type = "dose")[[1]],
500)
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", type = "admin")[[1]],
"oral")

63
inst/tinytest/test-ab_property.R

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Data Analysis for R #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2021 Berends MS, Luz CF et al. #
# Developed at the University of Groningen, the Netherlands, in #
# collaboration with non-profit organisations Certe Medical #
# Diagnostics & Advice, and University Medical Center Groningen. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_identical(ab_name("AMX", language = NULL), "Amoxicillin")
expect_identical(as.character(ab_atc("AMX")), "J01CA04")
expect_identical(ab_cid("AMX"), as.integer(33613))
expect_inherits(ab_tradenames("AMX"), "character")
expect_inherits(ab_tradenames(c("AMX", "AMX")), "list")
expect_identical(ab_group("AMX", language = NULL), "Beta-lactams/penicillins")
expect_identical(ab_atc_group1("AMX", language = NULL), "Beta-lactam antibacterials, penicillins")
expect_identical(ab_atc_group2("AMX", language = NULL), "Penicillins with extended spectrum")
expect_identical(ab_name("Fluclox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("fluklox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("floxapen", language = NULL), "Flucloxacillin")
expect_identical(ab_name(21319, language = NULL), "Flucloxacillin")
expect_identical(ab_name("J01CF05", language = NULL), "Flucloxacillin")
expect_identical(ab_ddd("AMX", "oral"), 1.5)
expect_identical(ab_ddd("AMX", "oral", units = TRUE), "g")
expect_identical(ab_ddd("AMX", "iv"), 3)
expect_identical(ab_ddd("AMX", "iv", units = TRUE), "g")
expect_identical(ab_name(x = c("AMC", "PLB"), language = NULL), c("Amoxicillin/clavulanic acid", "Polymyxin B"))
expect_identical(ab_name(x = c("AMC", "PLB"), tolower = TRUE, language = NULL),
c("amoxicillin/clavulanic acid", "polymyxin B"))
expect_inherits(ab_info("AMX"), "list")
expect_error(ab_property("amox", "invalid property"))
expect_error(ab_name("amox", language = "INVALID"))
expect_stdout(print(ab_name("amox", language = NULL)))
expect_equal(ab_name("21066-6", language = NULL), "Ampicillin")
expect_equal(ab_loinc("ampicillin"),
c("21066-6", "3355-5", "33562-0", "33919-2", "43883-8", "43884-6", "87604-5"))
expect_true(ab_url("AMX") %like% "whocc.no")
expect_warning(ab_url("ASP"))

61
tests/testthat/test-join_microorganisms.R → inst/tinytest/test-age.R

@ -23,41 +23,46 @@ @@ -23,41 +23,46 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("join_microorganisms.R")
expect_equal(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = "2019-01-01"),
c(39, 34, 29))
test_that("joins work", {
skip_on_cran()
unjoined <- example_isolates
inner <- example_isolates %>% inner_join_microorganisms()
left <- example_isolates %>% left_join_microorganisms()
semi <- example_isolates %>% semi_join_microorganisms()
anti <- example_isolates %>% anti_join_microorganisms()
suppressWarnings(right <- example_isolates %>% right_join_microorganisms())
suppressWarnings(full <- example_isolates %>% full_join_microorganisms())
expect_equal(age(x = c("2019-01-01", "2019-04-01", "2019-07-01"),
reference = "2019-09-01",
exact = TRUE),
c(0.6656393, 0.4191781, 0.1698630),
tolerance = 0.001)
expect_true(ncol(unjoined) < ncol(inner))
expect_true(nrow(unjoined) == nrow(inner))
expect_error(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = c("2019-01-01", "2019-01-01")))
expect_true(ncol(unjoined) < ncol(left))
expect_true(nrow(unjoined) == nrow(left))
expect_warning(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = "1975-01-01"))
expect_true(ncol(semi) == ncol(semi))
expect_true(nrow(semi) == nrow(semi))
expect_warning(age(x = c("1800-01-01", "1805-01-01", "1810-01-01"),
reference = "2019-01-01"))
expect_true(nrow(anti) == 0)
expect_equal(length(age(x = c("2019-01-01", NA), na.rm = TRUE)),
1)
expect_true(nrow(unjoined) < nrow(right))
expect_true(nrow(unjoined) < nrow(full))
expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COLI")), 1)
expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COLI", by = c("mo" = "mo"))), 1)
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
expect_equal(nrow(left_join_microorganisms("B_ESCHR_COLI")), 1)
expect_equal(length(unique(age_groups(ages, 50))),
2)
expect_equal(length(unique(age_groups(ages, c(50, 60)))),
3)
expect_identical(class(age_groups(ages, "child")),
c("ordered", "factor"))
expect_equal(nrow(semi_join_microorganisms("B_ESCHR_COLI")), 1)
expect_equal(nrow(anti_join_microorganisms("B_ESCHR_COLI")), 0)
expect_identical(class(age_groups(ages, "elderly")),
c("ordered", "factor"))
expect_warning(right_join_microorganisms("B_ESCHR_COLI"))
expect_warning(full_join_microorganisms("B_ESCHR_COLI"))
})
expect_identical(class(age_groups(ages, "tens")),
c("ordered", "factor"))
expect_identical(class(age_groups(ages, "fives")),
c("ordered", "factor"))
expect_equal(length(age_groups(c(10, 20, 30, NA), na.rm = TRUE)),
3)

12
tests/testthat/test-atc_online.R → inst/tinytest/test-atc_online.R

@ -23,15 +23,9 @@ @@ -23,15 +23,9 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("atc_online.R")
test_that("atc_online works", {
skip_on_cran()
skip_if_not_installed("curl")
skip_if_not(curl::has_internet())
expect_gte(length(atc_online_groups(ab_atc("AMX"))), 1)
if (tryCatch(curl::has_internet(), error = function(e) FALSE)) {
expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "P"), 3)
expect_warning(atc_online_ddd(ab_atc("Novobiocin"), administration = "P"))
})
}

9
tests/testthat/test-availability.R → inst/tinytest/test-availability.R

@ -22,10 +22,5 @@ @@ -22,10 +22,5 @@
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("availability.R")
test_that("availability works", {
skip_on_cran()
expect_equal(class(availability(example_isolates)), "data.frame")
})
expect_inherits(availability(example_isolates), "data.frame")

19
tests/testthat/test-skewness.R → inst/tinytest/test-bug_drug_combinations.R

@ -23,17 +23,8 @@ @@ -23,17 +23,8 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
context("skewness.R")
test_that("skewness works", {
skip_on_cran()
expect_equal(skewness(example_isolates$age),
-1.212888,
tolerance = 0.00001)
expect_equal(unname(skewness(data.frame(example_isolates$age))),
-1.212888,
tolerance = 0.00001)
expect_equal(skewness(matrix(example_isolates$age)),
-1.212888,
tolerance = 0.00001)
})
b <- suppressWarnings(bug_drug_combinations(example_isolates))
expect_inherits(b, "bug_drug_combinations")
expect_stdout(print(b))
expect_true(is.data.frame(format(b)))
expect_true(is.data.frame(format(b, combine_IR = TRUE, add_ab_group = FALSE)))

99
inst/tinytest/test-count.R

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Data Analysis for R #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2021 Berends MS, Luz CF et al. #
# Developed at the University of Groningen, the Netherlands, in #
# collaboration with non-profit organisations Certe Medical #
# Diagnostics & Advice, and University Medical Center Groningen. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_equal(count_resistant(example_isolates$AMX), count_R(example_isolates$AMX))
expect_equal(count_susceptible(example_isolates$AMX), count_SI(example_isolates$AMX))
expect_equal(count_all(example_isolates$AMX), n_rsi(example_isolates$AMX))
# AMX resistance in `example_isolates`
expect_equal(count_R(example_isolates$AMX), 804)
expect_equal(count_I(example_isolates$AMX), 3)
expect_equal(suppressWarnings(count_S(example_isolates$AMX)), 543)
expect_equal(count_R(example_isolates$AMX) + count_I(example_isolates$AMX),
suppressWarnings(count_IR(example_isolates$AMX)))
expect_equal(suppressWarnings(count_S(example_isolates$AMX)) + count_I(example_isolates$AMX),
count_SI(example_isolates$AMX))
# warning for speed loss
reset_all_thrown_messages()
expect_warning(count_resistant(as.character(example_isolates$AMC)))
reset_all_thrown_messages()
expect_warning(count_resistant(example_isolates$AMC,
as.character(example_isolates$GEN)))
# check for errors
expect_error(count_resistant("test", minimum = "test"))
expect_error(count_resistant("test", as_percent = "test"))
expect_error(count_susceptible("test", minimum = "test"))
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"))) {
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)
expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE), 1798)
expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = FALSE), 1936)
expect_identical(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE),
example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE) +
example_isolates %>% count_resistant(AMC, GEN, only_all_tested = TRUE))
# count of cases
expect_equal(example_isolates %>%
group_by(hospital_id) %>%
summarise(cipro = count_susceptible(CIP),
genta = count_susceptible(GEN),
combination = count_susceptible(CIP, GEN)) %>%
pull(combination),
c(253, 465, 192, 558))
# count_df
expect_equal(
example_isolates %>% select(AMX) %>% count_df() %>% pull(value),
c(example_isolates$AMX %>% count_susceptible(),
example_isolates$AMX %>% count_resistant())
)
expect_equal(
example_isolates %>% select(AMX) %>% count_df(combine_IR = TRUE) %>% pull(value),
c(suppressWarnings(example_isolates$AMX %>% count_S()),
suppressWarnings(example_isolates$AMX %>% count_IR()))
)
expect_equal(
example_isolates %>% select(AMX) %>% count_df(combine_SI = FALSE) %>% pull(value),
c(suppressWarnings(example_isolates$AMX %>% count_S()),
example_isolates$AMX %>% count_I(),
example_isolates$AMX %>% count_R())
)
# grouping in rsi_calc_df() (= backbone of rsi_df())
expect_true("hospital_id" %in% (example_isolates %>%
group_by(hospital_id) %>%
select(hospital_id, AMX, CIP, gender) %>%
rsi_df() %>%
colnames()))
}

84
inst/tinytest/test-data.R

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Data Analysis for R #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2021 Berends MS, Luz CF et al. #
# Developed at the University of Groningen, the Netherlands, in #
# collaboration with non-profit organisations Certe Medical #
# Diagnostics & Advice, and University Medical Center Groningen. #
# #
# This R package is free software; you ca