Browse Source

(v1.5.0.9017) unit testing

v1.8.2
parent
commit
cb404492b2
  1. 2
      DESCRIPTION
  2. 6
      NEWS.md
  3. 2
      R/aa_helper_functions.R
  4. 3
      R/filter_ab_class.R
  5. 9
      R/first_isolate.R
  6. 3
      R/key_antibiotics.R
  7. 3
      R/mdro.R
  8. BIN
      data-raw/AMR_1.5.0.9017.tar.gz
  9. 2
      docs/404.html
  10. 2
      docs/LICENSE-text.html
  11. 2
      docs/articles/index.html
  12. 2
      docs/authors.html
  13. 2
      docs/index.html
  14. 2
      docs/pkgdown.yml
  15. 2
      docs/reference/index.html
  16. 2
      docs/survey.html
  17. 1
      tests/testthat/test-ab_class_selectors.R
  18. 25
      tests/testthat/test-filter_ab_class.R
  19. 6
      tests/testthat/test-first_isolate.R
  20. 7
      tests/testthat/test-mdro.R

2
DESCRIPTION

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Package: AMR
Version: 1.5.0.9016
Version: 1.5.0.9017
Date: 2021-02-08
Title: Antimicrobial Resistance Data Analysis
Authors@R: c(

6
NEWS.md

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
# AMR 1.5.0.9016
# AMR 1.5.0.9017
## <small>Last updated: 8 February 2021</small>
### New
@ -52,11 +52,11 @@ @@ -52,11 +52,11 @@
* WHONET code `"PNV"` will now correctly be interpreted as `PHN`, the antibiotic code for phenoxymethylpenicillin ('peni V')
* Fix for verbose output of `mdro(..., verbose = TRUE)` for German guideline (3MGRN and 4MGRN) and Dutch guideline (BRMO, only *P. aeruginosa*)
* `is.rsi.eligible()` now detects if the column name resembles an antibiotic name or code and now returns `TRUE` immediately if the input contains any of the values "R", "S" or "I". This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns.
* Functions `get_episode()` and `is_new_episode()` now support less than a day as value for argument `episode_days` (e.g., to include one patient/test per hour)
* Functions `get_episode()` and `is_new_episode()` now support less than a day as value for argument `episode_days` (e.g., to include one patient/test per hour)
* Argument `ampc_cephalosporin_resistance` in `eucast_rules()` now also applies to value "I" (not only "S")
* Updated colours of values R, S and I in tibble printing
* Functions `print()` and `summary()` on a Principal Components Analysis object (`pca()`) now print additional group info if the original data was grouped using `dplyr::group_by()`
* Improved speed of `guess_ab_col()`
* Improved speed and reliability of `guess_ab_col()`. As this also internally improves the reliability of `first_isolate()` and `mdro()`, this might have a slight impact on the results of those functions.
### Other
* Big documentation updates

2
R/aa_helper_functions.R

@ -734,7 +734,7 @@ get_current_column <- function() { @@ -734,7 +734,7 @@ get_current_column <- function() {
is_null_or_grouped_tbl <- function(x) {
# attribute "grouped_df" might change at one point, so only set in one place; here.
is.null(x) || inherits(x, "grouped_tbl")
is.null(x) || inherits(x, "grouped_df")
}
unique_call_id <- function(entire_session = FALSE) {

3
R/filter_ab_class.R

@ -147,9 +147,6 @@ filter_ab_class <- function(x, @@ -147,9 +147,6 @@ filter_ab_class <- function(x,
} else {
scope_txt <- " and "
scope_fn <- all
if (length(agents) > 1) {
operator <- gsub("is", "are", operator)
}
}
if (length(agents) > 1) {
operator <- " are"

9
R/first_isolate.R

@ -187,7 +187,8 @@ first_isolate <- function(x = NULL, @@ -187,7 +187,8 @@ first_isolate <- function(x = NULL,
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# is also fix for using a grouped df as input (a dot as first argument)
x <- get_current_data(arg_name = "x", call = -2)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
meet_criteria(x, allow_class = "data.frame")
}
# remove data.table, grouping from tibbles, etc.
x <- as.data.frame(x, stringsAsFactors = FALSE)
@ -518,7 +519,8 @@ filter_first_isolate <- function(x = NULL, @@ -518,7 +519,8 @@ filter_first_isolate <- function(x = NULL,
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# is also fix for using a grouped df as input (a dot as first argument)
x <- get_current_data(arg_name = "x", call = -2)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
meet_criteria(x, allow_class = "data.frame")
}
subset(x, first_isolate(x = x,
col_date = col_date,
@ -543,7 +545,8 @@ filter_first_weighted_isolate <- function(x = NULL, @@ -543,7 +545,8 @@ filter_first_weighted_isolate <- function(x = NULL,
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# is also fix for using a grouped df as input (a dot as first argument)
x <- get_current_data(arg_name = "x", call = -2)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
meet_criteria(x, allow_class = "data.frame")
}
y <- x
if (is.null(col_keyantibiotics)) {

3
R/key_antibiotics.R

@ -155,7 +155,8 @@ key_antibiotics <- function(x = NULL, @@ -155,7 +155,8 @@ key_antibiotics <- function(x = NULL,
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# is also fix for using a grouped df as input (a dot as first argument)
x <- get_current_data(arg_name = "x", call = -2)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
meet_criteria(x, allow_class = "data.frame")
}
# force regular data.frame, not a tibble or data.table
x <- as.data.frame(x, stringsAsFactors = FALSE)

3
R/mdro.R

@ -218,7 +218,8 @@ mdro <- function(x = NULL, @@ -218,7 +218,8 @@ mdro <- function(x = NULL,
if (is_null_or_grouped_tbl(x)) {
# when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all())
# is also fix for using a grouped df as input (a dot as first argument)
x <- get_current_data(arg_name = "x", call = -2)
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
meet_criteria(x, allow_class = "data.frame")
}
# force regular data.frame, not a tibble or data.table

BIN
data-raw/AMR_1.5.0.9016.tar.gz → data-raw/AMR_1.5.0.9017.tar.gz

Binary file not shown.

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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</span>
</span>
</div>

2
docs/index.html

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

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-02-08T12:50Z
last_built: 2021-02-08T19:58Z
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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</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.5.0.9016</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9017</span>
</span>
</div>

1
tests/testthat/test-antibiotic_class_selectors.R → tests/testthat/test-ab_class_selectors.R

@ -39,6 +39,7 @@ test_that("Antibiotic class selectors work", { @@ -39,6 +39,7 @@ test_that("Antibiotic class selectors work", {
expect_lt(example_isolates %>% dplyr::select(fluoroquinolones()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(glycopeptides()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(macrolides()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(oxazolidinones()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(penicillins()) %>% ncol(), ncol(example_isolates))
expect_lt(example_isolates %>% dplyr::select(tetracyclines()) %>% ncol(), ncol(example_isolates))

25
tests/testthat/test-filter_ab_class.R

@ -30,17 +30,20 @@ test_that("ATC-group filtering works", { @@ -30,17 +30,20 @@ test_that("ATC-group filtering works", {
library(dplyr)
expect_gt(example_isolates %>% filter_ab_class("carbapenem") %>% nrow(), 0)
expect_gt(example_isolates %>% filter_aminoglycosides() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_carbapenems() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_cephalosporins() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_1st_cephalosporins() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_2nd_cephalosporins() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_3rd_cephalosporins() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_4th_cephalosporins() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_fluoroquinolones() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_glycopeptides() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_macrolides() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_tetracyclines() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_aminoglycosides() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_carbapenems() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_1st_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_2nd_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_3rd_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_4th_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_5th_cephalosporins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_fluoroquinolones() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_glycopeptides() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_macrolides() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_oxazolidinones() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_penicillins() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_tetracyclines() %>% ncol(), 0)
expect_gt(example_isolates %>% filter_carbapenems("R", "all") %>% nrow(), 0)

6
tests/testthat/test-first_isolate.R

@ -50,7 +50,7 @@ test_that("first isolates work", { @@ -50,7 +50,7 @@ test_that("first isolates work", {
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1396)
1395)
# when not ignoring I
expect_equal(
@ -65,7 +65,7 @@ test_that("first isolates work", { @@ -65,7 +65,7 @@ test_that("first isolates work", {
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1419)
1418)
# when using points
expect_equal(
suppressWarnings(
@ -78,7 +78,7 @@ test_that("first isolates work", { @@ -78,7 +78,7 @@ test_that("first isolates work", {
type = "points",
info = TRUE),
na.rm = TRUE)),
1399)
1398)
# first non-ICU isolates
expect_equal(

7
tests/testthat/test-mdro.R

@ -47,7 +47,7 @@ test_that("mdro works", { @@ -47,7 +47,7 @@ test_that("mdro works", {
library(dplyr)
# example_isolates should have these finding using Dutch guidelines
expect_equal(as.double(table(outcome)),
c(1969, 25, 6)) # 1969 neg, 25 unconfirmed, 6 pos
c(1970, 24, 6)) # 1970 neg, 24 unconfirmed, 6 pos
expect_equal(brmo(example_isolates, info = FALSE),
mdro(example_isolates, guideline = "BRMO", info = FALSE))
@ -241,4 +241,9 @@ test_that("mdro works", { @@ -241,4 +241,9 @@ test_that("mdro works", {
guideline = custom_mdro_guideline(test ~ "A"),
info = FALSE))
# print groups
library(dplyr)
expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), info = TRUE))
expect_output(x <- mdro(example_isolates %>% group_by(hospital_id), guideline = custom, info = TRUE))
})

Loading…
Cancel
Save