diff --git a/DESCRIPTION b/DESCRIPTION index cc9fc761..fc14968e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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( diff --git a/NEWS.md b/NEWS.md index f78a1028..f95332df 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.5.0.9016 +# AMR 1.5.0.9017 ## Last updated: 8 February 2021 ### New @@ -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 diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 336c4872..d63cf6e9 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -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) { diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index e716bf2f..893413e9 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -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" diff --git a/R/first_isolate.R b/R/first_isolate.R index 995e9c17..81d49977 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -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, 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, 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)) { diff --git a/R/key_antibiotics.R b/R/key_antibiotics.R index 686d59f3..11f4195e 100755 --- a/R/key_antibiotics.R +++ b/R/key_antibiotics.R @@ -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) diff --git a/R/mdro.R b/R/mdro.R index a5a9b3e5..e14206f5 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -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 diff --git a/data-raw/AMR_1.5.0.9016.tar.gz b/data-raw/AMR_1.5.0.9017.tar.gz similarity index 88% rename from data-raw/AMR_1.5.0.9016.tar.gz rename to data-raw/AMR_1.5.0.9017.tar.gz index ad1a0193..c3ea82bb 100644 Binary files a/data-raw/AMR_1.5.0.9016.tar.gz and b/data-raw/AMR_1.5.0.9017.tar.gz differ diff --git a/docs/404.html b/docs/404.html index 9f8b1cf3..90d7944f 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index a9c2bca3..bc5967d7 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/articles/index.html b/docs/articles/index.html index d6f73389..be0ffa27 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/authors.html b/docs/authors.html index bd5df5f6..ab0d3f3f 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/index.html b/docs/index.html index 24e23c9c..53683825 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 4dd7b6e4..21a36d32 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -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 diff --git a/docs/reference/index.html b/docs/reference/index.html index c08f1829..5c6ae730 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/docs/survey.html b/docs/survey.html index 90349031..07e2bfb7 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9017 diff --git a/tests/testthat/test-antibiotic_class_selectors.R b/tests/testthat/test-ab_class_selectors.R similarity index 96% rename from tests/testthat/test-antibiotic_class_selectors.R rename to tests/testthat/test-ab_class_selectors.R index 1ddf6afb..bc215db8 100644 --- a/tests/testthat/test-antibiotic_class_selectors.R +++ b/tests/testthat/test-ab_class_selectors.R @@ -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)) diff --git a/tests/testthat/test-filter_ab_class.R b/tests/testthat/test-filter_ab_class.R index 35fbfa9f..439551b0 100644 --- a/tests/testthat/test-filter_ab_class.R +++ b/tests/testthat/test-filter_ab_class.R @@ -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) diff --git a/tests/testthat/test-first_isolate.R b/tests/testthat/test-first_isolate.R index e20df1f8..ec776a28 100755 --- a/tests/testthat/test-first_isolate.R +++ b/tests/testthat/test-first_isolate.R @@ -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", { type = "keyantibiotics", info = TRUE), na.rm = TRUE)), - 1419) + 1418) # when using points expect_equal( suppressWarnings( @@ -78,7 +78,7 @@ test_that("first isolates work", { type = "points", info = TRUE), na.rm = TRUE)), - 1399) + 1398) # first non-ICU isolates expect_equal( diff --git a/tests/testthat/test-mdro.R b/tests/testthat/test-mdro.R index 2b9c4655..42bf6363 100755 --- a/tests/testthat/test-mdro.R +++ b/tests/testthat/test-mdro.R @@ -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", { 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)) + })