diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 3a0c14de..e4d9c3b7 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -123,7 +123,7 @@ jobs: run: | brew install mariadb-connector-c - - name: Install dependencies + - name: Install package dependencies if: matrix.config.r != '3.0' && matrix.config.r != '3.1' && matrix.config.r != '3.2' run: | remotes::install_deps(dependencies = TRUE) @@ -137,22 +137,22 @@ jobs: as.data.frame(utils::installed.packages())[, "Version", drop = FALSE] shell: Rscript {0} - # - name: Run R CMD check - # if: matrix.config.r != '3.0' && matrix.config.r != '3.1' && matrix.config.r != '3.2' - # env: - # _R_CHECK_CRAN_INCOMING_: false - # run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - # shell: Rscript {0} + - name: Run R CMD check + if: matrix.config.r != '3.0' && matrix.config.r != '3.1' && matrix.config.r != '3.2' + env: + _R_CHECK_CRAN_INCOMING_: false + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + shell: Rscript {0} - name: Run R CMD check on older R versions - # if: matrix.config.r == '3.0' || matrix.config.r == '3.1' || matrix.config.r == '3.2' + if: matrix.config.r == '3.0' || matrix.config.r == '3.1' || matrix.config.r == '3.2' env: _R_CHECK_CRAN_INCOMING_: false _R_CHECK_FORCE_SUGGESTS_: false _R_CHECK_LENGTH_1_CONDITION_: verbose _R_CHECK_LENGTH_1_LOGIC2_: verbose run: | - R CMD check data-raw/AMR_*.tar.gz --no-manual --as-cran + R CMD check data-raw/AMR_*.tar.gz --no-manual --no-build-vignettes - name: Show testthat output if: always() diff --git a/DESCRIPTION b/DESCRIPTION index fc8083e2..85885258 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.4.0.9058 +Version: 1.4.0.9059 Date: 2021-01-04 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 40a68ab8..83df7775 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.4.0.9058 +# AMR 1.4.0.9059 ## Last updated: 4 January 2021 ### New * Functions `get_episode()` and `is_new_episode()` to determine (patient) episodes which are not necessarily based on microorganisms. The `get_episode()` function returns the index number of the episode per group, while the `is_new_episode()` function returns values `TRUE`/`FALSE` to indicate whether an item in a vector is the start of a new episode. They also support `dplyr`s grouping (i.e. using `group_by()`): diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index f0d84d02..0276b60c 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -458,7 +458,7 @@ meet_criteria <- function(object, stop_if(allow_NULL == FALSE, "argument `", obj_name, "` must not be NULL", call = call_depth) return(invisible()) } - if (is.null(dim(object)) && length(object) == 1 && is.na(object)) { + if (is.null(dim(object)) && length(object) == 1 && suppressWarnings(is.na(object))) { # suppressWarnings for functions stop_if(allow_NA == FALSE, "argument `", obj_name, "` must not be NA", call = call_depth) return(invisible()) } @@ -527,23 +527,36 @@ meet_criteria <- function(object, } get_current_data <- function(arg_name, call) { + if (as.double(R.Version()$major) + (as.double(R.Version()$minor) / 100) < 3.2) { + if (is.na(arg_name)) { + warning_("this function can only be used in R >= 3.2", call = call) + return(data.frame()) + } else { + stop_("argument `", arg_name, "` is missing with no default", call = call) + } + } + # try a (base R) method, by going over the complete system call stack with sys.frames() not_set <- TRUE frms <- lapply(sys.frames(), function(el) { - if (tryCatch(not_set == TRUE && ".data" %in% names(el) && is.data.frame(el$`.data`), error = function(e) FALSE)) { - # dplyr? - an element `.data` will be in the system call stack - not_set <<- FALSE - el$`.data` - } else if (tryCatch(not_set == TRUE && any(c("x", "xx") %in% names(el)), error = function(e) FALSE)) { - # otherwise try base R: - # an element `x` will be in this environment for only cols, e.g. `example_isolates[, carbapenems()]` - # an element `xx` will be in this environment for rows + cols, e.g. `example_isolates[c(1:3), carbapenems()]` - if (is.data.frame(el$xx)) { + if (".Generic" %in% names(el)) { + if (tryCatch(not_set == TRUE && ".data" %in% names(el) && is.data.frame(el$`.data`), error = function(e) FALSE)) { + # dplyr? - an element `.data` will be in the system call stack not_set <<- FALSE - el$xx - } else if (is.data.frame(el$x)) { - not_set <<- FALSE - el$x + el$`.data` + } else if (tryCatch(not_set == TRUE && any(c("x", "xx") %in% names(el)), error = function(e) FALSE)) { + # otherwise try base R: + # an element `x` will be in this environment for only cols, e.g. `example_isolates[, carbapenems()]` + # an element `xx` will be in this environment for rows + cols, e.g. `example_isolates[c(1:3), carbapenems()]` + if (tryCatch(is.data.frame(el$xx), error = function(e) FALSE)) { + not_set <<- FALSE + el$xx + } else if (tryCatch(is.data.frame(el$x))) { + not_set <<- FALSE + el$x + } else { + NULL + } } else { NULL } diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index 673447ea..f3211490 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -27,7 +27,9 @@ #' #' These functions help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. #' @inheritParams filter_ab_class -#' @details All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.) in the [antibiotics] data set. This means that a selector like e.g. [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. +#' @details These functions only work in R 3.2 (2015) and later. +#' +#' All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.) in the [antibiotics] data set. This means that a selector like e.g. [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. #' @rdname antibiotic_class_selectors #' @seealso [filter_ab_class()] for the `filter()` equivalent. #' @name antibiotic_class_selectors @@ -161,7 +163,12 @@ tetracyclines <- function() { ab_selector <- function(ab_class, function_name) { meet_criteria(ab_class, allow_class = "character", has_length = 1, .call_depth = 1) meet_criteria(function_name, allow_class = "character", has_length = 1, .call_depth = 1) - + + if (as.double(R.Version()$major) + (as.double(R.Version()$minor) / 100) < 3.2) { + warning_(function_name, "() can only be used in R >= 3.2", call = FALSE) + return(NULL) + } + vars_df <- get_current_data(arg_name = NA, call = -3) ab_in_data <- get_column_abx(vars_df, info = FALSE) diff --git a/data-raw/AMR_1.4.0.9058.tar.gz b/data-raw/AMR_1.4.0.9059.tar.gz similarity index 79% rename from data-raw/AMR_1.4.0.9058.tar.gz rename to data-raw/AMR_1.4.0.9059.tar.gz index 4bdc18cc..5ea064c4 100644 Binary files a/data-raw/AMR_1.4.0.9058.tar.gz and b/data-raw/AMR_1.4.0.9059.tar.gz differ diff --git a/docs/404.html b/docs/404.html index dc184c34..576efc7e 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index f8426757..e6a80ec3 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 diff --git a/docs/articles/index.html b/docs/articles/index.html index 4116a500..99b0cafa 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 diff --git a/docs/authors.html b/docs/authors.html index cb175c91..85a4a984 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 diff --git a/docs/index.html b/docs/index.html index 8f977006..b9642e1d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 diff --git a/docs/news/index.html b/docs/news/index.html index 52d71f3a..efaee483 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

-AMR 1.4.0.9058 Unreleased +
+

+AMR 1.4.0.9059 Unreleased

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 04ee4437..11ecbf3a 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-01-04T10:27Z +last_built: 2021-01-04T11:28Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index 72791542..5a6123b0 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0 + 1.4.0.9059

@@ -281,7 +281,8 @@

Details

-

All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.) in the antibiotics data set. This means that a selector like e.g. aminoglycosides() will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.

+

These functions only work in R 3.2 (2015) and later.

+

All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.) in the antibiotics data set. This means that a selector like e.g. aminoglycosides() will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.

Reference data publicly available

diff --git a/docs/reference/index.html b/docs/reference/index.html index 38a7f65c..ea81bcd4 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059
diff --git a/docs/survey.html b/docs/survey.html index d7ff502b..5ebafb63 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9058 + 1.4.0.9059

diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd index f87f9146..23b2b354 100644 --- a/man/antibiotic_class_selectors.Rd +++ b/man/antibiotic_class_selectors.Rd @@ -53,6 +53,8 @@ tetracyclines() These functions help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. } \details{ +These functions only work in R 3.2 (2015) and later. + All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.) in the \link{antibiotics} data set. This means that a selector like e.g. \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. } \section{Reference data publicly available}{