Compare commits

..

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

View File

@ -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 }}

View File

@ -131,9 +131,11 @@ 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 ..
ls -lh
R CMD build AMR
R CMD check --no-manual --run-donttest --run-dontrun AMR_*.tar.gz
shell: bash
@ -141,6 +143,8 @@ jobs:
- name: Show unit tests output
if: always()
run: |
ls -lh
cd AMR
find . -name 'tinytest.Rout*' -exec cat '{}' \; || true
shell: bash

View File

@ -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
# use RStudio Package Manager to quickly install packages
use-public-rspm: true
- uses: r-lib/actions/setup-pandoc@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
- 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}

View File

@ -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"))

View File

@ -1,5 +1,5 @@
Package: AMR
Version: 1.8.1.9034
Version: 1.8.1.9040
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

View File

@ -1,4 +1,4 @@
# AMR 1.8.1.9034
# AMR 1.8.1.9040
### 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.

View File

@ -651,7 +651,7 @@ dataset_UTF8_to_ASCII <- function(df) {
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

View File

@ -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
)

12
R/mo.R
View File

@ -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))

View File

@ -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]+", "",

View File

@ -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))

Binary file not shown.

Binary file not shown.

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.

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))
}
# 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)))
}

View File

@ -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")
)

View File

@ -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

View File

@ -53,13 +53,14 @@ expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "
# antibiotic names must always be coercible to their original AB code
expect_identical(as.ab(antibiotics$name), antibiotics$ab)
if (AMR:::pkg_is_available("tibble", also_load = FALSE)) {
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
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])
}
}
df <- AMR:::MO_lookup
expect_true(nrow(df[which(df$prevalence == 1), , drop = FALSE]) < nrow(df[which(df$prevalence == 2), , drop = FALSE]))

View File

@ -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",

View File

@ -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

View File

@ -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))
}
}