diff --git a/.github/workflows/check-pr.yaml b/.github/workflows/check-pr.yaml index 0a51be69..f91b8bca 100644 --- a/.github/workflows/check-pr.yaml +++ b/.github/workflows/check-pr.yaml @@ -32,6 +32,9 @@ name: R-code-check-PR jobs: R-code-check-PR: + # do not run if we are the authors - the other checks will already run + if: ${{ github.event.comment.author_association != 'MEMBER' && github.event.comment.author_association != 'OWNER' }} + runs-on: ${{ matrix.config.os }} continue-on-error: ${{ matrix.config.allowfail }} diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 56f463fc..bec95ebd 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -131,6 +131,7 @@ jobs: _R_CHECK_LENGTH_1_LOGIC2_: verbose # during 'R CMD check', R_LIBS_USER will be overwritten, so: R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }} + # this is a required value to run the unit tests: R_RUN_TINYTEST: true run: | cd .. diff --git a/.github/workflows/codecovr.yaml b/.github/workflows/codecovr.yaml index cf935069..b0bafc5a 100644 --- a/.github/workflows/codecovr.yaml +++ b/.github/workflows/codecovr.yaml @@ -33,54 +33,30 @@ name: code-coverage jobs: code-coverage: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} steps: - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r@v2 with: r-version: release - - - uses: r-lib/actions/setup-pandoc@v2 - # with: - # pandoc-version: '2.7.3' # The pandoc version to download (if necessary) and use. + # use RStudio Package Manager to quickly install packages + use-public-rspm: true - - name: Query dependencies - # this will change once a week, so it will cache dependency updates - run: | - writeLines(paste(format(Sys.Date(), "week %V %Y"), sprintf("R-%i.%i", getRversion()$major, getRversion()$minor)), ".github/week-R-version") - shell: Rscript {0} - - - name: Restore cached R packages - # this step will add the step 'Post Restore cached R packages' on a succesful run - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ matrix.config.os }}-${{ hashFiles('.github/week-R-version') }}-v4 - - - name: Unpack AMR and install R dependencies - run: | - tar -xf data-raw/AMR_latest.tar.gz - Rscript -e "source('data-raw/_install_deps.R')" - shell: bash - - - name: Show session info - run: | - options(width = 100) - utils::sessionInfo() - as.data.frame(utils::installed.packages())[, "Version", drop = FALSE] - shell: Rscript {0} + extra-packages: any::covr - name: Test coverage env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }} R_RUN_TINYTEST: true run: | - install.packages("covr", repos = "https://cran.rstudio.com/") - library(AMR) - library(tinytest) x <- covr::codecov(line_exclusions = list("R/atc_online.R", "R/mo_source.R", "R/translate.R", "R/resistance_predict.R", "R/aa_helper_functions.R", "R/aa_helper_pm_functions.R", "R/zzz.R")) print(x) shell: Rscript {0} diff --git a/.github/workflows/lintr.yaml b/.github/workflows/lintr.yaml index 8f302eed..fecc0d56 100644 --- a/.github/workflows/lintr.yaml +++ b/.github/workflows/lintr.yaml @@ -33,34 +33,23 @@ name: lintr jobs: lintr: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r@v2 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + r-version: release + # use RStudio Package Manager to quickly install packages + use-public-rspm: true - - name: Install dependencies - run: | - install.packages(c("remotes")) - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("lintr") - shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr - name: Lint run: lintr::lint_package(linters = lintr::with_defaults(line_length_linter = NULL, trailing_whitespace_linter = NULL, object_name_linter = NULL, cyclocomp_linter = NULL, object_length_linter = lintr::object_length_linter(length = 50L)), exclusions = list("R/aa_helper_pm_functions.R")) diff --git a/DESCRIPTION b/DESCRIPTION index dc3381d1..527ce06f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.1.9034 +Version: 1.8.1.9039 Date: 2022-08-28 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) @@ -42,7 +42,7 @@ Suggests: rvest, tinytest, xml2 -VignetteBuilder: knitr +VignetteBuilder: knitr,rmarkdown URL: https://msberends.github.io/AMR/, https://github.com/msberends/AMR BugReports: https://github.com/msberends/AMR/issues License: GPL-2 | file LICENSE diff --git a/NEWS.md b/NEWS.md index 9050d52d..55ee8c17 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.1.9034 +# AMR 1.8.1.9039 ### New * EUCAST 2022 and CLSI 2022 guidelines have been added for `as.rsi()`. EUCAST 2022 is now the new default guideline for all MIC and disks diffusion interpretations. diff --git a/R/first_isolate.R b/R/first_isolate.R index 869e9fb9..e0eb7615 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -529,7 +529,7 @@ first_isolate <- function(x = NULL, } if (!is.null(col_icu)) { if (icu_exclude == TRUE) { - message_("Excluding ", format(sum(!col_icu, na.rm = TRUE), big.mark = ","), " isolates from ICU.", + message_("Excluding ", format(sum(col_icu, na.rm = TRUE), big.mark = ","), " isolates from ICU.", add_fn = font_black, as_note = FALSE ) diff --git a/R/mo.R b/R/mo.R index 952d0dd0..968a8f23 100755 --- a/R/mo.R +++ b/R/mo.R @@ -204,12 +204,12 @@ as.mo <- function(x, )) } + reference_df <- repair_reference_df(reference_df) if (!is.null(reference_df) && check_validity_mo_source(reference_df) && isFALSE(Becker) && isFALSE(Lancefield) && - all(x %in% unlist(reference_df), na.rm = TRUE)) { - reference_df <- repair_reference_df(reference_df) + all(x %in% reference_df[, 1, drop = TRUE], na.rm = TRUE)) { suppressWarnings( y <- data.frame(x = x, stringsAsFactors = FALSE) %pm>% pm_left_join(reference_df, by = "x") %pm>% @@ -221,6 +221,7 @@ as.mo <- function(x, y <- x } else { # will be checked for mo class in validation and uses exec_as.mo internally if necessary + y <- mo_validate( x = x, property = "mo", Becker = Becker, Lancefield = Lancefield, @@ -420,7 +421,7 @@ exec_as.mo <- function(x, } # all empty - if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0)) { + if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0, na.rm = TRUE)) { if (property == "mo") { return(set_clean_class(rep(NA_character_, length(x_input)), new_class = c("mo", "character") @@ -428,7 +429,7 @@ exec_as.mo <- function(x, } else { return(rep(NA_character_, length(x_input))) } - } else if (all(x %in% reference_df[, 1, drop = TRUE][[1]])) { + } else if (all(x %in% reference_df[, 1, drop = TRUE], na.rm = TRUE)) { # all in reference df colnames(reference_df)[1] <- "x" suppressWarnings( @@ -2357,6 +2358,9 @@ replace_ignore_pattern <- function(x, ignore_pattern) { } repair_reference_df <- function(reference_df) { + if (is.null(reference_df)) { + return(NULL) + } # has valid own reference_df reference_df <- reference_df %pm>% pm_filter(!is.na(mo)) diff --git a/data-raw/_install_deps.R b/data-raw/_install_deps.R index f22b7aea..d0529fd9 100644 --- a/data-raw/_install_deps.R +++ b/data-raw/_install_deps.R @@ -26,7 +26,6 @@ # some old R instances have trouble installing tinytest, so we ship it too install.packages("data-raw/tinytest_1.3.1.tar.gz", dependencies = c("Depends", "Imports", "LinkingTo")) install.packages(getwd(), repos = NULL, type = "source") -# install.packages("data-raw/AMR_latest.tar.gz", dependencies = FALSE) pkg_suggests <- gsub( "[^a-zA-Z0-9]+", "", diff --git a/data-raw/_pre_commit_hook.R b/data-raw/_pre_commit_hook.R index e744e285..0eea76f5 100644 --- a/data-raw/_pre_commit_hook.R +++ b/data-raw/_pre_commit_hook.R @@ -475,6 +475,11 @@ rm(current_globalenv) devtools::load_all(quiet = TRUE) +# Update URLs ------------------------------------------------------------- +usethis::ui_info("Checking URLs for redirects") +invisible(capture.output(urlchecker::url_update())) + + # Document pkg ------------------------------------------------------------ usethis::ui_info("Documenting package") suppressMessages(devtools::document(quiet = TRUE)) diff --git a/data-raw/microorganisms.old.dta b/data-raw/microorganisms.old.dta index 4e7a7358..552c99a2 100644 Binary files a/data-raw/microorganisms.old.dta and b/data-raw/microorganisms.old.dta differ diff --git a/data-raw/microorganisms.old.feather b/data-raw/microorganisms.old.feather index 6dd4d740..a1a12688 100644 Binary files a/data-raw/microorganisms.old.feather and b/data-raw/microorganisms.old.feather differ diff --git a/data-raw/microorganisms.old.md5 b/data-raw/microorganisms.old.md5 index ce38bc35..ad0f168b 100644 --- a/data-raw/microorganisms.old.md5 +++ b/data-raw/microorganisms.old.md5 @@ -1 +1 @@ -19af89838b60bc8549d4474609629e8d +b57c9cc7380a233a2616a80e8e904a81 diff --git a/data-raw/microorganisms.old.parquet b/data-raw/microorganisms.old.parquet index 2abfbd2c..b8234690 100644 Binary files a/data-raw/microorganisms.old.parquet and b/data-raw/microorganisms.old.parquet differ diff --git a/data-raw/microorganisms.old.rds b/data-raw/microorganisms.old.rds index 3c562450..5d01dc50 100644 Binary files a/data-raw/microorganisms.old.rds and b/data-raw/microorganisms.old.rds differ diff --git a/data-raw/microorganisms.old.sas b/data-raw/microorganisms.old.sas index 5d9891bb..ee9632b7 100644 Binary files a/data-raw/microorganisms.old.sas and b/data-raw/microorganisms.old.sas differ diff --git a/data-raw/microorganisms.old.sav b/data-raw/microorganisms.old.sav index fd371edf..06658306 100644 Binary files a/data-raw/microorganisms.old.sav and b/data-raw/microorganisms.old.sav differ diff --git a/data-raw/microorganisms.old.xlsx b/data-raw/microorganisms.old.xlsx index 7e954067..ed658de3 100644 Binary files a/data-raw/microorganisms.old.xlsx and b/data-raw/microorganisms.old.xlsx differ diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index a970048f..c9382018 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/data/microorganisms.old.rda b/data/microorganisms.old.rda index d3a1c6c8..a42d6023 100644 Binary files a/data/microorganisms.old.rda and b/data/microorganisms.old.rda differ diff --git a/inst/tinytest/test-_misc.R b/inst/tinytest/test-_misc.R index 6871292c..ff511589 100755 --- a/inst/tinytest/test-_misc.R +++ b/inst/tinytest/test-_misc.R @@ -47,7 +47,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { 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: +# we rely on "grouped_tbl" being a class of grouped tibbles, so run a test that checks for this: if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward))) } diff --git a/inst/tinytest/test-ab_property.R b/inst/tinytest/test-ab_property.R index b80e4db2..4ce82eeb 100644 --- a/inst/tinytest/test-ab_property.R +++ b/inst/tinytest/test-ab_property.R @@ -68,15 +68,15 @@ expect_true(ab_url("AMX") %like% "whocc.no") expect_warning(ab_url("ASP")) expect_identical( - colnames(set_ab_names(example_isolates[, 20:25])), + colnames(set_ab_names(example_isolates[, 17:22])), c("cefoxitin", "cefotaxime", "ceftazidime", "ceftriaxone", "gentamicin", "tobramycin") ) expect_identical( - colnames(set_ab_names(example_isolates[, 20:25], language = "nl", snake_case = FALSE)), + colnames(set_ab_names(example_isolates[, 17:22], language = "nl", snake_case = FALSE)), c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine") ) expect_identical( - colnames(set_ab_names(example_isolates[, 20:25], property = "atc")), + colnames(set_ab_names(example_isolates[, 17:22], property = "atc")), c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01") ) diff --git a/inst/tinytest/test-count.R b/inst/tinytest/test-count.R index 262018bf..ac64d773 100644 --- a/inst/tinytest/test-count.R +++ b/inst/tinytest/test-count.R @@ -79,7 +79,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { combination = count_susceptible(CIP, GEN) ) %>% pull(combination), - c(253, 465, 192, 558) + c(946, 428, 94) ) # count_df diff --git a/inst/tinytest/test-data.R b/inst/tinytest/test-data.R index 4086f6d2..22e2b003 100644 --- a/inst/tinytest/test-data.R +++ b/inst/tinytest/test-data.R @@ -57,7 +57,6 @@ expect_identical(as.ab(antibiotics$name), antibiotics$ab) datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE] for (i in seq_len(length(datasets))) { dataset <- get(datasets[i], envir = asNamespace("AMR")) - expect_identical(class(dataset), "data.frame") expect_identical(AMR:::dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i]) } diff --git a/inst/tinytest/test-first_isolate.R b/inst/tinytest/test-first_isolate.R index 2ec4fe53..ceb0d86a 100755 --- a/inst/tinytest/test-first_isolate.R +++ b/inst/tinytest/test-first_isolate.R @@ -75,7 +75,7 @@ expect_equal( ), na.rm = TRUE ), - 941 + 942 ) # set 1500 random observations to be of specimen type 'Urine' @@ -160,7 +160,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { # support for WHONET expect_message(example_isolates %>% - select(-patient_id) %>% + select(-patient) %>% mutate( `First name` = "test", `Last name` = "test", diff --git a/inst/tinytest/test-proportion.R b/inst/tinytest/test-proportion.R index bfaab47a..79e6683f 100755 --- a/inst/tinytest/test-proportion.R +++ b/inst/tinytest/test-proportion.R @@ -84,7 +84,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { combination_n = n_rsi(CIP, GEN) ) %>% pull(combination_n), - c(305, 617, 241, 711) + c(1181, 577, 116) ) # proportion_df diff --git a/tests/tinytest.R b/tests/tinytest.R index 2753f082..b54662b4 100644 --- a/tests/tinytest.R +++ b/tests/tinytest.R @@ -27,8 +27,9 @@ 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")) { + if (AMR:::pkg_is_available("tinytest", also_load = TRUE)) { library(AMR) + set_AMR_locale("English") out <- test_package("AMR", testdir = ifelse(AMR:::dir.exists("inst/tinytest"), "inst/tinytest", @@ -37,7 +38,7 @@ if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) { verbose = 99, color = FALSE ) - cat("SUMMARY:\n") + cat("\n\nSUMMARY:\n") print(summary(out)) } }