diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index e64929be..9cf9701c 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -50,17 +50,22 @@ jobs: fail-fast: false matrix: config: + # these are the developmental version of R - we allow those tests to fail - {os: macOS-latest, r: 'devel', allowfail: true} - - {os: macOS-latest, r: 'release', allowfail: false} - - {os: macOS-latest, r: 'oldrel', allowfail: false} - - {os: windows-latest, r: 'devel', allowfail: true} - - {os: windows-latest, r: 'release', allowfail: false} - - {os: windows-latest, r: 'oldrel', allowfail: false} - - {os: ubuntu-20.04, r: 'devel', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + + # these are the current release of R + - {os: macOS-latest, r: 'release', allowfail: false} + - {os: windows-latest, r: 'release', allowfail: false} - {os: ubuntu-20.04, r: 'release', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + + # these are the previous release of R + - {os: macOS-latest, r: 'oldrel', allowfail: false} + - {os: windows-latest, r: 'oldrel', allowfail: false} - {os: ubuntu-20.04, r: 'oldrel', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + + # test against all released versions of R >= 3.0, we support them all! - {os: ubuntu-20.04, r: '4.1', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: '4.0', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: '3.6', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} diff --git a/.github/workflows/codecovr.yaml b/.github/workflows/codecovr.yaml index b4784214..38a0f177 100644 --- a/.github/workflows/codecovr.yaml +++ b/.github/workflows/codecovr.yaml @@ -30,7 +30,6 @@ on: - master pull_request: branches: - - premaster - master name: code-coverage @@ -76,10 +75,9 @@ jobs: library(AMR) library(tinytest) library(covr) - source_files <- list.files("AMR/R", pattern = ".R$", full.names = TRUE) - test_files <- list.files("AMR/inst/tinytest", full.names = TRUE) - cov <- file_coverage(source_files = source_files, test_files = test_files, parent_env = asNamespace("AMR"), line_exclusions = list("AMR/R/atc_online.R", "AMR/R/mo_source.R", "AMR/R/translate.R", "AMR/R/resistance_predict.R", "AMR/R/aa_helper_functions.R", "AMR/R/aa_helper_pm_functions.R", "AMR/R/zzz.R")) - print(cov) + source_files <- list.files("R", pattern = ".R$", full.names = TRUE) + test_files <- list.files("inst/tinytest", full.names = TRUE) + cov <- file_coverage(source_files = source_files, test_files = test_files, parent_env = asNamespace("AMR"), 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")) attr(cov, which = "package") <- list(path = ".") # until https://github.com/r-lib/covr/issues/478 is solved codecov(coverage = cov, quiet = FALSE) shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index cb09bf45..bf62ac5b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.6.0.9060 -Date: 2021-05-22 +Version: 1.6.0.9061 +Date: 2021-05-23 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 8a36c740..87de423e 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# `AMR` 1.6.0.9060 -## Last updated: 22 May 2021 +# `AMR` 1.6.0.9061 +## Last updated: 23 May 2021 ### Breaking change * All antibiotic class selectors (such as `carbapenems()`, `aminoglycosides()`) can now be used for filtering as well, making all their accompanying `filter_*()` functions redundant (such as `filter_carbapenems()`, `filter_aminoglycosides()`). These functions are now deprecated and will be removed in a next release. @@ -64,6 +64,7 @@ * Updated join functions to always use `dplyr` join functions if the `dplyr` package is installed - now also preserving grouped variables * Antibiotic class selectors (such as `cephalosporins()`) now maintain the column order from the original data * Fix for selecting columns using `fluoroquinolones()` +* `age()` now vectorises over both `x` and `reference` ### Other * All unit tests are now processed by the `tinytest` package, instead of the `testthat` package. The `testthat` package unfortunately requires tons of dependencies that are also heavy and only usable for recent R versions, disallowing developers to test a package under any R 3.* version. On the contrary, the `tinytest` package is very lightweight and dependency-free. diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index d8414af3..80126fc7 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -27,7 +27,7 @@ #' #' These functions help to filter and select columns with antibiotic test results that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. \strong{\Sexpr{ifelse(as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.2, paste0("NOTE: THESE FUNCTIONS DO NOT WORK ON YOUR CURRENT R VERSION. These functions require R version 3.2 or later - you have ", R.version.string, "."), "")}} #' @inheritSection lifecycle Stable Lifecycle -#' @param ab_class an antimicrobial class, like `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value. +#' @param ab_class an antimicrobial class, such as `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value. #' @param only_rsi_columns a [logical] to indicate whether only columns of class `` must be selected (defaults to `FALSE`), see [as.rsi()] #' @details \strong{\Sexpr{ifelse(as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.2, paste0("NOTE: THESE FUNCTIONS DO NOT WORK ON YOUR CURRENT R VERSION. These functions require R version 3.2 or later - you have ", R.version.string, "."), "")}} #' diff --git a/R/age.R b/R/age.R index 5b532c89..849b467c 100755 --- a/R/age.R +++ b/R/age.R @@ -27,12 +27,14 @@ #' #' Calculates age in years based on a reference date, which is the sytem date at default. #' @inheritSection lifecycle Stable Lifecycle -#' @param x date(s), will be coerced with [as.POSIXlt()] -#' @param reference reference date(s) (defaults to today), will be coerced with [as.POSIXlt()] +#' @param x date(s), [character] (vectors) will be coerced with [as.POSIXlt()] +#' @param reference reference date(s) (defaults to today), [character] (vectors) will be coerced with [as.POSIXlt()] #' @param exact a [logical] to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of [year-to-date](https://en.wikipedia.org/wiki/Year-to-date) (YTD) of `x` by the number of days in the year of `reference` (either 365 or 366). #' @param na.rm a [logical] to indicate whether missing values should be removed #' @param ... arguments passed on to [as.POSIXlt()], such as `origin` #' @details Ages below 0 will be returned as `NA` with a warning. Ages above 120 will only give a warning. +#' +#' This function vectorises over both `x` and `reference`, meaning that either can have a length of 1 while the other argument has a larger length. #' @return An [integer] (no decimals) if `exact = FALSE`, a [double] (with decimals) otherwise #' @seealso To split ages into groups, use the [age_groups()] function. #' @inheritSection AMR Read more on Our Website! @@ -53,8 +55,13 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) { meet_criteria(na.rm, allow_class = "logical", has_length = 1) if (length(x) != length(reference)) { - stop_if(length(reference) != 1, "`x` and `reference` must be of same length, or `reference` must be of length 1.") - reference <- rep(reference, length(x)) + if (length(x) == 1) { + x <- rep(x, length(reference)) + } else if (length(reference) == 1) { + reference <- rep(reference, length(x)) + } else { + stop_("`x` and `reference` must be of same length, or `reference` must be of length 1.") + } } x <- as.POSIXlt(x, ...) reference <- as.POSIXlt(reference, ...) @@ -68,15 +75,15 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) { # add decimals if (exact == TRUE) { # get dates of `x` when `x` would have the year of `reference` - x_in_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), format(x, "-%m-%d"))) + x_in_reference_year <- as.POSIXlt(paste0(format(as.Date(reference), "%Y"), format(as.Date(x), "-%m-%d"))) # get differences in days - n_days_x_rest <- as.double(difftime(reference, x_in_reference_year, units = "days")) + n_days_x_rest <- as.double(difftime(as.Date(reference), as.Date(x_in_reference_year), units = "days")) # get numbers of days the years of `reference` has for a reliable denominator - n_days_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), "-12-31"))$yday + 1 + n_days_reference_year <- as.POSIXlt(paste0(format(as.Date(reference), "%Y"), "-12-31"))$yday + 1 # add decimal parts of year mod <- n_days_x_rest / n_days_reference_year # negative mods are cases where `x_in_reference_year` > `reference` - so 'add' a year - mod[mod < 0] <- 1 + mod[mod < 0] + mod[mod < 0] <- mod[mod < 0] + 1 # and finally add to ages ages <- ages + mod } diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 4f2c044c..7fe3d414 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 99ba4b0d..52bf38b9 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index d4050696..fe7fda44 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html index be882ebb..8cc857e5 100644 --- a/docs/articles/datasets.html +++ b/docs/articles/datasets.html @@ -39,7 +39,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 @@ -192,7 +192,7 @@ diff --git a/docs/authors.html b/docs/authors.html index a96e8a77..967b41fd 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 diff --git a/docs/extra.css b/docs/extra.css index c5af0bd9..db0fd3c6 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -222,6 +222,9 @@ table a:not(.btn) { table a:not(.btn):hover { text-decoration: underline; } +.template-article thead th { + text-align: inherit; +} /* text below header in manual overview */ .template-reference-index h2 ~ p { diff --git a/docs/index.html b/docs/index.html index 39cb1286..b3613817 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 diff --git a/docs/news/index.html b/docs/news/index.html index 675accf7..95babb9a 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061 @@ -236,12 +236,12 @@ Source: NEWS.md -
-

- Unreleased AMR 1.6.0.9060

-
+
+

+ Unreleased AMR 1.6.0.9061

+

-Last updated: 22 May 2021 +Last updated: 23 May 2021

@@ -335,6 +335,9 @@
  • Antibiotic class selectors (such as cephalosporins()) now maintain the column order from the original data
  • Fix for selecting columns using fluoroquinolones()
  • +
  • +age() now vectorises over both x and reference +
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 74046425..ec8a439e 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-22T07:53Z +last_built: 2021-05-23T20:10Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/age.html b/docs/reference/age.html index 56409a1d..9ce01b1c 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -82,7 +82,7 @@ AMR (for R) - 1.6.0.9055 + 1.6.0.9061
    @@ -249,11 +249,11 @@ x -

    date(s), will be coerced with as.POSIXlt()

    +

    date(s), character (vectors) will be coerced with as.POSIXlt()

    reference -

    reference date(s) (defaults to today), will be coerced with as.POSIXlt()

    +

    reference date(s) (defaults to today), character (vectors) will be coerced with as.POSIXlt()

    exact @@ -275,6 +275,7 @@

    Details

    Ages below 0 will be returned as NA with a warning. Ages above 120 will only give a warning.

    +

    This function vectorises over both x and reference, meaning that either can have a length of 1 while the other argument has a larger length.

    Stable Lifecycle

    diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index 627ddd78..c232f49c 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -83,7 +83,7 @@ AMR (for R) - 1.6.0.9055 + 1.6.0.9061
    @@ -281,7 +281,7 @@ ab_class -

    an antimicrobial class, like "carbapenems". The columns group, atc_group1 and atc_group2 of the antibiotics data set will be searched (case-insensitive) for this value.

    +

    an antimicrobial class, such as "carbapenems". The columns group, atc_group1 and atc_group2 of the antibiotics data set will be searched (case-insensitive) for this value.

    only_rsi_columns diff --git a/docs/reference/index.html b/docs/reference/index.html index 3b5e745f..79a67d6a 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061
    diff --git a/docs/survey.html b/docs/survey.html index fb15c1df..f756d1d6 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9060 + 1.6.0.9061
    diff --git a/man/age.Rd b/man/age.Rd index 120a039c..ef23a199 100644 --- a/man/age.Rd +++ b/man/age.Rd @@ -7,9 +7,9 @@ age(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) } \arguments{ -\item{x}{date(s), will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}} +\item{x}{date(s), \link{character} (vectors) will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}} -\item{reference}{reference date(s) (defaults to today), will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}} +\item{reference}{reference date(s) (defaults to today), \link{character} (vectors) will be coerced with \code{\link[=as.POSIXlt]{as.POSIXlt()}}} \item{exact}{a \link{logical} to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of \href{https://en.wikipedia.org/wiki/Year-to-date}{year-to-date} (YTD) of \code{x} by the number of days in the year of \code{reference} (either 365 or 366).} @@ -25,6 +25,8 @@ Calculates age in years based on a reference date, which is the sytem date at de } \details{ Ages below 0 will be returned as \code{NA} with a warning. Ages above 120 will only give a warning. + +This function vectorises over both \code{x} and \code{reference}, meaning that either can have a length of 1 while the other argument has a larger length. } \section{Stable Lifecycle}{ diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd index 066a5e70..2f028977 100644 --- a/man/antibiotic_class_selectors.Rd +++ b/man/antibiotic_class_selectors.Rd @@ -53,7 +53,7 @@ penicillins(only_rsi_columns = FALSE) tetracyclines(only_rsi_columns = FALSE) } \arguments{ -\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.} +\item{ab_class}{an antimicrobial class, such as \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.} \item{only_rsi_columns}{a \link{logical} to indicate whether only columns of class \verb{} must be selected (defaults to \code{FALSE}), see \code{\link[=as.rsi]{as.rsi()}}} } diff --git a/pkgdown/extra.css b/pkgdown/extra.css index c5af0bd9..db0fd3c6 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -222,6 +222,9 @@ table a:not(.btn) { table a:not(.btn):hover { text-decoration: underline; } +.template-article thead th { + text-align: inherit; +} /* text below header in manual overview */ .template-reference-index h2 ~ p {