diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 253557a1..2a75c1b0 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -97,8 +97,9 @@ jobs: if: runner.os == 'Linux' # update the below with sysreqs::sysreqs("DESCRIPTION") and check the "DEB" entries (for Ubuntu). # we don't want to depend on the sysreqs pkg here, as it requires a quite new R version + # as of May 2021: https://sysreqs.r-hub.io/pkg/AMR,R,cleaner,curl,dplyr,ggplot2,ggtext,knitr,microbenchmark,pillar,readxl,rmarkdown,rstudioapi,rvest,skimr,tidyr,tinytest,xml2,backports,crayon,rlang,vctrs,evaluate,highr,markdown,stringr,yaml,xfun,cli,ellipsis,fansi,lifecycle,utf8,glue,mime,magrittr,stringi,generics,R6,tibble,tidyselect,pkgconfig,purrr,digest,gtable,isoband,MASS,mgcv,scales,withr,nlme,Matrix,farver,labeling,munsell,RColorBrewer,viridisLite,lattice,colorspace,gridtext,Rcpp,RCurl,png,jpeg,bitops,cellranger,progress,rematch,hms,prettyunits,htmltools,jsonlite,tinytex,base64enc,httr,selectr,openssl,askpass,sys,repr,cpp11 run: | - sudo apt install -y libssl-dev pandoc pandoc-citeproc libxml2-dev libicu-dev libcurl4-openssl-dev + sudo apt install -y libssl-dev pandoc pandoc-citeproc libxml2-dev libicu-dev libcurl4-openssl-dev libpng-dev - name: Restore cached R packages # this step will add the step 'Post Restore cached R packages' on a succesful run @@ -109,10 +110,7 @@ jobs: key: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-v4 - name: Install AMR and tinytest and update dependencies - # some old R instances have trouble installing tinytest, so we ship it too run: | - install.packages("data-raw/AMR_latest.tar.gz") - trimws <- AMR:::trimws; install.packages("data-raw/tinytest_1.2.4.tar.gz") source("data-raw/_install_deps.R") shell: Rscript {0} @@ -122,26 +120,16 @@ jobs: utils::sessionInfo() as.data.frame(utils::installed.packages())[, "Version", drop = FALSE] shell: Rscript {0} - - - name: Run R CMD check on Windows - if: runner.os == 'Windows' - env: - _R_CHECK_CRAN_INCOMING_: false - _R_CHECK_FORCE_SUGGESTS_: false - _R_CHECK_DEPENDS_ONLY_: true - _R_CHECK_LENGTH_1_CONDITION_: verbose - _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 }} - R_RUN_TINYTEST: true + + - name: Unpack shipped version and remove vignettes + if: always() run: | tar -xf data-raw/AMR_latest.tar.gz rm -rf AMR/vignettes - R CMD check AMR + Rscript -e "writeLines(readLines('DESCRIPTION')[!grepl('VignetteBuilder', readLines('DESCRIPTION'))], 'DESCRIPTION')" shell: bash - - - name: Run R CMD check on Linux and macOS - if: runner.os != 'Windows' + + - name: Run R CMD check env: _R_CHECK_CRAN_INCOMING_: false _R_CHECK_FORCE_SUGGESTS_: false @@ -152,9 +140,7 @@ jobs: R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }} R_RUN_TINYTEST: true run: | - tar -xf data-raw/AMR_latest.tar.gz - rm -rf AMR/vignettes - R CMD check AMR --no-manual --no-vignettes + R CMD check --no-manual --no-vignettes AMR shell: bash - name: Show unit tests output diff --git a/DESCRIPTION b/DESCRIPTION index 7b1df64e..ff8defd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.6.0.9043 -Date: 2021-05-17 +Version: 1.6.0.9044 +Date: 2021-05-18 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index 2c00a467..5d94b329 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -174,6 +174,7 @@ export(atc_online_ddd) export(atc_online_groups) export(atc_online_property) export(availability) +export(betalactams) export(brmo) export(bug_drug_combinations) export(carbapenems) @@ -206,6 +207,7 @@ export(filter_4th_cephalosporins) export(filter_5th_cephalosporins) export(filter_ab_class) export(filter_aminoglycosides) +export(filter_betalactams) export(filter_carbapenems) export(filter_cephalosporins) export(filter_first_isolate) diff --git a/NEWS.md b/NEWS.md index 5c16162f..10633cb6 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# `AMR` 1.6.0.9043 -## Last updated: 17 May 2021 +# `AMR` 1.6.0.9044 +## Last updated: 18 May 2021 ### New * Function `custom_eucast_rules()` that brings support for custom AMR rules in `eucast_rules()` @@ -11,7 +11,9 @@ * The `first_isolate()` function can now take a vector of values for `col_keyantibiotics` and can have an episode length of `Inf` * Since the phenotype-based method is the new default, `filter_first_isolate()` renders the `filter_first_weighted_isolate()` function redundant. For this reason, `filter_first_weighted_isolate()` is now deprecated. * The documentation of the `first_isolate()` and `key_antimicrobials()` functions has been completely rewritten. -* Added `ggplot()` method for `resistance_predict()` +* Function `betalactams()` as additional antbiotic column selector and function `filter_betalactams()` as additional antbiotic column filter. The group of betalactams consists of all carbapenems, cephalosporins and penicillins. +* A `ggplot()` method for `resistance_predict()` + ### Changed * Custom MDRO guidelines (`mdro()`, `custom_mdro_guideline()`): @@ -41,7 +43,8 @@ * Updated `skimr::skim()` usage for MIC values to also include 25th and 75th percentiles * Fix for plotting missing MIC/disk diffusion values * Updated join functions to always use `dplyr` join functions if the `dplyr` package is installed - now also preserving grouped variables -* Fix for filtering on antibiotic classes (such as `filter_cephalosporins()`) +* Fix for filtering on antibiotic classes (such as `filter_cephalosporins()`), which now also supports dplyr groups +* Antibiotic class selectors (such as `cephalosporins()`) now maintain the column order from the original data ### 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, defeating the purpose to test our package under less recent R versions. On the contrary, the `tinytest` package is very lightweight and dependency-free. diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 47a0ee87..4522db0e 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -1172,14 +1172,13 @@ strrep <- function(x, times) { paste0(replicate(times, x), collapse = "") }, list(x = x, times = times), MoreArgs = list()), use.names = FALSE) } -trimws <- function(x, which = c("both", "left", "right")) { +trimws <- function(x, which = c("both", "left", "right"), whitespace = "[ \t\r\n]") { which <- match.arg(which) mysub <- function(re, x) sub(re, "", x, perl = TRUE) - if (which == "left") - return(mysub("^[ \t\r\n]+", x)) - if (which == "right") - return(mysub("[ \t\r\n]+$", x)) - mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) + switch(which, + left = mysub(paste0("^", whitespace, "+"), x), + right = mysub(paste0(whitespace, "+$"), x), + both = mysub(paste0(whitespace, "+$"), mysub(paste0("^", whitespace, "+"), x))) } isFALSE <- function(x) { is.logical(x) && length(x) == 1L && !is.na(x) && !x diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index 95258e91..7e647a9a 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -32,6 +32,8 @@ #' @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, "."), "")}} #' #' 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. +#' +#' The group of betalactams consists of all carbapenems, cephalosporins and penicillins. #' @rdname antibiotic_class_selectors #' @seealso [filter_ab_class()] for the `filter()` equivalent. #' @name antibiotic_class_selectors @@ -91,6 +93,11 @@ aminoglycosides <- function(only_rsi_columns = FALSE) { ab_selector("aminoglycoside", function_name = "aminoglycosides", only_rsi_columns = only_rsi_columns) } +#' @rdname antibiotic_class_selectors +#' @export +betalactams <- function(only_rsi_columns = FALSE) { + ab_selector("carbapenem|cephalosporin|penicillin", function_name = "betalactams", only_rsi_columns = only_rsi_columns) +} #' @rdname antibiotic_class_selectors #' @export carbapenems <- function(only_rsi_columns = FALSE) { @@ -187,7 +194,7 @@ ab_selector <- function(ab_class, # improve speed here so it will only run once when e.g. in one select call if (!identical(pkg_env$ab_selector, unique_call_id())) { - ab_in_data <- get_column_abx(vars_df, info = FALSE, only_rsi_columns = only_rsi_columns) + ab_in_data <- get_column_abx(vars_df, info = FALSE, only_rsi_columns = only_rsi_columns, sort = FALSE) pkg_env$ab_selector <- unique_call_id() pkg_env$ab_selector_cols <- ab_in_data } else { @@ -212,6 +219,7 @@ ab_selector <- function(ab_class, } # get the columns with a group names in the chosen ab class agents <- ab_in_data[names(ab_in_data) %in% ab_reference$ab] + if (message_not_thrown_before(function_name)) { if (length(agents) == 0) { message_("No antimicrobial agents of class ", ab_group, " found", examples, ".") diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index 3824edb3..12271640 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -34,6 +34,8 @@ #' @param only_rsi_columns a [logical] to indicate whether only columns must be included that were transformed to class `` (see [as.rsi()]) on beforehand (defaults to `FALSE`) #' @param ... arguments passed on to [filter_ab_class()] #' @details All columns of `x` will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g. [filter_aminoglycosides()] will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. +#' +#' The group of betalactams consists of all carbapenems, cephalosporins and penicillins. #' @rdname filter_ab_class #' @seealso [antibiotic_class_selectors()] for the `select()` equivalent. #' @export @@ -88,16 +90,16 @@ filter_ab_class <- function(x, if (is.null(.call_depth)) { .call_depth <- 0 } + meet_criteria(x, allow_class = "data.frame", .call_depth = .call_depth) meet_criteria(ab_class, allow_class = "character", has_length = 1, .call_depth = .call_depth) meet_criteria(result, allow_class = "character", has_length = c(1, 2, 3), allow_NULL = TRUE, .call_depth = .call_depth) meet_criteria(scope, allow_class = "character", has_length = 1, is_in = c("all", "any"), .call_depth = .call_depth) meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1, .call_depth = .call_depth) - + check_dataset_integrity() # save to return later - x_class <- class(x) x.bak <- x x <- as.data.frame(x, stringsAsFactors = FALSE) @@ -111,14 +113,24 @@ filter_ab_class <- function(x, stop_ifnot(all(scope %in% c("any", "all")), "`scope` must be one of: 'any', 'all'") # get all columns in data with names that resemble antibiotics - ab_in_data <- get_column_abx(x, info = FALSE, only_rsi_columns = only_rsi_columns) + ab_in_data <- get_column_abx(x, info = FALSE, only_rsi_columns = only_rsi_columns, sort = FALSE) + + # improve speed here so it will only run once when e.g. in one select call + if (!identical(pkg_env$filter_ab_selector, unique_call_id())) { + ab_in_data <- get_column_abx(x, info = FALSE, only_rsi_columns = only_rsi_columns, sort = FALSE) + pkg_env$filter_ab_selector <- unique_call_id() + pkg_env$filter_ab_selector_cols <- ab_in_data + } else { + ab_in_data <- pkg_env$filter_ab_selector_cols + } + if (length(ab_in_data) == 0) { - message_("No columns with class found (see ?as.rsi), data left unchanged.") + message_("No columns with antibiotic test results found (see ?as.rsi), data left unchanged.") return(x.bak) } # get reference data ab_class.bak <- ab_class - ab_class <- gsub("[^a-zA-Z0-9]+", ".*", ab_class) + ab_class <- gsub("[^a-zA-Z|0-9]+", ".*", ab_class) ab_class <- gsub("(ph|f)", "(ph|f)", ab_class) ab_class <- gsub("(t|th)", "(t|th)", ab_class) ab_reference <- subset(antibiotics, @@ -133,8 +145,8 @@ filter_ab_class <- function(x, # get the columns with a group names in the chosen ab class agents <- ab_in_data[names(ab_in_data) %in% ab_reference$ab] if (length(agents) == 0) { - message_("No antimicrobial agents of class ", ab_group, - " found (such as ", find_ab_names(ab_class, 2), + message_("No antimicrobial agents of class '", ab_group, + "' found (such as ", find_ab_names(ab_class, 2), ")", ifelse(only_rsi_columns == TRUE, " with class ,", ","), " data left unchanged.") @@ -162,18 +174,22 @@ filter_ab_class <- function(x, # sort columns on official name agents <- agents[order(ab_name(names(agents), language = NULL))] + agents_formatted <- paste0("'", font_bold(agents, collapse = NULL), "'") + agents_names <- ab_name(names(agents), tolower = TRUE, language = NULL) + need_name <- tolower(gsub("[^a-zA-Z]", "", agents)) != tolower(gsub("[^a-zA-Z]", "", agents_names)) + agents_formatted[need_name] <- paste0(agents_formatted[need_name], + " (", agents_names[need_name], ")") + message_("Filtering on ", ab_group, ": ", scope, - paste(paste0("`", font_bold(agents, collapse = NULL), - "` (", ab_name(names(agents), tolower = TRUE, language = NULL), ")"), - collapse = scope_txt), + vector_or(agents_formatted, quotes = FALSE, last_sep = scope_txt), operator, " ", vector_or(result, quotes = TRUE), as_note = FALSE, extra_indent = 6) x_transposed <- as.list(as.data.frame(t(x[, agents, drop = FALSE]), stringsAsFactors = FALSE)) filtered <- vapply(FUN.VALUE = logical(1), x_transposed, function(y) scope_fn(y %in% result, na.rm = TRUE)) - x <- x[which(filtered), , drop = FALSE] - class(x) <- x_class - x + + # this returns the original data with the filtering, also preserving attributes (such as dplyr groups) + x.bak[which(filtered), , drop = FALSE] } #' @rdname filter_ab_class @@ -192,6 +208,21 @@ filter_aminoglycosides <- function(x, ...) } +#' @rdname filter_ab_class +#' @export +filter_betalactams <- function(x, + result = NULL, + scope = "any", + only_rsi_columns = FALSE, + ...) { + filter_ab_class(x = x, + ab_class = "carbapenem|cephalosporin|penicillin", + result = result, + scope = scope, + only_rsi_columns = only_rsi_columns, + .call_depth = 1, + ...) +} #' @rdname filter_ab_class #' @export filter_carbapenems <- function(x, @@ -401,8 +432,10 @@ filter_tetracyclines <- function(x, } find_ab_group <- function(ab_class) { + ab_class[ab_class == "carbapenem|cephalosporin|penicillin"] <- "betalactam" ab_class <- gsub("[^a-zA-Z0-9]", ".*", ab_class) ifelse(ab_class %in% c("aminoglycoside", + "betalactam", "carbapenem", "cephalosporin", "fluoroquinolone", @@ -424,9 +457,20 @@ find_ab_group <- function(ab_class) { } find_ab_names <- function(ab_group, n = 3) { - ab_group <- gsub("[^a-zA-Z0-9]", ".*", ab_group) - drugs <- antibiotics[which(antibiotics$group %like% ab_group & antibiotics$ab %unlike% "[0-9]$"), ]$name - paste0(sort(ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE), - tolower = TRUE, language = NULL)), - collapse = ", ") + ab_group <- gsub("[^a-zA-Z|0-9]", ".*", ab_group) + + # try popular first, they have DDDs + drugs <- antibiotics[which((!is.na(antibiotics$iv_ddd) | !is.na(antibiotics$oral_ddd)) & + antibiotics$name %unlike% " " & + antibiotics$group %like% ab_group & + antibiotics$ab %unlike% "[0-9]$"), ]$name + if (length(drugs) < n) { + # now try it all + drugs <- antibiotics[which(antibiotics$group %like% ab_group & + antibiotics$ab %unlike% "[0-9]$"), ]$name + } + vector_or(ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE), + tolower = TRUE, + language = NULL), + quotes = FALSE) } diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 6d9499d2..f071bed6 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/data-raw/_install_deps.R b/data-raw/_install_deps.R index 2b9ce79e..9b27adea 100644 --- a/data-raw/_install_deps.R +++ b/data-raw/_install_deps.R @@ -23,7 +23,14 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -pkg_suggests <- AMR:::trimws(unlist(strsplit(packageDescription("AMR")$Suggests, ",(\n)?"))) +install.packages("data-raw/AMR_latest.tar.gz", dependencies = FALSE) + +# some old R instances have trouble installing tinytest, so we ship it too +# R < 3.2 does not contain trimws(), which is part of this script and of a tinytest script +trimws <- AMR:::trimws +intall.packages("data-raw/tinytest_1.2.4.tar.gz") + +pkg_suggests <- trimws(unlist(strsplit(packageDescription("AMR")$Suggests, ",(\n)?"))) to_install <- pkg_suggests[!pkg_suggests %in% rownames(utils::installed.packages())] to_update <- as.data.frame(utils::old.packages(repos = "https://cran.rstudio.com/"), stringsAsFactors = FALSE) diff --git a/docs/404.html b/docs/404.html index d371cdb4..df253600 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index c2ea2125..df173321 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html index 35e34a1e..363d22cd 100644 --- a/docs/articles/datasets.html +++ b/docs/articles/datasets.html @@ -39,7 +39,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 @@ -192,7 +192,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 07d02cb0..6e7f4153 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 diff --git a/docs/index.html b/docs/index.html index d95a6f64..e4c6c913 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,76 +1,37 @@ - - - - + + + + - -AMR (for R) • AMR (for R) - - - +Antimicrobial Resistance Data Analysis • AMR (for R) + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - -
-
- + +
+ - - -
+
- -
- +

Note: the rules of ‘EUCAST Clinical Breakpoints v11.0 (2021)’ are now implemented.

@@ -259,9 +218,9 @@ library(dplyr) example_isolates %>% - mutate(bacteria = mo_fullname(mo)) %>% - filter(mo_is_gram_negative(), mo_is_intrinsic_resistant(ab = "cefotax")) %>% - select(bacteria, aminoglycosides(), carbapenems()) + mutate(bacteria = mo_fullname(mo)) %>% + filter(mo_is_gram_negative(), mo_is_intrinsic_resistant(ab = "cefotax")) %>% + select(bacteria, aminoglycosides(), carbapenems()) #> NOTE: Using column 'mo' as input for mo_is_gram_negative() #> NOTE: Using column 'mo' as input for mo_is_intrinsic_resistant() #> NOTE: Determining intrinsic resistance based on 'EUCAST Expert Rules' and @@ -270,7 +229,7 @@ #> 'KAN' (kanamycin) and 'TOB' (tobramycin) #> Selecting carbapenems: columns 'IPM' (imipenem) and 'MEM' (meropenem)

With only having defined a row filter on Gram-negative bacteria with intrinsic resistance to cefotaxime (mo_is_gram_negative() and mo_is_intrinsic_resistant()) and a column selection on two antibiotic groups (aminoglycosides() and carbapenems()), the reference data about all microorganisms and all antibiotics in the AMR package make sure you get what you meant:

- +
@@ -432,7 +391,7 @@

The latest and unpublished development version can be installed from GitHub using:

 install.packages("remotes") # if you haven't already
-remotes::install_github("msberends/AMR")
+remotes::install_github("msberends/AMR")

You can also download the latest build from our repository: https://github.com/msberends/AMR/raw/master/data-raw/AMR_latest.tar.gz

@@ -494,7 +453,7 @@
  • It analyses the data with convenient functions that use well-known methods.

    @@ -541,22 +500,59 @@ - + +
    +

    License

    + +
    +
    +

    Citation

    + +
    +
    +

    Developers

    + +
    + - -
  • -
  • Added ggplot() method for resistance_predict() +
  • Function betalactams() as additional antbiotic column selector and function filter_betalactams() as additional antbiotic column filter. The group of betalactams consists of all carbapenems, cephalosporins and penicillins.
  • +
  • A ggplot() method for resistance_predict()
  • @@ -306,7 +307,8 @@
  • Updated skimr::skim() usage for MIC values to also include 25th and 75th percentiles
  • Fix for plotting missing MIC/disk diffusion values
  • Updated join functions to always use dplyr join functions if the dplyr package is installed - now also preserving grouped variables
  • -
  • Fix for filtering on antibiotic classes (such as filter_cephalosporins())
  • +
  • Fix for filtering on antibiotic classes (such as filter_cephalosporins()), which now also supports dplyr groups
  • +
  • Antibiotic class selectors (such as cephalosporins()) now maintain the column order from the original data
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c2160931..fb62a95f 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-17T17:42Z +last_built: 2021-05-17T22:52Z 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 9301799d..e15cd0e5 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.9021 + 1.6.0.9044
    @@ -248,6 +248,8 @@ aminoglycosides(only_rsi_columns =FALSE) +betalactams(only_rsi_columns =FALSE) + carbapenems(only_rsi_columns =FALSE)cephalosporins(only_rsi_columns =FALSE) @@ -292,6 +294,7 @@

    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.

    +

    The group of betalactams consists of all carbapenems, cephalosporins and penicillins.

    Stable Lifecycle

    diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index f7308a5b..7db9aa7a 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ AMR (for R) - 1.6.0.9021 + 1.6.0.9044 @@ -259,6 +259,14 @@ ...) +filter_betalactams( + x, + result =NULL, + scope ="any", + only_rsi_columns =FALSE, + ... +) + filter_carbapenems(x, result =NULL, @@ -395,6 +403,7 @@

    Details

    All columns of x will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g. filter_aminoglycosides() will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.

    +

    The group of betalactams consists of all carbapenems, cephalosporins and penicillins.

    Stable Lifecycle

    diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index 27929725..d33270c0 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -83,7 +83,7 @@ AMR (for R) - 1.6.0.9021 + 1.6.0.9044 @@ -375,7 +375,7 @@

    Details

    To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below.

    -

    These functions are context-aware. This means that then the x argument can be left blank, see Examples.

    +

    These functions are context-aware. This means that the x argument can be left blank if used inside a data.frame call, 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.

    Different methods

    diff --git a/docs/reference/index.html b/docs/reference/index.html index ab8509b3..90f35cee 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 @@ -526,13 +526,13 @@ diff --git a/docs/reference/key_antimicrobials.html b/docs/reference/key_antimicrobials.html index 503a497b..6ceb6dfc 100644 --- a/docs/reference/key_antimicrobials.html +++ b/docs/reference/key_antimicrobials.html @@ -82,7 +82,7 @@ AMR (for R) - 1.6.0.9021 + 1.6.0.9044 @@ -323,7 +323,7 @@

    Details

    -

    The key_antimicrobials() and all_antimicrobials() functions are context-aware. This means that then the x argument can be left blank, see Examples.

    +

    The key_antimicrobials() and all_antimicrobials() functions are context-aware. This means that the x argument can be left blank if used inside a data.frame call, see Examples.

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

    Please see the first_isolate() function how these important functions enable the 'phenotype-based' method for determination of first isolates.

    The default antimicrobial agents used for all rows (set in universal) are:

      diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index c16f313f..5c7e45e0 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -82,7 +82,7 @@ AMR (for R) - 1.6.0.9021 + 1.6.0.9044 @@ -330,7 +330,7 @@ Ordered factor with levels Details -

      These functions are context-aware. This means that then the x argument can be left blank, see Examples.

      +

      These functions are context-aware. This means that the x argument can be left blank if used inside a data.frame call, 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).

      Note: Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named order Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu et al. in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this mdro() function makes sure that results from before 2016 and after 2016 are identical.

      Supported International / National Guidelines

      diff --git a/docs/survey.html b/docs/survey.html index 54586883..64c890fd 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9043 + 1.6.0.9044 diff --git a/inst/tinytest/test-ab_class_selectors.R b/inst/tinytest/test-ab_class_selectors.R index 76bf9a23..824a139a 100644 --- a/inst/tinytest/test-ab_class_selectors.R +++ b/inst/tinytest/test-ab_class_selectors.R @@ -23,20 +23,21 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -if (pkg_is_available("dplyr")) { - expect_true(example_isolates %>% select(aminoglycosides()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(carbapenems()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins_1st()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins_2nd()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins_3rd()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins_4th()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(cephalosporins_5th()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(fluoroquinolones()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(glycopeptides()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(macrolides()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(oxazolidinones()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(penicillins()) %>% ncol() < ncol(example_isolates)) - expect_true(example_isolates %>% select(tetracyclines()) %>% ncol() < ncol(example_isolates)) +if (as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) >= 3.2) { + # antibiotic class selectors require at least R-3.2 + expect_true(ncol(example_isolates[, aminoglycosides(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, betalactams(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, carbapenems(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins_1st(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins_2nd(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins_3rd(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins_4th(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, cephalosporins_5th(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, fluoroquinolones(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, glycopeptides(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, macrolides(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, oxazolidinones(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, penicillins(), drop = FALSE]) < ncol(example_isolates)) + expect_true(ncol(example_isolates[, tetracyclines(), drop = FALSE]) < ncol(example_isolates)) } - diff --git a/inst/tinytest/test-filter_ab_class.R b/inst/tinytest/test-filter_ab_class.R index a8132cf5..60d36f64 100644 --- a/inst/tinytest/test-filter_ab_class.R +++ b/inst/tinytest/test-filter_ab_class.R @@ -26,13 +26,14 @@ if (pkg_is_available("dplyr")) { expect_true(example_isolates %>% filter_ab_class("carbapenem") %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_aminoglycosides() %>% nrow() < nrow(example_isolates)) + expect_true(example_isolates %>% filter_betalactams() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_carbapenems() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_cephalosporins() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_1st_cephalosporins() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_2nd_cephalosporins() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_3rd_cephalosporins() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_4th_cephalosporins() %>% nrow() < nrow(example_isolates)) - expect_true(example_isolates %>% filter_5th_cephalosporins() %>% nrow() < nrow(example_isolates)) + expect_true(example_isolates %>% mutate(ceftaroline = CTX) %>% filter_5th_cephalosporins() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_fluoroquinolones() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_glycopeptides() %>% nrow() < nrow(example_isolates)) expect_true(example_isolates %>% filter_macrolides() %>% nrow() < nrow(example_isolates)) diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd index 9d1edea0..25cf0d12 100644 --- a/man/antibiotic_class_selectors.Rd +++ b/man/antibiotic_class_selectors.Rd @@ -4,6 +4,7 @@ \alias{antibiotic_class_selectors} \alias{ab_class} \alias{aminoglycosides} +\alias{betalactams} \alias{carbapenems} \alias{cephalosporins} \alias{cephalosporins_1st} @@ -23,6 +24,8 @@ ab_class(ab_class, only_rsi_columns = FALSE) aminoglycosides(only_rsi_columns = FALSE) +betalactams(only_rsi_columns = FALSE) + carbapenems(only_rsi_columns = FALSE) cephalosporins(only_rsi_columns = FALSE) @@ -61,6 +64,8 @@ These functions help to select the columns of antibiotics that are of a specific \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, "."), "")}} 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. + +The group of betalactams consists of all carbapenems, cephalosporins and penicillins. } \section{Stable Lifecycle}{ diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index f019b185..678c1615 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -3,6 +3,7 @@ \name{filter_ab_class} \alias{filter_ab_class} \alias{filter_aminoglycosides} +\alias{filter_betalactams} \alias{filter_carbapenems} \alias{filter_cephalosporins} \alias{filter_1st_cephalosporins} @@ -35,6 +36,14 @@ filter_aminoglycosides( ... ) +filter_betalactams( + x, + result = NULL, + scope = "any", + only_rsi_columns = FALSE, + ... +) + filter_carbapenems( x, result = NULL, @@ -157,6 +166,8 @@ Filter isolates on results in specific antimicrobial classes. This makes it easy } \details{ All columns of \code{x} will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g. \code{\link[=filter_aminoglycosides]{filter_aminoglycosides()}} will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. + +The group of betalactams consists of all carbapenems, cephalosporins and penicillins. } \section{Stable Lifecycle}{
    bacteria AMK
    -

    ab_class() aminoglycosides() carbapenems() cephalosporins() cephalosporins_1st() cephalosporins_2nd() cephalosporins_3rd() cephalosporins_4th() cephalosporins_5th() fluoroquinolones() glycopeptides() macrolides() oxazolidinones() penicillins() tetracyclines()

    +

    ab_class() aminoglycosides() betalactams() carbapenems() cephalosporins() cephalosporins_1st() cephalosporins_2nd() cephalosporins_3rd() cephalosporins_4th() cephalosporins_5th() fluoroquinolones() glycopeptides() macrolides() oxazolidinones() penicillins() tetracyclines()

    Antibiotic Class Selectors

    -

    filter_ab_class() filter_aminoglycosides() filter_carbapenems() filter_cephalosporins() filter_1st_cephalosporins() filter_2nd_cephalosporins() filter_3rd_cephalosporins() filter_4th_cephalosporins() filter_5th_cephalosporins() filter_fluoroquinolones() filter_glycopeptides() filter_macrolides() filter_oxazolidinones() filter_penicillins() filter_tetracyclines()

    +

    filter_ab_class() filter_aminoglycosides() filter_betalactams() filter_carbapenems() filter_cephalosporins() filter_1st_cephalosporins() filter_2nd_cephalosporins() filter_3rd_cephalosporins() filter_4th_cephalosporins() filter_5th_cephalosporins() filter_fluoroquinolones() filter_glycopeptides() filter_macrolides() filter_oxazolidinones() filter_penicillins() filter_tetracyclines()

    Filter Isolates on Result in Antimicrobial Class