2 Commits
Author SHA1 Message Date
dr. M.S. (Matthijs) Berends c44ddf272f fix for R <= 3.3 2022-08-28 19:34:04 +02:00
dr. M.S. (Matthijs) Berends 71db246d5c unit test fix 2022-08-28 19:17:12 +02:00
28 changed files with 62 additions and 80 deletions
+3
View File
@@ -32,6 +32,9 @@ name: R-code-check-PR
jobs: jobs:
R-code-check-PR: 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 }} runs-on: ${{ matrix.config.os }}
continue-on-error: ${{ matrix.config.allowfail }} continue-on-error: ${{ matrix.config.allowfail }}
+4
View File
@@ -131,9 +131,11 @@ jobs:
_R_CHECK_LENGTH_1_LOGIC2_: verbose _R_CHECK_LENGTH_1_LOGIC2_: verbose
# during 'R CMD check', R_LIBS_USER will be overwritten, so: # during 'R CMD check', R_LIBS_USER will be overwritten, so:
R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }} R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }}
# this is a required value to run the unit tests:
R_RUN_TINYTEST: true R_RUN_TINYTEST: true
run: | run: |
cd .. cd ..
ls -lh
R CMD build AMR R CMD build AMR
R CMD check --no-manual --run-donttest --run-dontrun AMR_*.tar.gz R CMD check --no-manual --run-donttest --run-dontrun AMR_*.tar.gz
shell: bash shell: bash
@@ -141,6 +143,8 @@ jobs:
- name: Show unit tests output - name: Show unit tests output
if: always() if: always()
run: | run: |
ls -lh
cd AMR
find . -name 'tinytest.Rout*' -exec cat '{}' \; || true find . -name 'tinytest.Rout*' -exec cat '{}' \; || true
shell: bash shell: bash
+9 -33
View File
@@ -33,54 +33,30 @@ name: code-coverage
jobs: jobs:
code-coverage: code-coverage:
runs-on: macOS-latest runs-on: ubuntu-latest
env: env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2 - uses: r-lib/actions/setup-r@v2
with: with:
r-version: release r-version: release
# use RStudio Package Manager to quickly install packages
use-public-rspm: true
- uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r-dependencies@v2
# with:
# pandoc-version: '2.7.3' # The pandoc version to download (if necessary) and use.
- 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
with: with:
path: ${{ env.R_LIBS_USER }} extra-packages: any::covr
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}
- name: Test coverage - name: Test coverage
env: env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }}
R_RUN_TINYTEST: true R_RUN_TINYTEST: true
run: | 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")) 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) print(x)
shell: Rscript {0} shell: Rscript {0}
+9 -20
View File
@@ -33,34 +33,23 @@ name: lintr
jobs: jobs:
lintr: lintr:
runs-on: macOS-latest runs-on: ubuntu-latest
env: env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@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: with:
path: ${{ env.R_LIBS_USER }} r-version: release
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} # use RStudio Package Manager to quickly install packages
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- use-public-rspm: true
- name: Install dependencies - uses: r-lib/actions/setup-r-dependencies@v2
run: | with:
install.packages(c("remotes")) extra-packages: any::lintr
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("lintr")
shell: Rscript {0}
- name: Lint - 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")) 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"))
+2 -2
View File
@@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 1.8.1.9034 Version: 1.8.1.9040
Date: 2022-08-28 Date: 2022-08-28
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
@@ -42,7 +42,7 @@ Suggests:
rvest, rvest,
tinytest, tinytest,
xml2 xml2
VignetteBuilder: knitr VignetteBuilder: knitr,rmarkdown
URL: https://msberends.github.io/AMR/, https://github.com/msberends/AMR URL: https://msberends.github.io/AMR/, https://github.com/msberends/AMR
BugReports: https://github.com/msberends/AMR/issues BugReports: https://github.com/msberends/AMR/issues
License: GPL-2 | file LICENSE License: GPL-2 | file LICENSE
+1 -1
View File
@@ -1,4 +1,4 @@
# AMR 1.8.1.9034 # AMR 1.8.1.9040
### New ### 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. * 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.
+1 -1
View File
@@ -651,7 +651,7 @@ dataset_UTF8_to_ASCII <- function(df) {
df[, i] <- col df[, i] <- col
} }
} }
tibble::as_tibble(df) import_fn("as_tibble", "tibble")(df)
} }
# for eucast_rules() and mdro(), creates markdown output with URLs and names # for eucast_rules() and mdro(), creates markdown output with URLs and names
+1 -1
View File
@@ -529,7 +529,7 @@ first_isolate <- function(x = NULL,
} }
if (!is.null(col_icu)) { if (!is.null(col_icu)) {
if (icu_exclude == TRUE) { 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, add_fn = font_black,
as_note = FALSE as_note = FALSE
) )
+8 -4
View File
@@ -204,12 +204,12 @@ as.mo <- function(x,
)) ))
} }
reference_df <- repair_reference_df(reference_df)
if (!is.null(reference_df) && if (!is.null(reference_df) &&
check_validity_mo_source(reference_df) && check_validity_mo_source(reference_df) &&
isFALSE(Becker) && isFALSE(Becker) &&
isFALSE(Lancefield) && isFALSE(Lancefield) &&
all(x %in% unlist(reference_df), na.rm = TRUE)) { all(x %in% reference_df[, 1, drop = TRUE], na.rm = TRUE)) {
reference_df <- repair_reference_df(reference_df)
suppressWarnings( suppressWarnings(
y <- data.frame(x = x, stringsAsFactors = FALSE) %pm>% y <- data.frame(x = x, stringsAsFactors = FALSE) %pm>%
pm_left_join(reference_df, by = "x") %pm>% pm_left_join(reference_df, by = "x") %pm>%
@@ -221,6 +221,7 @@ as.mo <- function(x,
y <- x y <- x
} else { } else {
# will be checked for mo class in validation and uses exec_as.mo internally if necessary # will be checked for mo class in validation and uses exec_as.mo internally if necessary
y <- mo_validate( y <- mo_validate(
x = x, property = "mo", x = x, property = "mo",
Becker = Becker, Lancefield = Lancefield, Becker = Becker, Lancefield = Lancefield,
@@ -420,7 +421,7 @@ exec_as.mo <- function(x,
} }
# all empty # 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") { if (property == "mo") {
return(set_clean_class(rep(NA_character_, length(x_input)), return(set_clean_class(rep(NA_character_, length(x_input)),
new_class = c("mo", "character") new_class = c("mo", "character")
@@ -428,7 +429,7 @@ exec_as.mo <- function(x,
} else { } else {
return(rep(NA_character_, length(x_input))) 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 # all in reference df
colnames(reference_df)[1] <- "x" colnames(reference_df)[1] <- "x"
suppressWarnings( suppressWarnings(
@@ -2357,6 +2358,9 @@ replace_ignore_pattern <- function(x, ignore_pattern) {
} }
repair_reference_df <- function(reference_df) { repair_reference_df <- function(reference_df) {
if (is.null(reference_df)) {
return(NULL)
}
# has valid own reference_df # has valid own reference_df
reference_df <- reference_df %pm>% reference_df <- reference_df %pm>%
pm_filter(!is.na(mo)) pm_filter(!is.na(mo))
-1
View File
@@ -26,7 +26,6 @@
# some old R instances have trouble installing tinytest, so we ship it too # 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("data-raw/tinytest_1.3.1.tar.gz", dependencies = c("Depends", "Imports", "LinkingTo"))
install.packages(getwd(), repos = NULL, type = "source") install.packages(getwd(), repos = NULL, type = "source")
# install.packages("data-raw/AMR_latest.tar.gz", dependencies = FALSE)
pkg_suggests <- gsub( pkg_suggests <- gsub(
"[^a-zA-Z0-9]+", "", "[^a-zA-Z0-9]+", "",
+5
View File
@@ -475,6 +475,11 @@ rm(current_globalenv)
devtools::load_all(quiet = TRUE) devtools::load_all(quiet = TRUE)
# Update URLs -------------------------------------------------------------
usethis::ui_info("Checking URLs for redirects")
invisible(capture.output(urlchecker::url_update()))
# Document pkg ------------------------------------------------------------ # Document pkg ------------------------------------------------------------
usethis::ui_info("Documenting package") usethis::ui_info("Documenting package")
suppressMessages(devtools::document(quiet = TRUE)) suppressMessages(devtools::document(quiet = TRUE))
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
19af89838b60bc8549d4474609629e8d b57c9cc7380a233a2616a80e8e904a81
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -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)) 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")) { if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward))) expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward)))
} }
+3 -3
View File
@@ -68,15 +68,15 @@ expect_true(ab_url("AMX") %like% "whocc.no")
expect_warning(ab_url("ASP")) expect_warning(ab_url("ASP"))
expect_identical( 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") c("cefoxitin", "cefotaxime", "ceftazidime", "ceftriaxone", "gentamicin", "tobramycin")
) )
expect_identical( 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") c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine")
) )
expect_identical( 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") c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")
) )
+1 -1
View File
@@ -79,7 +79,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
combination = count_susceptible(CIP, GEN) combination = count_susceptible(CIP, GEN)
) %>% ) %>%
pull(combination), pull(combination),
c(253, 465, 192, 558) c(946, 428, 94)
) )
# count_df # count_df
+5 -4
View File
@@ -53,12 +53,13 @@ expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "
# antibiotic names must always be coercible to their original AB code # antibiotic names must always be coercible to their original AB code
expect_identical(as.ab(antibiotics$name), antibiotics$ab) expect_identical(as.ab(antibiotics$name), antibiotics$ab)
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy) if (AMR:::pkg_is_available("tibble", also_load = FALSE)) {
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item", drop = TRUE] # there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
for (i in seq_len(length(datasets))) { 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")) 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]) expect_identical(AMR:::dataset_UTF8_to_ASCII(dataset), dataset, info = datasets[i])
}
} }
df <- AMR:::MO_lookup df <- AMR:::MO_lookup
+2 -2
View File
@@ -75,7 +75,7 @@ expect_equal(
), ),
na.rm = TRUE na.rm = TRUE
), ),
941 942
) )
# set 1500 random observations to be of specimen type 'Urine' # 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 # support for WHONET
expect_message(example_isolates %>% expect_message(example_isolates %>%
select(-patient_id) %>% select(-patient) %>%
mutate( mutate(
`First name` = "test", `First name` = "test",
`Last name` = "test", `Last name` = "test",
+1 -1
View File
@@ -84,7 +84,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) {
combination_n = n_rsi(CIP, GEN) combination_n = n_rsi(CIP, GEN)
) %>% ) %>%
pull(combination_n), pull(combination_n),
c(305, 617, 241, 711) c(1181, 577, 116)
) )
# proportion_df # proportion_df
+3 -2
View File
@@ -27,8 +27,9 @@
if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) { if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) {
# env var 'R_LIBS_USER' got overwritten during 'R CMD check' in GitHub Actions, so: # 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())) .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) library(AMR)
set_AMR_locale("English")
out <- test_package("AMR", out <- test_package("AMR",
testdir = ifelse(AMR:::dir.exists("inst/tinytest"), testdir = ifelse(AMR:::dir.exists("inst/tinytest"),
"inst/tinytest", "inst/tinytest",
@@ -37,7 +38,7 @@ if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) {
verbose = 99, verbose = 99,
color = FALSE color = FALSE
) )
cat("SUMMARY:\n") cat("\n\nSUMMARY:\n")
print(summary(out)) print(summary(out))
} }
} }