From 835cf7c32d978e3791589254339cf08552a33136 Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Sun, 18 Sep 2022 14:00:29 +0200 Subject: [PATCH] fixes --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/aa_helper_functions.R | 4 ---- inst/tinytest/test-_misc.R | 11 ++++++----- inst/tinytest/test-eucast_rules.R | 2 +- tests/tinytest.R | 9 +++++++++ 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 582660a77..7cc70be3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.1.9052 +Version: 1.8.1.9055 Date: 2022-09-18 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 3b92a2851..8ae49a755 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.1.9052 +# AMR 1.8.1.9055 This version will eventually become v2.0! We're happy to reach a new major milestone soon! diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 7aed7d40a..96753438e 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -1489,8 +1489,4 @@ if (getRversion() < "4.0.0") { } } -# for tinytest unit tests, that call AMR:::xxx(): -strrep <- strrep - - # nolint end diff --git a/inst/tinytest/test-_misc.R b/inst/tinytest/test-_misc.R index ff5115893..03e1b85e1 100755 --- a/inst/tinytest/test-_misc.R +++ b/inst/tinytest/test-_misc.R @@ -31,11 +31,12 @@ expect_equal(AMR:::percentage(0.1234), "12.3%") 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") +# test functions on all R versions - R < 3.3 did not contain these +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(AMR:::generate_warning_abs_missing(c("AMP", "AMX"))) expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE)) diff --git a/inst/tinytest/test-eucast_rules.R b/inst/tinytest/test-eucast_rules.R index 36692152b..a0c4de339 100755 --- a/inst/tinytest/test-eucast_rules.R +++ b/inst/tinytest/test-eucast_rules.R @@ -36,7 +36,7 @@ expect_equal( ) ) MOs_mentioned <- unique(AMR:::EUCAST_RULES_DF$this_value) -MOs_mentioned <- sort(AMR:::trimws(unlist(strsplit(MOs_mentioned[!AMR:::is_valid_regex(MOs_mentioned)], ",", fixed = TRUE)))) +MOs_mentioned <- sort(trimws(unlist(strsplit(MOs_mentioned[!AMR:::is_valid_regex(MOs_mentioned)], ",", fixed = TRUE)))) MOs_test <- suppressWarnings(suppressMessages(mo_name(MOs_mentioned))) expect_true(length(MOs_mentioned[MOs_test != MOs_mentioned]) == 0) diff --git a/tests/tinytest.R b/tests/tinytest.R index fed6c0e18..27c122a96 100644 --- a/tests/tinytest.R +++ b/tests/tinytest.R @@ -23,13 +23,22 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # +# we use {tinytest} instead of {testthat} because it does not rely on recent R versions - we want to test on R >= 3.0. + # test only on GitHub Actions and at home - not on CRAN as tests are lengthy if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) { # env var 'R_LIBS_USER' got overwritten during 'R CMD check' in GitHub Actions, so: .libPaths(c(Sys.getenv("R_LIBS_USER_GH_ACTIONS"), .libPaths())) if (AMR:::pkg_is_available("tinytest", also_load = TRUE)) { library(AMR) + # set language set_AMR_locale("English") + # get trimws() and strrep() if on old R + if (getRversion() < "3.3.0") { + trimws <- AMR:::trimws + strrep <- AMR:::strrep + } + # start the unit tests out <- test_package("AMR", testdir = ifelse(dir.exists("inst/tinytest"), "inst/tinytest",