diff --git a/DESCRIPTION b/DESCRIPTION index 7165b521..39b43819 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.4.0.9049 +Version: 1.4.0.9050 Date: 2020-12-27 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 24bcf467..d16b725b 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.4.0.9049 +# AMR 1.4.0.9050 ## Last updated: 27 December 2020 ### New @@ -47,6 +47,7 @@ * Fix for printing class in tibbles when all values are `NA` * Fix for `mo_shortname()` when the input contains `NA` * If `as.mo()` takes more than 30 seconds, some suggestions will be done to improve speed +* Lost dependency on the `tidyselect` package for using antibiotic selectors such as `carbapenems()` and `aminoglycosides()` ### Other * All messages and warnings thrown by this package now break sentences on whole words diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index caa9aead..af484964 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -25,11 +25,9 @@ #' Antibiotic class selectors #' -#' Use these selection helpers inside any function that allows [Tidyverse selection helpers](https://tidyselect.r-lib.org/reference/language.html), such as [`select()`][dplyr::select()] and [`pivot_longer()`][tidyr::pivot_longer()]. They help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. +#' 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. -#' -#' **N.B. These functions require the `tidyselect` package to be installed**, that comes with the `dplyr` package. An error will be thrown if the `tidyselect` package is not installed, or if the functions are used outside a function that allows [Tidyverse selection helpers](https://tidyselect.r-lib.org/reference/language.html) such as [`select()`][dplyr::select()] and [`pivot_longer()`][tidyr::pivot_longer()]`. #' @rdname antibiotic_class_selectors #' @seealso [filter_ab_class()] for the `filter()` equivalent. #' @name antibiotic_class_selectors @@ -37,6 +35,14 @@ #' @inheritSection AMR Reference data publicly available #' @inheritSection AMR Read more on our website! #' @examples +#' # `example_isolates` is a dataset available in the AMR package. +#' # See ?example_isolates. +#' +#' # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): +#' example_isolates[, c(carbapenems())] +#' # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB': +#' example_isolates[, c("mo", aminoglycosides())] +#' #' if (require("dplyr")) { #' #' # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): @@ -151,10 +157,13 @@ 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) - peek_vars_tidyselect <- import_fn("peek_vars", "tidyselect") - vars_vct <- peek_vars_tidyselect(fn = function_name) - vars_df <- data.frame(as.list(vars_vct), stringsAsFactors = FALSE)[1, , drop = FALSE] - colnames(vars_df) <- vars_vct + for (i in seq_len(length(sys.frames()))) { + vars_df <- sys.frames()[[i]]$x + if (!is.null(vars_df) && is.data.frame(vars_df)) { + break + } + } + stop_ifnot(is.data.frame(vars_df), "the ", function_name, "() function must be used inside dplyr verbs or a data.frame call.") ab_in_data <- get_column_abx(vars_df, info = FALSE) if (length(ab_in_data) == 0) { diff --git a/R/first_isolate.R b/R/first_isolate.R index 1037d3af..950f345f 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -27,7 +27,7 @@ #' #' Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use [is_new_episode()] that also supports grouping with the `dplyr` package. #' @inheritSection lifecycle Stable lifecycle -#' @param x a [data.frame] containing isolates. Can be omitted when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. +#' @param x a [data.frame] containing isolates. Can be left blank when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. #' @param col_date column name of the result date (or date that is was received on the lab), defaults to the first column with a date class #' @param col_patient_id column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive) #' @param col_mo column name of the IDs of the microorganisms (see [as.mo()]), defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()]. @@ -46,7 +46,7 @@ #' @param include_unknown logical to determine whether 'unknown' microorganisms should be included too, i.e. microbial code `"UNKNOWN"`, which defaults to `FALSE`. For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default. Isolates with a microbial ID of `NA` will always be excluded as first isolate. #' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], or arguments passed on to [key_antibiotics()] when using [filter_first_weighted_isolate()] #' @details -#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be omitted, please see *Examples*. +#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, please see *Examples*. #' #' The [first_isolate()] function is a wrapper around the [is_new_episode()] function, but more efficient for data sets containing microorganism codes or names. #' diff --git a/R/key_antibiotics.R b/R/key_antibiotics.R index 7cfe13a4..37cc1667 100755 --- a/R/key_antibiotics.R +++ b/R/key_antibiotics.R @@ -27,7 +27,7 @@ #' #' These function can be used to determine first isolates (see [first_isolate()]). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates can then be called first *weighted* isolates. #' @inheritSection lifecycle Stable lifecycle -#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be omitted when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. +#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. #' @param y,z character vectors to compare #' @inheritParams first_isolate #' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of **broad-spectrum** antibiotics, case-insensitive. See details for which antibiotics will be used at default (which are guessed with [guess_ab_col()]). @@ -36,7 +36,7 @@ #' @param warnings give a warning about missing antibiotic columns (they will be ignored) #' @param ... other arguments passed on to functions #' @details -#' The [key_antibiotics()] function is context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be omitted, please see *Examples*. +#' The [key_antibiotics()] function is context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, please see *Examples*. #' #' The function [key_antibiotics()] returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using [key_antibiotics_equal()], to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (`"."`) by [key_antibiotics()] and ignored by [key_antibiotics_equal()]. #' diff --git a/R/mdro.R b/R/mdro.R index 6c035d2f..5b0388b5 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -27,7 +27,7 @@ #' #' Determine which isolates are multidrug-resistant organisms (MDRO) according to international and national guidelines. #' @inheritSection lifecycle Stable lifecycle -#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be omitted when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. +#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. #' @param guideline a specific guideline to follow. When left empty, the publication by Magiorakos *et al.* (2012, Clinical Microbiology and Infection) will be followed, please see *Details*. #' @inheritParams eucast_rules #' @param pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for *S. aureus*. Setting this `pct_required_classes` argument to `0.5` (default) means that for every *S. aureus* isolate at least 8 different classes must be available. Any lower number of available classes will return `NA` for that isolate. @@ -35,7 +35,7 @@ #' @param verbose a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not. #' @inheritSection eucast_rules Antibiotics #' @details -#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be omitted, please see *Examples*. +#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, please see *Examples*. #' #' For the `pct_required_classes` argument, values above 1 will be divided by 100. This is to support both fractions (`0.75` or `3/4`) and percentages (`75`). #' diff --git a/R/mo.R b/R/mo.R index 05c798e5..b90954a0 100755 --- a/R/mo.R +++ b/R/mo.R @@ -438,7 +438,7 @@ exec_as.mo <- function(x, strip_whitespace <- function(x, dyslexia_mode) { # all whitespaces (tab, new lines, etc.) should be one space - # and spaces before and after should be omitted + # and spaces before and after should be left blank trimmed <- trimws2(x) # also, make sure the trailing and leading characters are a-z or 0-9 # in case of non-regex diff --git a/R/mo_property.R b/R/mo_property.R index 9b6509e2..6599ca3d 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -27,7 +27,7 @@ #' #' Use these functions to return a specific property of a microorganism based on the latest accepted taxonomy. All input values will be evaluated internally with [as.mo()], which makes it possible to use microbial abbreviations, codes and names as input. Please see *Examples*. #' @inheritSection lifecycle Stable lifecycle -#' @param x any character (vector) that can be coerced to a valid microorganism code with [as.mo()]. Can be omitted for auto-guessing the column containing microorganism codes when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()], please see *Examples*. +#' @param x any character (vector) that can be coerced to a valid microorganism code with [as.mo()]. Can be left blank for auto-guessing the column containing microorganism codes when used inside `dplyr` verbs, such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()], please see *Examples*. #' @param property one of the column names of the [microorganisms] data set: `r paste0('"``', colnames(microorganisms), '\``"', collapse = ", ")`, or must be `"shortname"` #' @param language language of the returned text, defaults to system language (see [get_locale()]) and can be overwritten by setting the option `AMR_locale`, e.g. `options(AMR_locale = "de")`, see [translate]. Also used to translate text like "no growth". Use `language = NULL` or `language = ""` to prevent translation. #' @param ... other arguments passed on to [as.mo()], such as 'allow_uncertain' and 'ignore_pattern' diff --git a/R/mo_source.R b/R/mo_source.R index 6c9cacf6..5f0e2eca 100644 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -149,8 +149,8 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s } else if (path %like% "[.]xlsx?$") { # is Excel file (old or new) - read_excel <- import_fn("read_excel", "readxl") - df <- read_excel(path) + stop_ifnot_installed("readxl") + df <- readxl::read_excel(path) } else if (path %like% "[.]tsv$") { df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE) diff --git a/docs/404.html b/docs/404.html index 2fcd8e66..88d51b11 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 0ebd4ab2..079f10ab 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/articles/index.html b/docs/articles/index.html index eb22e187..46a278da 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/authors.html b/docs/authors.html index 691261d5..9b0624c4 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/index.html b/docs/index.html index 849cadac..4ff7f4f5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/news/index.html b/docs/news/index.html index 35b24adf..f85a2332 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

-AMR 1.4.0.9049 Unreleased +
+

+AMR 1.4.0.9050 Unreleased

@@ -306,6 +306,7 @@
  • Fix for printing class in tibbles when all values are NA

  • Fix for mo_shortname() when the input contains NA

  • If as.mo() takes more than 30 seconds, some suggestions will be done to improve speed

  • +
  • Lost dependency on the tidyselect package for using antibiotic selectors such as carbapenems() and aminoglycosides()

  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 709059a9..d48e1c1d 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: 2020-12-27T14:06Z +last_built: 2020-12-27T19:32Z 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 cff9656c..cf10b3a5 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9046 + 1.4.0.9050
    @@ -239,7 +239,7 @@
    -

    Use these selection helpers inside any function that allows Tidyverse selection helpers, such as select() and pivot_longer(). They help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations.

    +

    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.

    ab_class(ab_class)
    @@ -282,7 +282,6 @@
         

    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.

    -

    N.B. These functions require the tidyselect package to be installed, that comes with the dplyr package. An error will be thrown if the tidyselect package is not installed, or if the functions are used outside a function that allows Tidyverse selection helpers such as select() and pivot_longer()`.

    Reference data publicly available

    @@ -298,7 +297,15 @@

    filter_ab_class() for the filter() equivalent.

    Examples

    -
    if (require("dplyr")) {
    +    
    # `example_isolates` is a dataset available in the AMR package.
    +# See ?example_isolates.
    +
    +# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
    +example_isolates[, c(carbapenems())]
    +# this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
    +example_isolates[, c("mo", aminoglycosides())]
    +
    +if (require("dplyr")) {
     
       # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
       example_isolates %>% 
    diff --git a/docs/reference/eucast_rules.html b/docs/reference/eucast_rules.html
    index a8c2e140..ea173fc7 100644
    --- a/docs/reference/eucast_rules.html
    +++ b/docs/reference/eucast_rules.html
    @@ -83,7 +83,7 @@ To improve the interpretation of the antibiogram before EUCAST rules are applied
           
           
             AMR (for R)
    -        1.4.0.9048
    +        1.4.0.9050
           
         

    diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index 8e8e11b9..e1dc82be 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9046 + 1.4.0.9050 @@ -239,7 +239,7 @@
    -

    Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use is_new_episode() that also supports grouping with the dplyr package.

    +

    Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use is_new_episode() that also supports grouping with the dplyr package.

    first_isolate(
    @@ -285,7 +285,7 @@
         
         
           x
    -      

    a data.frame containing isolates. Can be omitted when used inside dplyr verbs, such as filter(), mutate() and summarise().

    +

    a data.frame containing isolates. Can be left blank when used inside dplyr verbs, such as filter(), mutate() and summarise().

    col_date @@ -366,8 +366,8 @@

    A logical vector

    Details

    -

    These functions are context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be omitted, please see Examples.

    -

    The first_isolate() function is a wrapper around the is_new_episode() function, but more efficient for data sets containing microorganism codes or names.

    +

    These functions are context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, please see Examples.

    +

    The first_isolate() function is a wrapper around the is_new_episode() function, but more efficient for data sets containing microorganism codes or names.

    All isolates with a microbial ID of NA will be excluded as first isolate.

    Why this is so important

    diff --git a/docs/reference/get_episode.html b/docs/reference/get_episode.html index 2c7c1684..f780af55 100644 --- a/docs/reference/get_episode.html +++ b/docs/reference/get_episode.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9048 + 1.4.0.9050 diff --git a/docs/reference/index.html b/docs/reference/index.html index a338ac6b..85b27cb8 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9049 + 1.4.0.9050 diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html index 93209875..6e95e09b 100644 --- a/docs/reference/key_antibiotics.html +++ b/docs/reference/key_antibiotics.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9046 + 1.4.0.9050 @@ -281,7 +281,7 @@ x -

    a data.frame with antibiotics columns, like AMX or amox. Can be omitted when used inside dplyr verbs, such as filter(), mutate() and summarise().

    +

    a data.frame with antibiotics columns, like AMX or amox. Can be left blank when used inside dplyr verbs, such as filter(), mutate() and summarise().

    col_mo @@ -331,7 +331,7 @@

    Details

    -

    The key_antibiotics() function is context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be omitted, please see Examples.

    +

    The key_antibiotics() function is context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, please see Examples.

    The function key_antibiotics() returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using key_antibiotics_equal(), to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (".") by key_antibiotics() and ignored by key_antibiotics_equal().

    The first_isolate() function only uses this function on the same microbial species from the same patient. Using this, e.g. an MRSA will be included after a susceptible S. aureus (MSSA) is found within the same patient episode. Without key antibiotic comparison it would not. See first_isolate() for more info.

    At default, the antibiotics that are used for Gram-positive bacteria are: