diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 5e55ee43..6499de07 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -121,6 +121,7 @@ jobs: # - name: Only keep vignettes on release version - name: Remove vignettes # if: matrix.config.r != 'release' + if: always() # writing to DESCRIPTION2 and then moving to DESCRIPTION is required for R < 3.3 as writeLines() cannot overwrite run: | rm -rf AMR/vignettes diff --git a/DESCRIPTION b/DESCRIPTION index 0e3944fc..3806104e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.6.0.9064 +Version: 1.6.0.9065 Date: 2021-05-24 Title: Antimicrobial Resistance Data Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index c6c5ee0a..af61cdf7 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# `AMR` 1.6.0.9064 +# `AMR` 1.6.0.9065 ## Last updated: 24 May 2021 ### Breaking change diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 1411b022..035cc239 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -864,8 +864,13 @@ unique_call_id <- function(entire_session = FALSE) { } else { # combination of environment ID (like "0x7fed4ee8c848") # and highest system call + call <- paste0(deparse(sys.calls()[[1]]), collapse = "") + if (call %like% "run_test_dir|test_all|tinytest|test_package|testthat") { + # unit tests will keep the same call and environment - give them a unique ID + call <- paste0(sample(c(c(0:9), letters[1:6]), size = 64, replace = TRUE), collapse = "") + } c(envir = gsub("", "\\1", utils::capture.output(sys.frames()[[1]])), - call = paste0(deparse(sys.calls()[[1]]), collapse = "")) + call = call) } } @@ -881,14 +886,6 @@ message_not_thrown_before <- function(fn, entire_session = FALSE) { is.null(pkg_env[[paste0("thrown_msg.", fn)]]) || !identical(pkg_env[[paste0("thrown_msg.", fn)]], unique_call_id(entire_session)) } -reset_all_thrown_messages <- function() { - # for unit tests, where the environment and highest system call do not change - # can be found in tests/testthat/*.R - pkg_env_contents <- ls(envir = pkg_env) - rm(list = pkg_env_contents[pkg_env_contents %like% "^thrown_msg."], - envir = pkg_env) -} - has_colour <- function() { # this is a base R version of crayon::has_color, but disables colours on emacs diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 16cab8c4..2f5dfa95 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -115,35 +115,35 @@ #' ggplot() + #' geom_col(aes(x = x, y = y, fill = z)) + #' scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R") +#' +#' # resistance of ciprofloxacine per age group +#' example_isolates %>% +#' mutate(first_isolate = first_isolate()) %>% +#' filter(first_isolate == TRUE, +#' mo == as.mo("E. coli")) %>% +#' # age_groups() is also a function in this AMR package: +#' group_by(age_group = age_groups(age)) %>% +#' select(age_group, +#' CIP) %>% +#' ggplot_rsi(x = "age_group") +#' +#' # a shorter version which also adjusts data label colours: +#' example_isolates %>% +#' select(AMX, NIT, FOS, TMP, CIP) %>% +#' ggplot_rsi(colours = FALSE) +#' +#' +#' # it also supports groups (don't forget to use the group var on `x` or `facet`): +#' example_isolates %>% +#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>% +#' group_by(hospital_id) %>% +#' ggplot_rsi(x = "hospital_id", +#' facet = "antibiotic", +#' nrow = 1, +#' title = "AMR of Anti-UTI Drugs Per Hospital", +#' x.title = "Hospital", +#' datalabels = FALSE) #' } -#' -#' # resistance of ciprofloxacine per age group -#' example_isolates %>% -#' mutate(first_isolate = first_isolate(.)) %>% -#' filter(first_isolate == TRUE, -#' mo == as.mo("E. coli")) %>% -#' # age_groups() is also a function in this AMR package: -#' group_by(age_group = age_groups(age)) %>% -#' select(age_group, -#' CIP) %>% -#' ggplot_rsi(x = "age_group") -#' -#' # a shorter version which also adjusts data label colours: -#' example_isolates %>% -#' select(AMX, NIT, FOS, TMP, CIP) %>% -#' ggplot_rsi(colours = FALSE) -#' -#' -#' # it also supports groups (don't forget to use the group var on `x` or `facet`): -#' example_isolates %>% -#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>% -#' group_by(hospital_id) %>% -#' ggplot_rsi(x = "hospital_id", -#' facet = "antibiotic", -#' nrow = 1, -#' title = "AMR of Anti-UTI Drugs Per Hospital", -#' x.title = "Hospital", -#' datalabels = FALSE) #' } ggplot_rsi <- function(data, position = NULL, diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index d155cdc3..f769346f 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/docs/404.html b/docs/404.html index 96109e99..287410c4 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 7161b151..a6bcb473 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html index 14fb93f4..9818eee8 100644 --- a/docs/articles/datasets.html +++ b/docs/articles/datasets.html @@ -39,7 +39,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/articles/index.html b/docs/articles/index.html index b4f0d5b1..56ba07bf 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/authors.html b/docs/authors.html index b2bf94df..9899ed21 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/index.html b/docs/index.html index 84867edc..9bfe1b75 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/news/index.html b/docs/news/index.html index a6a600b3..7a1295c6 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

- Unreleased AMR 1.6.0.9064

+
+

+ Unreleased AMR 1.6.0.9065

Last updated: 24 May 2021 @@ -288,7 +288,7 @@
  • Function betalactams() as additional antbiotic column selector and function filter_betalactams() as additional antbiotic column filter. The group of betalactams consists of all carbapenems, cephalosporins and penicillins.
  • -
  • A ggplot() method for resistance_predict() +
  • A ggplot() method for resistance_predict()
  • @@ -387,7 +387,7 @@ #> Filtering on oxazolidinones: value in column `LNZ` (linezolid) is either "R", "S" or "I"
  • Support for custom MDRO guidelines, using the new custom_mdro_guideline() function, please see mdro() for additional info

  • -
  • ggplot() generics for classes <mic> and <disk>

  • +
  • ggplot() generics for classes <mic> and <disk>

  • Function mo_is_yeast(), which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales:

    @@ -444,7 +444,7 @@
     
  • Plotting of MIC and disk diffusion values now support interpretation colouring if you supply the microorganism and antimicrobial agent
  • All colours were updated to colour-blind friendly versions for values R, S and I for all plot methods (also applies to tibble printing)
  • Interpretation of MIC and disk diffusion values to R/SI will now be translated if the system language is German, Dutch or Spanish (see translate)
  • -
  • Plotting is now possible with base R using plot() and with ggplot2 using ggplot() on any vector of MIC and disk diffusion values
  • +
  • Plotting is now possible with base R using plot() and with ggplot2 using ggplot() on any vector of MIC and disk diffusion values
  • Updated SNOMED codes to US Edition of SNOMED CT from 1 September 2020 and added the source to the help page of the microorganisms data set
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 9a7f96cd..b25a43cc 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-05-24T07:33Z +last_built: 2021-05-24T09:00Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index a353ee1e..7ae757af 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -82,7 +82,7 @@ AMR (for R) - 1.6.0.9063 + 1.6.0.9065
    @@ -477,35 +477,35 @@ The lifecycle of this function is stableggplot() + geom_col(aes(x = x, y = y, fill = z)) + scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R") + + # resistance of ciprofloxacine per age group + example_isolates %>% + mutate(first_isolate = first_isolate()) %>% + filter(first_isolate == TRUE, + mo == as.mo("E. coli")) %>% + # age_groups() is also a function in this AMR package: + group_by(age_group = age_groups(age)) %>% + select(age_group, + CIP) %>% + ggplot_rsi(x = "age_group") + + # a shorter version which also adjusts data label colours: + example_isolates %>% + select(AMX, NIT, FOS, TMP, CIP) %>% + ggplot_rsi(colours = FALSE) + + + # it also supports groups (don't forget to use the group var on `x` or `facet`): + example_isolates %>% + select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>% + group_by(hospital_id) %>% + ggplot_rsi(x = "hospital_id", + facet = "antibiotic", + nrow = 1, + title = "AMR of Anti-UTI Drugs Per Hospital", + x.title = "Hospital", + datalabels = FALSE) } - -# resistance of ciprofloxacine per age group -example_isolates %>% - mutate(first_isolate = first_isolate(.)) %>% - filter(first_isolate == TRUE, - mo == as.mo("E. coli")) %>% - # age_groups() is also a function in this AMR package: - group_by(age_group = age_groups(age)) %>% - select(age_group, - CIP) %>% - ggplot_rsi(x = "age_group") - -# a shorter version which also adjusts data label colours: -example_isolates %>% - select(AMX, NIT, FOS, TMP, CIP) %>% - ggplot_rsi(colours = FALSE) - - -# it also supports groups (don't forget to use the group var on `x` or `facet`): -example_isolates %>% - select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>% - group_by(hospital_id) %>% - ggplot_rsi(x = "hospital_id", - facet = "antibiotic", - nrow = 1, - title = "AMR of Anti-UTI Drugs Per Hospital", - x.title = "Hospital", - datalabels = FALSE) # } diff --git a/docs/reference/index.html b/docs/reference/index.html index be2ec9af..70c4f41c 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/docs/survey.html b/docs/survey.html index 1b504005..5da36e7d 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9064 + 1.6.0.9065 diff --git a/inst/tinytest/test-_misc.R b/inst/tinytest/test-_misc.R index c9ae8afb..3d0bd421 100755 --- a/inst/tinytest/test-_misc.R +++ b/inst/tinytest/test-_misc.R @@ -22,34 +22,32 @@ # 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(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 +# round up 0.5 expect_equal(AMR:::percentage(0.0054), "0.5%") expect_equal(AMR:::percentage(0.0055), "0.6%") - + 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(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 (AMR:::pkg_is_available("dplyr")) { + +if (AMR:::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 (AMR:::pkg_is_available("dplyr")) { - expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id))) - } +} - +# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this: +if (AMR:::pkg_is_available("dplyr")) { + expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id))) +} diff --git a/inst/tinytest/test-count.R b/inst/tinytest/test-count.R index 73e1d68a..b39f3d7f 100644 --- a/inst/tinytest/test-count.R +++ b/inst/tinytest/test-count.R @@ -36,11 +36,9 @@ expect_equal(count_R(example_isolates$AMX) + count_I(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 -AMR:::reset_all_thrown_messages() expect_warning(count_resistant(as.character(example_isolates$AMC))) -AMR:::reset_all_thrown_messages() + expect_warning(count_resistant(example_isolates$AMC, as.character(example_isolates$GEN))) diff --git a/inst/tinytest/test-eucast_rules.R b/inst/tinytest/test-eucast_rules.R index b51a2df0..b2e0d607 100755 --- a/inst/tinytest/test-eucast_rules.R +++ b/inst/tinytest/test-eucast_rules.R @@ -45,6 +45,7 @@ expect_warning(eucast_rules(data.frame(mo = "Escherichia coli", vancomycin = "S" expect_identical(colnames(example_isolates), colnames(suppressWarnings(eucast_rules(example_isolates, info = FALSE)))) + expect_stdout(suppressMessages(eucast_rules(example_isolates, info = TRUE))) a <- data.frame(mo = c("Klebsiella pneumoniae", @@ -84,7 +85,7 @@ if (AMR:::pkg_is_available("dplyr")) { "R") } -# Azithromycin and Clarythromycin must be equal to Erythromycin +# azithromycin and clarythromycin must be equal to Erythromycin a <- suppressWarnings(as.rsi(eucast_rules(data.frame(mo = example_isolates$mo, ERY = example_isolates$ERY, AZM = as.rsi("R"), @@ -117,18 +118,21 @@ if (AMR:::pkg_is_available("dplyr")) { expect_stdout(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, rules = "all", info = TRUE))) # AmpC de-repressed cephalo mutants + expect_identical( eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"), cefotax = as.rsi(c("S", "S"))), ampc_cephalosporin_resistance = TRUE, info = FALSE)$cefotax, as.rsi(c("S", "R"))) + expect_identical( eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"), cefotax = as.rsi(c("S", "S"))), ampc_cephalosporin_resistance = NA, info = FALSE)$cefotax, as.rsi(c("S", NA))) + expect_identical( eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"), cefotax = as.rsi(c("S", "S"))), diff --git a/inst/tinytest/test-proportion.R b/inst/tinytest/test-proportion.R index 30c8baa6..d27691e5 100755 --- a/inst/tinytest/test-proportion.R +++ b/inst/tinytest/test-proportion.R @@ -88,14 +88,12 @@ if (AMR:::pkg_is_available("dplyr")) { example_isolates$AMX %>% proportion_R()) ) } -AMR:::reset_all_thrown_messages() + expect_warning(proportion_R(as.character(example_isolates$AMC))) -AMR:::reset_all_thrown_messages() expect_warning(proportion_S(as.character(example_isolates$AMC))) -AMR:::reset_all_thrown_messages() expect_warning(proportion_S(as.character(example_isolates$AMC, example_isolates$GEN))) -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 +118,8 @@ expect_identical(suppressWarnings(proportion_S(example_isolates$AMX, minimum = n NA_real_) # warning for speed loss -AMR:::reset_all_thrown_messages() expect_warning(proportion_R(as.character(example_isolates$GEN))) -AMR:::reset_all_thrown_messages() expect_warning(proportion_I(as.character(example_isolates$GEN))) -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"])) diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index cfb1356b..629d95e4 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -202,34 +202,34 @@ if (require("ggplot2") & require("dplyr")) { ggplot() + geom_col(aes(x = x, y = y, fill = z)) + scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R") -} -# resistance of ciprofloxacine per age group -example_isolates \%>\% - mutate(first_isolate = first_isolate(.)) \%>\% - filter(first_isolate == TRUE, - mo == as.mo("E. coli")) \%>\% - # age_groups() is also a function in this AMR package: - group_by(age_group = age_groups(age)) \%>\% - select(age_group, - CIP) \%>\% - ggplot_rsi(x = "age_group") + # resistance of ciprofloxacine per age group + example_isolates \%>\% + mutate(first_isolate = first_isolate()) \%>\% + filter(first_isolate == TRUE, + mo == as.mo("E. coli")) \%>\% + # age_groups() is also a function in this AMR package: + group_by(age_group = age_groups(age)) \%>\% + select(age_group, + CIP) \%>\% + ggplot_rsi(x = "age_group") -# a shorter version which also adjusts data label colours: -example_isolates \%>\% - select(AMX, NIT, FOS, TMP, CIP) \%>\% - ggplot_rsi(colours = FALSE) + # a shorter version which also adjusts data label colours: + example_isolates \%>\% + select(AMX, NIT, FOS, TMP, CIP) \%>\% + ggplot_rsi(colours = FALSE) -# it also supports groups (don't forget to use the group var on `x` or `facet`): -example_isolates \%>\% - select(hospital_id, AMX, NIT, FOS, TMP, CIP) \%>\% - group_by(hospital_id) \%>\% - ggplot_rsi(x = "hospital_id", - facet = "antibiotic", - nrow = 1, - title = "AMR of Anti-UTI Drugs Per Hospital", - x.title = "Hospital", - datalabels = FALSE) + # it also supports groups (don't forget to use the group var on `x` or `facet`): + example_isolates \%>\% + select(hospital_id, AMX, NIT, FOS, TMP, CIP) \%>\% + group_by(hospital_id) \%>\% + ggplot_rsi(x = "hospital_id", + facet = "antibiotic", + nrow = 1, + title = "AMR of Anti-UTI Drugs Per Hospital", + x.title = "Hospital", + datalabels = FALSE) +} } }