diff --git a/DESCRIPTION b/DESCRIPTION index 2f8fe91d..d959183a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.2.0.9006 -Date: 2020-06-11 +Version: 1.2.0.9007 +Date: 2020-06-17 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index da462f62..cd554d43 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -75,6 +75,7 @@ export(ab_tradenames) export(ab_url) export(age) export(age_groups) +export(aminoglycosides) export(anti_join_microorganisms) export(as.ab) export(as.disk) @@ -87,7 +88,14 @@ export(atc_online_property) export(availability) export(brmo) export(bug_drug_combinations) +export(carbapenems) export(catalogue_of_life_version) +export(cephalosporins) +export(cephalosporins_1st) +export(cephalosporins_2nd) +export(cephalosporins_3rd) +export(cephalosporins_4th) +export(cephalosporins_5th) export(count_I) export(count_IR) export(count_R) @@ -117,6 +125,7 @@ export(filter_macrolides) export(filter_penicillins) export(filter_tetracyclines) export(first_isolate) +export(fluoroquinolones) export(full_join_microorganisms) export(g.test) export(geom_rsi) @@ -125,6 +134,7 @@ export(get_mo_source) export(ggplot_pca) export(ggplot_rsi) export(ggplot_rsi_predict) +export(glycopeptides) export(guess_ab_col) export(inner_join_microorganisms) export(is.ab) @@ -139,6 +149,7 @@ export(kurtosis) export(labels_rsi_count) export(left_join_microorganisms) export(like) +export(macrolides) export(mdr_cmi2012) export(mdr_tb) export(mdro) @@ -172,6 +183,7 @@ export(mrgn) export(n_rsi) export(p_symbol) export(pca) +export(penicillins) export(portion_I) export(portion_IR) export(portion_R) @@ -195,6 +207,7 @@ export(semi_join_microorganisms) export(set_mo_source) export(skewness) export(susceptibility) +export(tetracyclines) export(theme_rsi) importFrom(graphics,arrows) importFrom(graphics,axis) diff --git a/NEWS.md b/NEWS.md index dd1ee8a2..23bd33fb 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,15 +1,29 @@ -# AMR 1.2.0.9006 -## Last updated: 11-Jun-2020 +# AMR 1.2.0.9007 +## Last updated: 17-Jun-2020 + +### New +* [Tidyverse selections](https://tidyselect.r-lib.org/reference/language.html), that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like `dplyr::select()` and `tidyr::pivot_longer()`: + ```r + library(dplyr) + + example_isolates %>% + select(carbapenems()) + #> Selecting carbapenems: `IPM` (imipenem), `MEM` (meropenem) + + tibble(J01CA01 = "S") %>% + select(penicillins()) + #> Selecting beta-lactams/penicillins: `J01CA01` (ampicillin) + ``` ### Changed * Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded * All `*_join_microorganisms()` functions now return the original data class (e.g. tibbles and data.tables) * Fixed a bug where `as.ab()` would return an error on invalid input values -* Fixed a bug for using grouped versions of `rsi_df()`, `proportion_df()` and `count_df()` +* Fixed a bug for using grouped versions of `rsi_df()`, `proportion_df()` and `count_df()`, and fixed a bug where not all different antimicrobial results were added as rows * Added function `filter_penicillins()` to filter isolates on a specific result in any column with a name in the antimicrobial 'penicillins' class (more specific: ATC subgroup *Beta-lactam antibacterials, penicillins*) * Added official antimicrobial names to all `filter_ab_class()` functions, such as `filter_aminoglycosides()` * Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set -* Improved auto-determination for columns of types and +* Improved auto-determination for columns of types `` and `` # AMR 1.2.0 diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R new file mode 100644 index 00000000..e1c65f0e --- /dev/null +++ b/R/ab_class_selectors.R @@ -0,0 +1,159 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2018-2020 Berends MS, Luz CF et al. # +# # +# This R package is free software; you can freely use and distribute # +# it for both personal and commercial purposes under the terms of the # +# GNU General Public License version 2.0 (GNU GPL-2), as published by # +# the Free Software Foundation. # +# # +# We created this package for both routine data analysis and academic # +# research and it was publicly released in the hope that it will be # +# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # +# Visit our website for more info: https://msberends.gitlab.io/AMR. # +# ==================================================================== # + +#' Antibiotic class selectors +#' +#' Use these selection helpers inside any function that allows [Tidyverse selections](https://tidyselect.r-lib.org/reference/language.html), like `dplyr::select()` or `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. +#' @details All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). 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 if the `tidyselect` package is installed, that comes with the `dplyr` package. An error will be thrown if `tidyselect` package is not installed, or if the functions are used outside a function that allows Tidyverse selections like `select()` or `pivot_longer()`. +#' @rdname antibiotic_class_selectors +#' @seealso [filter_ab_class()] for the `filter()` equivalent. +#' @name antibiotic_class_selectors +#' @export +#' @examples +#' if (require("dplyr")) { +#' +#' # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): +#' example_isolates %>% +#' select(carbapenems()) +#' +#' +#' # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB': +#' example_isolates %>% +#' select(mo, aminoglycosides()) +#' +#' +#' data.frame(irrelevant = "value", +#' J01CA01 = "S") %>% # ATC code of ampicillin +#' select(penicillins()) # so the 'J01CA01' column is selected +#' +#' } +aminoglycosides <- function() { + ab_selector("aminoglycoside") +} + +#' @rdname antibiotic_class_selectors +#' @export +carbapenems <- function() { + ab_selector("carbapenem") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins <- function() { + ab_selector("cephalosporin") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins_1st <- function() { + ab_selector("cephalosporins.*1") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins_2nd <- function() { + ab_selector("cephalosporins.*2") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins_3rd <- function() { + ab_selector("cephalosporins.*3") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins_4th <- function() { + ab_selector("cephalosporins.*4") +} + +#' @rdname antibiotic_class_selectors +#' @export +cephalosporins_5th <- function() { + ab_selector("cephalosporins.*5") +} + +#' @rdname antibiotic_class_selectors +#' @export +fluoroquinolones <- function() { + ab_selector("fluoroquinolone") +} + +#' @rdname antibiotic_class_selectors +#' @export +glycopeptides <- function() { + ab_selector("glycopeptide") +} + +#' @rdname antibiotic_class_selectors +#' @export +macrolides <- function() { + ab_selector("macrolide") +} + +#' @rdname antibiotic_class_selectors +#' @export +penicillins <- function() { + ab_selector("penicillin") +} + +#' @rdname antibiotic_class_selectors +#' @export +tetracyclines <- function() { + ab_selector("tetracycline") +} + +ab_selector <- function(ab_class, vars = NULL) { + + stopifnot_installed_package("tidyselect") + peek_vars_tidyselect <- get("peek_vars", envir = asNamespace("tidyselect")) + + vars_vct <- peek_vars_tidyselect(fn = ab_class) + vars_df <- data.frame(as.list(vars_vct))[0, , drop = FALSE] + colnames(vars_df) <- vars_vct + ab_in_data <- suppressMessages(get_column_abx(vars_df)) + + if (length(ab_in_data) == 0) { + message(font_blue("NOTE: no antimicrobial agents found.")) + return(NULL) + } + + ab_reference <- subset(antibiotics, + group %like% ab_class | + atc_group1 %like% ab_class | + atc_group2 %like% ab_class) + ab_group <- find_ab_group(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 (length(agents) == 0) { + message(font_blue(paste0("NOTE: no antimicrobial agents of class ", ab_group, + " found (such as ", find_ab_names(ab_class, 2), + ")."))) + } else { + message(font_blue(paste0("Selecting ", ab_group, ": ", + paste(paste0("`", font_bold(agents, collapse = NULL), + "` (", ab_name(names(agents), tolower = TRUE, language = NULL), ")"), + collapse = ", ")))) + } + unname(agents) +} diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index 9d51b6e9..6a553e75 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -24,12 +24,13 @@ #' Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside, or to filter on carbapenem-resistant isolates without the need to specify the drugs. #' @inheritSection lifecycle Stable lifecycle #' @param x a data set -#' @param ab_class an antimicrobial class, like `"carbapenems"`, as can be found in [`antibiotics$group`][antibiotics] +#' @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 result an antibiotic result: S, I or R (or a combination of more of them) #' @param scope the scope to check which variables to check, can be `"any"` (default) or `"all"` #' @param ... parameters passed on to `filter_at` from the `dplyr` package -#' @details The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched for the input given in `ab_class` (case-insensitive). Next, `x` will be checked for column names with a value in any abbreviation, code or official name found in the [antibiotics] data set. +#' @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. #' @rdname filter_ab_class +#' @seealso [antibiotic_class_selectors()] for the `select()` equivalent. #' @export #' @examples #' \dontrun{ @@ -329,6 +330,7 @@ filter_tetracyclines <- function(x, } find_ab_group <- function(ab_class) { + ab_class <- gsub("[^a-zA-Z0-9]", ".*", ab_class) ifelse(ab_class %in% c("aminoglycoside", "carbapenem", "cephalosporin", @@ -344,12 +346,14 @@ find_ab_group <- function(ab_class) { pull(group) %>% unique() %>% tolower() %>% + sort() %>% paste(collapse = "/") ) } find_ab_names <- function(ab_group, n = 3) { - drugs <- antibiotics[which(antibiotics$group %like% ab_group), "name"] + ab_group <- gsub("[^a-zA-Z0-9]", ".*", ab_group) + drugs <- antibiotics[which(antibiotics$group %like% ab_group & !antibiotics$ab %like% "[0-9]$"), ]$name paste0(sort(ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE), tolower = TRUE, language = NULL)), collapse = ", ") diff --git a/R/rsi_calc.R b/R/rsi_calc.R index 369785a3..e546083d 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -282,7 +282,9 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" } else if (isTRUE(combine_IR)) { out$interpretation <- factor(out$interpretation, levels = c("S", "IR"), ordered = TRUE) } else { - out$interpretation <- as.rsi(out$interpretation) + # don't use as.rsi() here, as it would add the class and we would like + # the same data structure as output, regardless of input + out$interpretation <- factor(out$interpretation, levels = c("S", "I", "R"), ordered = TRUE) } if (data_has_groups) { diff --git a/_pkgdown.yml b/_pkgdown.yml index 614f9ab0..4d144008 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -124,6 +124,7 @@ reference: - "`bug_drug_combinations`" - "`resistance_predict`" - "`pca`" + - "`antibiotic_class_selectors`" - "`filter_ab_class`" - "`g.test`" - "`ggplot_rsi`" diff --git a/docs/404.html b/docs/404.html index a674a1f9..b5cae315 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index b08bef1a..00f0bec5 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 diff --git a/docs/articles/index.html b/docs/articles/index.html index cbd03f55..a76ecdcd 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 diff --git a/docs/authors.html b/docs/authors.html index ed6ba49f..aa508916 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 diff --git a/docs/index.html b/docs/index.html index a4c8bb6f..144caf74 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 diff --git a/docs/news/index.html b/docs/news/index.html index e7000407..10ca6320 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9006 + 1.2.0.9007 @@ -229,14 +229,32 @@ Source: NEWS.md -
-

-AMR 1.2.0.9006 Unreleased +
+

+AMR 1.2.0.9007 Unreleased

-
+

-Last updated: 11-Jun-2020 +Last updated: 17-Jun-2020

+
+

+New

+
    +
  • +

    Tidyverse selections, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows Tidyverse selections, like dplyr::select() and tidyr::pivot_longer():

    +
    library(dplyr)
    +
    +example_isolates %>%
    +  select(carbapenems())
    +#> Selecting carbapenems: `IPM` (imipenem), `MEM` (meropenem)
    +
    +tibble(J01CA01 = "S") %>%
    +  select(penicillins())
    +#> Selecting beta-lactams/penicillins: `J01CA01` (ampicillin)
    +
  • +
+

Changed

@@ -244,13 +262,12 @@
  • Fixed a bug where eucast_rules() would not work on a tibble when the tibble or dplyr package was loaded
  • All *_join_microorganisms() functions now return the original data class (e.g. tibbles and data.tables)
  • Fixed a bug where as.ab() would return an error on invalid input values
  • -
  • Fixed a bug for using grouped versions of rsi_df(), proportion_df() and count_df() -
  • +
  • Fixed a bug for using grouped versions of rsi_df(), proportion_df() and count_df(), and fixed a bug where not all different antimicrobial results were added as rows
  • Added function filter_penicillins() to filter isolates on a specific result in any column with a name in the antimicrobial ‘penicillins’ class (more specific: ATC subgroup Beta-lactam antibacterials, penicillins)
  • Added official antimicrobial names to all filter_ab_class() functions, such as filter_aminoglycosides()
  • Added antibiotics code “FOX1” for cefoxitin screening (abbreviation “cfsc”) to the antibiotics data set
  • -
  • Improved auto-determination for columns of types and +
  • Improved auto-determination for columns of types <mo> and <Date>
  • @@ -324,9 +341,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/

    AMR 1.1.0 2020-04-15

    -
    +

    -New

    +New

    • Support for easy principal component analysis for AMR, using the new pca() function
    • Plotting biplots for principal component analysis using the new ggplot_pca() function
    • @@ -373,11 +390,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
    • Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline

    • Interpretation from MIC values (and disk zones) to R/SI can now be used with mutate_at() of the dplyr package:

      -
      yourdata %>%
      -  mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli")
      +
      yourdata %>%
      +  mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli")
       
       yourdata %>%
      -  mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = .$mybacteria)
      + mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = .$mybacteria)
    • Added antibiotic abbreviations for a laboratory manufacturer (GLIMS) for cefuroxime, cefotaxime, ceftazidime, cefepime, cefoxitin and trimethoprim/sulfamethoxazole

    • Added uti (as abbreviation of urinary tract infections) as parameter to as.rsi(), so interpretation of MIC values and disk zones can be made dependent on isolates specifically from UTIs

    • @@ -390,9 +407,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ AMR 1.0.0 2020-02-17

      This software is now out of beta and considered stable. Nonetheless, this package will be developed continually.

      -
      +

      -New

      +New
      • Support for the newest EUCAST Clinical Breakpoint Tables v.10.0, valid from 1 January 2020. This affects translation of MIC and disk zones using as.rsi() and inferred resistance and susceptibility using eucast_rules().
      • The repository of this package now contains a clean version of the EUCAST and CLSI guidelines from 2011-2020 to translate MIC and disk diffusion values to R/SI: https://gitlab.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt. This allows for machine reading these guidelines, which is almost impossible with the Excel and PDF files distributed by EUCAST and CLSI. This file used to process the EUCAST Clinical Breakpoints Excel file can be found here.
      • @@ -400,7 +417,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
        • Support for LOINC codes in the antibiotics data set. Use ab_loinc() to retrieve LOINC codes, or use a LOINC code for input in any ab_* function:

          -
          ab_loinc("ampicillin")
          +
          ab_loinc("ampicillin")
           #> [1] "21066-6" "3355-5"  "33562-0" "33919-2" "43883-8" "43884-6" "87604-5"
           ab_name("21066-6")
           #> [1] "Ampicillin"
          @@ -409,7 +426,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           
        • Support for SNOMED CT codes in the microorganisms data set. Use mo_snomed() to retrieve SNOMED codes, or use a SNOMED code for input in any mo_* function:

          -
          mo_snomed("S. aureus")
          +
          mo_snomed("S. aureus")
           #> [1] 115329001   3092008 113961008
           mo_name(115329001)
           #> [1] "Staphylococcus aureus"
          @@ -472,21 +489,21 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           
          • If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:

            -
            if (mo_family(somebugs) == "Enterobacteriaceae") ...
            +
            if (mo_family(somebugs) == "Enterobacteriaceae") ...

            then please adjust this to:

            -
            if (mo_order(somebugs) == "Enterobacterales") ...
            +
            if (mo_order(somebugs) == "Enterobacterales") ...
      -
      +

      -New

      +New
      • Functions susceptibility() and resistance() as aliases of proportion_SI() and proportion_R(), respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.

        -
        library(dplyr)
        +
        library(dplyr)
         example_isolates %>%
           group_by(bug = mo_name(mo)) %>%
           summarise(amoxicillin = resistance(AMX),
        @@ -513,7 +530,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
         
      • More intelligent way of coping with some consonants like “l” and “r”

      • Added a score (a certainty percentage) to mo_uncertainties(), that is calculated using the Levenshtein distance:

        -
        as.mo(c("Stafylococcus aureus",
        +
        as.mo(c("Stafylococcus aureus",
                 "staphylokok aureuz"))
         #> Warning: 
         #> Results of two values were guessed with uncertainty. Use mo_uncertainties() to review them.
        @@ -570,12 +587,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
         
        • Determination of first isolates now excludes all ‘unknown’ microorganisms at default, i.e. microbial code "UNKNOWN". They can be included with the new parameter include_unknown:

          -
          first_isolate(..., include_unknown = TRUE)
          +
          first_isolate(..., include_unknown = TRUE)

          For WHONET users, this means that all records/isolates with organism code "con" (contamination) will be excluded at default, since as.mo("con") = "UNKNOWN". The function always shows a note with the number of ‘unknown’ microorganisms that were included or excluded.

        • For code consistency, classes ab and mo will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in NA:

          -
          # how it works in base R:
          +
          # how it works in base R:
           x <- factor("A")
           x[1] <- "B"
           #> Warning message:
          @@ -592,13 +609,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           
        • Renamed data set septic_patients to example_isolates

        -
        +

        -New

        +New
        • Function bug_drug_combinations() to quickly get a data.frame with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed with mo_shortname() at default:

          -
          x <- bug_drug_combinations(example_isolates)
          +
          x <- bug_drug_combinations(example_isolates)
           #> NOTE: Using column `mo` as input for `col_mo`.
           x[1:4, ]
           #>             mo  ab S I R total
          @@ -619,11 +636,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           #> 4 Gram-negative AMX 227  0 405   632
           #> NOTE: Use 'format()' on this result to get a publicable/printable format.

          You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R format() function:

          -
          format(x, combine_IR = FALSE)
          +
          format(x, combine_IR = FALSE)
        • Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for portion_* functions or count_* functions. This can be used to determine the empiric susceptibility of a combination therapy. A new parameter only_all_tested (which defaults to FALSE) replaces the old also_single_tested and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the portion and count help pages), where the %SI is being determined:

          -
          # --------------------------------------------------------------------
          +
          # --------------------------------------------------------------------
           #                     only_all_tested = FALSE  only_all_tested = TRUE
           #                     -----------------------  -----------------------
           #  Drug A    Drug B   include as  include as   include as  include as
          @@ -643,7 +660,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           
        • tibble printing support for classes rsi, mic, disk, ab mo. When using tibbles containing antimicrobial columns, values S will print in green, values I will print in yellow and values R will print in red. Microbial IDs (class mo) will emphasise on the genus and species, not on the kingdom.

          -
          # (run this on your own console, as this page does not support colour printing)
          +
          # (run this on your own console, as this page does not support colour printing)
           library(dplyr)
           example_isolates %>%
             select(mo:AMC) %>%
          @@ -718,13 +735,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           

          AMR 0.7.1 2019-06-23

          -
          +

          -New

          +New
          • Function rsi_df() to transform a data.frame to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions count_df() and portion_df() to immediately show resistance percentages and number of available isolates:

            -
            septic_patients %>%
            +
            septic_patients %>%
               select(AMX, CIP) %>%
               rsi_df()
             #      antibiotic  interpretation      value  isolates
            @@ -749,7 +766,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
             
          • UPEC (Uropathogenic E. coli)

          All these lead to the microbial ID of E. coli:

          -
          as.mo("UPEC")
          +
          as.mo("UPEC")
           # B_ESCHR_COL
           mo_name("UPEC")
           # "Escherichia coli"
          @@ -799,9 +816,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
           

          AMR 0.7.0 2019-06-03

          -
          +

          -New

          +New
          • Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use as.rsi() on an MIC value (created with as.mic()), a disk diffusion value (created with the new as.disk()) or on a complete date set containing columns with MIC or disk diffusion values.
          • Function mo_name() as alias of mo_fullname() @@ -856,7 +873,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
          • when all values are unique it now shows a message instead of a warning

          • support for boxplots:

            -
            septic_patients %>%
            +
            septic_patients %>%
               freq(age) %>%
               boxplot()
             # grouped boxplots:
            @@ -916,9 +933,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
             
          • Contains the complete manual of this package and all of its functions with an explanation of their parameters
          • Contains a comprehensive tutorial about how to conduct antimicrobial resistance analysis, import data from WHONET or SPSS and many more.
          -
          +

          -New

          +New
          • BREAKING: removed deprecated functions, parameters and references to ‘bactid’. Use as.mo() to identify an MO code.

          • @@ -947,7 +964,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
          • New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:

            -
            filter_aminoglycosides()
            +
            filter_aminoglycosides()
             filter_carbapenems()
             filter_cephalosporins()
             filter_1st_cephalosporins()
            @@ -959,14 +976,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
             filter_macrolides()
             filter_tetracyclines()

            The antibiotics data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the antibiotics data set. For example:

            -
            septic_patients %>% filter_glycopeptides(result = "R")
            +
            septic_patients %>% filter_glycopeptides(result = "R")
             # Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R
             septic_patients %>% filter_glycopeptides(result = "R", scope = "all")
             # Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is R
          • All ab_* functions are deprecated and replaced by atc_* functions:

            -
            ab_property -> atc_property()
            +
            ab_property -> atc_property()
             ab_name -> atc_name()
             ab_official -> atc_official()
             ab_trivial_nl -> atc_trivial_nl()
            @@ -985,17 +1002,17 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
             
          • New function age_groups() to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.

          • New function ggplot_rsi_predict() as well as the base R plot() function can now be used for resistance prediction calculated with resistance_predict():

            -
            x <- resistance_predict(septic_patients, col_ab = "amox")
            +
            x <- resistance_predict(septic_patients, col_ab = "amox")
             plot(x)
             ggplot_rsi_predict(x)
          • Functions filter_first_isolate() and filter_first_weighted_isolate() to shorten and fasten filtering on data sets with antimicrobial results, e.g.:

            -
            septic_patients %>% filter_first_isolate(...)
            +
            septic_patients %>% filter_first_isolate(...)
             # or
             filter_first_isolate(septic_patients, ...)

            is equal to:

            -
            septic_patients %>%
            +
            septic_patients %>%
               mutate(only_firsts = first_isolate(septic_patients, ...)) %>%
               filter(only_firsts == TRUE) %>%
               select(-only_firsts)
            @@ -1026,7 +1043,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
            • Now handles incorrect spelling, like i instead of y and f instead of ph:

              -
              # mo_fullname() uses as.mo() internally
              +
              # mo_fullname() uses as.mo() internally
               
               mo_fullname("Sthafilokockus aaureuz")
               #> [1] "Staphylococcus aureus"
              @@ -1036,7 +1053,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
               
            • Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default allow_uncertain = TRUE is equal to uncertainty level 2. Run ?as.mo for more info about these levels.

              -
              # equal:
              +
              # equal:
               as.mo(..., allow_uncertain = TRUE)
               as.mo(..., allow_uncertain = 2)
               
              @@ -1049,7 +1066,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
               
            • All microbial IDs that found are now saved to a local file ~/.Rhistory_mo. Use the new function clean_mo_history() to delete this file, which resets the algorithms.

            • Incoercible results will now be considered ‘unknown’, MO code UNKNOWN. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:

              -
              mo_genus("qwerty", language = "es")
              +
              mo_genus("qwerty", language = "es")
               # Warning: 
               # one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it.
               #> [1] "(género desconocido)"
              @@ -1097,7 +1114,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
              • Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:

                -
                # Determine genus of microorganisms (mo) in `septic_patients` data set:
                +
                # Determine genus of microorganisms (mo) in `septic_patients` data set:
                 # OLD WAY
                 septic_patients %>%
                   mutate(genus = mo_genus(mo)) %>%
                @@ -1142,9 +1159,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                 

                AMR 0.5.0 2018-11-30

                -
                +

                -New

                +New
                • Repository moved to GitLab: https://gitlab.com/msberends/AMR
                • @@ -1180,7 +1197,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                • Fewer than 3 characters as input for as.mo will return NA

                • Function as.mo (and all mo_* wrappers) now supports genus abbreviations with “species” attached

                  -
                  as.mo("E. species")        # B_ESCHR
                  +
                  as.mo("E. species")        # B_ESCHR
                   mo_fullname("E. spp.")     # "Escherichia species"
                   as.mo("S. spp")            # B_STPHY
                   mo_fullname("S. species")  # "Staphylococcus species"
                  @@ -1195,13 +1212,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                  • Support for grouping variables, test with:

                    -
                    septic_patients %>%
                    +
                    septic_patients %>%
                       group_by(hospital_id) %>%
                       freq(gender)
                  • Support for (un)selecting columns:

                    -
                    septic_patients %>%
                    +
                    septic_patients %>%
                       freq(hospital_id) %>%
                       select(-count, -cum_count) # only get item, percent, cum_percent
                  • @@ -1261,9 +1278,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/

                    AMR 0.4.0 2018-10-01

                    -
                    +

                    -New

                    +New
                    • The data set microorganisms now contains all microbial taxonomic data from ITIS (kingdoms Bacteria, Fungi and Protozoa), the Integrated Taxonomy Information System, available via https://itis.gov. The data set now contains more than 18,000 microorganisms with all known bacteria, fungi and protozoa according ITIS with genus, species, subspecies, family, order, class, phylum and subkingdom. The new data set microorganisms.old contains all previously known taxonomic names from those kingdoms.

                    • @@ -1279,7 +1296,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/

                    They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:

                    -
                    mo_gramstain("E. coli")
                    +
                    mo_gramstain("E. coli")
                     # [1] "Gram negative"
                     mo_gramstain("E. coli", language = "de") # German
                     # [1] "Gramnegativ"
                    @@ -1288,7 +1305,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                     mo_fullname("S. group A", language = "pt") # Portuguese
                     # [1] "Streptococcus grupo A"

                    Furthermore, former taxonomic names will give a note about the current taxonomic name:

                    -
                    mo_gramstain("Esc blattae")
                    +
                    mo_gramstain("Esc blattae")
                     # Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)
                     # [1] "Gram negative"
                    @@ -1301,14 +1318,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                  • Function is.rsi.eligible to check for columns that have valid antimicrobial results, but do not have the rsi class yet. Transform the columns of your raw data with: data %>% mutate_if(is.rsi.eligible, as.rsi)

                  • Functions as.mo and is.mo as replacements for as.bactid and is.bactid (since the microoganisms data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The as.mo function determines microbial IDs using intelligent rules:

                    -
                    as.mo("E. coli")
                    +
                    as.mo("E. coli")
                     # [1] B_ESCHR_COL
                     as.mo("MRSA")
                     # [1] B_STPHY_AUR
                     as.mo("S group A")
                     # [1] B_STRPTC_GRA

                    And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:

                    -
                    thousands_of_E_colis <- rep("E. coli", 25000)
                    +
                    thousands_of_E_colis <- rep("E. coli", 25000)
                     microbenchmark::microbenchmark(as.mo(thousands_of_E_colis), unit = "s")
                     # Unit: seconds
                     #         min       median         max  neval
                    @@ -1340,7 +1357,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                     
                  • Added three antimicrobial agents to the antibiotics data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)

                  • Added 163 trade names to the antibiotics data set, it now contains 298 different trade names in total, e.g.:

                    -
                    ab_official("Bactroban")
                    +
                    ab_official("Bactroban")
                     # [1] "Mupirocin"
                     ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen"))
                     # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin"
                    @@ -1355,7 +1372,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                     
                  • Added parameters minimum and as_percent to portion_df

                  • Support for quasiquotation in the functions series count_* and portions_*, and n_rsi. This allows to check for more than 2 vectors or columns.

                    -
                    septic_patients %>% select(amox, cipr) %>% count_IR()
                    +
                    septic_patients %>% select(amox, cipr) %>% count_IR()
                     # which is the same as:
                     septic_patients %>% count_IR(amox, cipr)
                     
                    @@ -1373,10 +1390,10 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
                     
                  • Added longest en shortest character length in the frequency table (freq) header of class character

                  • Support for types (classes) list and matrix for freq

                    -
                    my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
                    +
                    my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
                     freq(my_matrix)

                    For lists, subsetting is possible:

                    -
                    my_list = list(age = septic_patients$age, gender = septic_patients$gender)
                    +
                    my_list = list(age = septic_patients$age, gender = septic_patients$gender)
                     my_list %>% freq(age)
                     my_list %>% freq(gender)
                  • @@ -1394,9 +1411,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/

                    AMR 0.3.0 2018-08-14

                    -
                    +

                    -New

                    +New
                    • BREAKING: rsi_df was removed in favour of new functions portion_R, portion_IR, portion_I, portion_SI and portion_S to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the old rsi function. The old function still works, but is deprecated. @@ -1531,9 +1548,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/

                      AMR 0.2.0 2018-05-03

                      -
                      +

                      -New

                      +New
                      • Full support for Windows, Linux and macOS
                      • Full support for old R versions, only R-3.0.0 (April 2013) or later is needed (needed packages may have other dependencies)
                      • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 373d9ea5..f3164d9f 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -10,7 +10,7 @@ articles: WHONET: WHONET.html benchmarks: benchmarks.html resistance_predict: resistance_predict.html -last_built: 2020-06-11T17:56Z +last_built: 2020-06-16T23:38Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html new file mode 100644 index 00000000..f4e2195b --- /dev/null +++ b/docs/reference/antibiotic_class_selectors.html @@ -0,0 +1,318 @@ + + + + + + + + +Antibiotic class selectors — antibiotic_class_selectors • AMR (for R) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        +
                        + + + + +
                        + +
                        +
                        + + +
                        +

                        Use these selection helpers inside any function that allows Tidyverse selections, like dplyr::select() or 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.

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

                        Details

                        + +

                        All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). 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 if the tidyselect package is installed, that comes with the dplyr package. An error will be thrown if tidyselect package is not installed, or if the functions are used outside a function that allows Tidyverse selections like select() or pivot_longer().

                        +

                        See also

                        + +

                        filter_ab_class() for the filter() equivalent.

                        + +

                        Examples

                        +
                        if (require("dplyr")) {
                        +
                        +  # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
                        +  example_isolates %>%
                        +    select(carbapenems())
                        +
                        +
                        +  # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
                        +  example_isolates %>%
                        +    select(mo, aminoglycosides())
                        +
                        +
                        +  data.frame(irrelevant = "value",
                        +             J01CA01 = "S") %>%   # ATC code of ampicillin
                        +    select(penicillins())         # so the 'J01CA01' column is selected
                        +
                        +}
                        +
                        + +
                        + + + +
                        + + + + + + + + diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 2554f2b0..2dd575ba 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9007
                      @@ -272,7 +272,7 @@ ab_class -

                      an antimicrobial class, like "carbapenems", as can be found in antibiotics$group

                      +

                      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.

                      result @@ -290,7 +290,7 @@

                      Details

                      -

                      The columns group, atc_group1 and atc_group2 of the antibiotics data set will be searched for the input given in ab_class (case-insensitive). Next, x will be checked for column names with a value in any abbreviation, code or official name found in the antibiotics data set.

                      +

                      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.

                      Stable lifecycle

                      @@ -298,6 +298,9 @@


                      The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.

                      If the unlying code needs breaking changes, they will occur gradually. For example, a parameter will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.

                      +

                      See also

                      + +

                      Examples

                      if (FALSE) {
                      diff --git a/docs/reference/index.html b/docs/reference/index.html
                      index 274ff04c..3d951d31 100644
                      --- a/docs/reference/index.html
                      +++ b/docs/reference/index.html
                      @@ -81,7 +81,7 @@
                             
                             
                               AMR (for R)
                      -        1.2.0.9006
                      +        1.2.0.9007
                             
                           
                      diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 38a73684..320f21f0 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -24,6 +24,9 @@ https://msberends.gitlab.io/AMR/reference/age_groups.html + + https://msberends.gitlab.io/AMR/reference/antibiotic_class_selectors.html + https://msberends.gitlab.io/AMR/reference/antibiotics.html diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd new file mode 100644 index 00000000..71e5712b --- /dev/null +++ b/man/antibiotic_class_selectors.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ab_class_selectors.R +\name{antibiotic_class_selectors} +\alias{antibiotic_class_selectors} +\alias{aminoglycosides} +\alias{carbapenems} +\alias{cephalosporins} +\alias{cephalosporins_1st} +\alias{cephalosporins_2nd} +\alias{cephalosporins_3rd} +\alias{cephalosporins_4th} +\alias{cephalosporins_5th} +\alias{fluoroquinolones} +\alias{glycopeptides} +\alias{macrolides} +\alias{penicillins} +\alias{tetracyclines} +\title{Antibiotic class selectors} +\usage{ +aminoglycosides() + +carbapenems() + +cephalosporins() + +cephalosporins_1st() + +cephalosporins_2nd() + +cephalosporins_3rd() + +cephalosporins_4th() + +cephalosporins_5th() + +fluoroquinolones() + +glycopeptides() + +macrolides() + +penicillins() + +tetracyclines() +} +\description{ +Use these selection helpers inside any function that allows \href{https://tidyselect.r-lib.org/reference/language.html}{Tidyverse selections}, like \code{dplyr::select()} or \code{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. +} +\details{ +All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a selector like e.g. \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. + +These functions only work if the \code{tidyselect} package is installed, that comes with the \code{dplyr} package. An error will be thrown if \code{tidyselect} package is not installed, or if the functions are used outside a function that allows Tidyverse selections like \code{select()} or \code{pivot_longer()}. +} +\examples{ +if (require("dplyr")) { + + # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): + example_isolates \%>\% + select(carbapenems()) + + + # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB': + example_isolates \%>\% + select(mo, aminoglycosides()) + + + data.frame(irrelevant = "value", + J01CA01 = "S") \%>\% # ATC code of ampicillin + select(penicillins()) # so the 'J01CA01' column is selected + +} +} +\seealso{ +\code{\link[=filter_ab_class]{filter_ab_class()}} for the \code{filter()} equivalent. +} diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index 44e724ef..c3c7f890 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -48,7 +48,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...) \arguments{ \item{x}{a data set} -\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{\link[=antibiotics]{antibiotics$group}}} +\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{result}{an antibiotic result: S, I or R (or a combination of more of them)} @@ -60,7 +60,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...) Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside, or to filter on carbapenem-resistant isolates without the need to specify the drugs. } \details{ -The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched for the input given in \code{ab_class} (case-insensitive). Next, \code{x} will be checked for column names with a value in any abbreviation, code or official name found in the \link{antibiotics} data set. +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. } \section{Stable lifecycle}{ @@ -103,3 +103,6 @@ example_isolates \%>\% filter_fluoroquinolones("R", "all") } } +\seealso{ +\code{\link[=antibiotic_class_selectors]{antibiotic_class_selectors()}} for the \code{select()} equivalent. +} diff --git a/tests/testthat/test-antibiotic_class_selectors.R b/tests/testthat/test-antibiotic_class_selectors.R new file mode 100644 index 00000000..9f45b70a --- /dev/null +++ b/tests/testthat/test-antibiotic_class_selectors.R @@ -0,0 +1,41 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2018-2020 Berends MS, Luz CF et al. # +# # +# This R package is free software; you can freely use and distribute # +# it for both personal and commercial purposes under the terms of the # +# GNU General Public License version 2.0 (GNU GPL-2), as published by # +# the Free Software Foundation. # +# # +# We created this package for both routine data analysis and academic # +# research and it was publicly released in the hope that it will be # +# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # +# Visit our website for more info: https://msberends.gitlab.io/AMR. # +# ==================================================================== # + +context("ab_class_selectors.R") + +test_that("Antibiotic class selectors work", { + skip_on_cran() + + expect_lt(example_isolates %>% dplyr::select(aminoglycosides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(carbapenems()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_1st()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_2nd()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_3rd()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_4th()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_5th()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(fluoroquinolones()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(glycopeptides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(macrolides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(penicillins()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(tetracyclines()) %>% ncol(), ncol(example_isolates)) + +})