diff --git a/.github/workflows/codecovr.yaml b/.github/workflows/codecovr.yaml index 08ccea5c5..efbd917ad 100644 --- a/.github/workflows/codecovr.yaml +++ b/.github/workflows/codecovr.yaml @@ -61,6 +61,6 @@ jobs: R_LIBS_USER_GH_ACTIONS: ${{ env.R_LIBS_USER }} R_RUN_TINYTEST: true run: | - x <- covr::codecov(line_exclusions = list("R/atc_online.R", "R/mo_source.R", "R/translate.R", "R/resistance_predict.R", "R/aa_helper_functions.R", "R/aa_helper_pm_functions.R", "R/zzz.R")) + x <- covr::codecov(line_exclusions = list("R/atc_online.R", "R/mo_source.R", "R/translate.R", "R/resistance_predict.R", "R/zz_deprecated.R", "R/aa_helper_functions.R", "R/aa_helper_pm_functions.R", "R/zzz.R")) print(x) shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index db2f05409..e02add6c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.8.2.9095 -Date: 2023-01-20 +Version: 1.8.2.9096 +Date: 2023-01-21 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NAMESPACE b/NAMESPACE index 77232b4fb..7e9bfd510 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,7 @@ S3method("[<-",disk) S3method("[<-",mic) S3method("[<-",mo) S3method("[<-",rsi) +S3method("[<-",sir) S3method("[[",ab) S3method("[[",av) S3method("[[",disk) @@ -39,6 +40,7 @@ S3method("[[<-",disk) S3method("[[<-",mic) S3method("[[<-",mo) S3method("[[<-",rsi) +S3method("[[<-",sir) S3method("^",mic) S3method("|",ab_selector) S3method("|",mic) @@ -63,6 +65,10 @@ S3method(as.rsi,data.frame) S3method(as.rsi,default) S3method(as.rsi,disk) S3method(as.rsi,mic) +S3method(as.sir,data.frame) +S3method(as.sir,default) +S3method(as.sir,disk) +S3method(as.sir,mic) S3method(asin,mic) S3method(asinh,mic) S3method(atan,mic) @@ -70,6 +76,7 @@ S3method(atanh,mic) S3method(barplot,disk) S3method(barplot,mic) S3method(barplot,rsi) +S3method(barplot,sir) S3method(c,ab) S3method(c,ab_selector) S3method(c,av) @@ -79,6 +86,7 @@ S3method(c,disk) S3method(c,mic) S3method(c,mo) S3method(c,rsi) +S3method(c,sir) S3method(ceiling,mic) S3method(close,progress_bar) S3method(cos,mic) @@ -91,6 +99,7 @@ S3method(cumsum,mic) S3method(digamma,mic) S3method(droplevels,mic) S3method(droplevels,rsi) +S3method(droplevels,sir) S3method(exp,mic) S3method(expm1,mic) S3method(floor,mic) @@ -111,13 +120,14 @@ S3method(mean_amr_distance,data.frame) S3method(mean_amr_distance,default) S3method(mean_amr_distance,disk) S3method(mean_amr_distance,mic) -S3method(mean_amr_distance,rsi) +S3method(mean_amr_distance,sir) S3method(median,mic) S3method(min,mic) S3method(plot,disk) S3method(plot,mic) S3method(plot,resistance_predict) S3method(plot,rsi) +S3method(plot,sir) S3method(print,ab) S3method(print,av) S3method(print,bug_drug_combinations) @@ -130,6 +140,7 @@ S3method(print,mo_renamed) S3method(print,mo_uncertainties) S3method(print,pca) S3method(print,rsi) +S3method(print,sir) S3method(prod,mic) S3method(quantile,mic) S3method(range,mic) @@ -139,6 +150,7 @@ S3method(rep,disk) S3method(rep,mic) S3method(rep,mo) S3method(rep,rsi) +S3method(rep,sir) S3method(round,mic) S3method(sign,mic) S3method(signif,mic) @@ -155,6 +167,7 @@ S3method(summary,mic) S3method(summary,mo) S3method(summary,pca) S3method(summary,rsi) +S3method(summary,sir) S3method(tan,mic) S3method(tanh,mic) S3method(tanpi,mic) @@ -166,6 +179,7 @@ S3method(unique,disk) S3method(unique,mic) S3method(unique,mo) S3method(unique,rsi) +S3method(unique,sir) export("%like%") export("%like_case%") export("%unlike%") @@ -173,6 +187,7 @@ export("%unlike_case%") export(NA_disk_) export(NA_mic_) export(NA_rsi_) +export(NA_sir_) export(ab_atc) export(ab_atc_group1) export(ab_atc_group2) @@ -210,6 +225,7 @@ export(as.disk) export(as.mic) export(as.mo) export(as.rsi) +export(as.sir) export(atc_online_ddd) export(atc_online_ddd_units) export(atc_online_groups) @@ -255,18 +271,22 @@ export(eucast_dosage) export(eucast_exceptional_phenotypes) export(eucast_rules) export(facet_rsi) +export(facet_sir) export(filter_first_isolate) export(first_isolate) export(fluoroquinolones) export(full_join_microorganisms) export(g.test) export(geom_rsi) +export(geom_sir) export(get_AMR_locale) export(get_episode) export(get_mo_source) export(ggplot_pca) export(ggplot_rsi) export(ggplot_rsi_predict) +export(ggplot_sir) +export(ggplot_sir_predict) export(glycopeptides) export(guess_ab_col) export(inner_join_microorganisms) @@ -277,12 +297,15 @@ export(is.mic) export(is.mo) export(is.rsi) export(is.rsi.eligible) +export(is.sir) export(is_new_episode) +export(is_sir_eligible) export(italicise_taxonomy) export(italicize_taxonomy) export(key_antimicrobials) export(kurtosis) export(labels_rsi_count) +export(labels_sir_count) export(left_join_microorganisms) export(like) export(lincosamides) @@ -333,6 +356,7 @@ export(mo_url) export(mo_year) export(mrgn) export(n_rsi) +export(n_sir) export(not_intrinsic_resistant) export(oxazolidinones) export(pca) @@ -348,25 +372,30 @@ export(quinolones) export(random_disk) export(random_mic) export(random_rsi) +export(random_sir) export(reset_AMR_locale) export(resistance) export(resistance_predict) export(right_join_microorganisms) -export(rsi_confidence_interval) export(rsi_df) -export(rsi_interpretation_history) export(rsi_predict) export(scale_rsi_colours) +export(scale_sir_colours) export(scale_y_percent) export(semi_join_microorganisms) export(set_AMR_locale) export(set_ab_names) export(set_mo_source) +export(sir_confidence_interval) +export(sir_df) +export(sir_interpretation_history) +export(sir_predict) export(skewness) export(streptogramins) export(susceptibility) export(tetracyclines) export(theme_rsi) +export(theme_sir) export(translate_AMR) export(trimethoprims) export(ureidopenicillins) diff --git a/NEWS.md b/NEWS.md index f142415bd..b4e911e3e 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9095 +# AMR 1.8.2.9096 *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* @@ -6,20 +6,29 @@ This is a new major release of the AMR package, with great new additions but als **[TL;DR](https://en.wikipedia.org/wiki/TL;DR)** +* All functions and arguments with 'rsi' were replaced with 'sir', such as the interpretation of MIC values (now `as.sir()` instead of `as.rsi()`) - all old functions still work for now * Microbiological taxonomy (`microorganisms` data set) updated to 2022 and now based on LPSN and GBIF * Much increased algorithms to translate user input to valid taxonomy, e.g. by using [recent scientific work](https://doi.org/10.1099/mic.0.001269) about per-species human pathogenicity * Clinical breakpoints added for EUCAST 2022 and CLSI 2022 * 20 new antibiotics added and updated all DDDs and ATC codes * Extended support for antiviral agents (`antivirals` data set), with many new functions * Now available in 16 languages -* Many new interesting functions, such as `rsi_confidence_interval()` and `mean_amr_distance()`, and `add_custom_microorganisms()` to add custom microorganisms to this package +* Many new interesting functions, such as `sir_confidence_interval()` and `mean_amr_distance()`, and `add_custom_microorganisms()` to add custom microorganisms to this package * Many small bug fixes ## New +### SIR vs. RSI + +For this milestone version, we replaced all mentions of RSI with SIR, to comply with what is actually being commonly used in the field of clinical microbiology when it comes to this tri-form regarding AMR. + +While existing functions such as `as.rsi()`, `rsi_df()` and `ggplot_rsi()` still work, their replacements `as.sir()`, `sir_df()`, `ggplot_sir()` are now the current functions for AMR data analysis. A warning will be thrown once a session to remind users about this. The data set `rsi_translation` is now called `clinical_breakpoints` to better reflect its content. + +The 'RSI functions' will be removed in a future version, but not before late 2023 / early 2024. + ### Interpretation of MIC and disk diffusion values -The clinical breakpoints and intrinsic resistance of EUCAST 2022 and CLSI 2022 have been added for `as.rsi()`. EUCAST 2022 (v12.0) is now the new default guideline for all MIC and disks diffusion interpretations, and for `eucast_rules()` to apply EUCAST Expert Rules. The default guideline (EUCAST) can now be changed with the new `AMR_guideline` option, such as: `options(AMR_guideline = "CLSI 2020")`. +The clinical breakpoints and intrinsic resistance of EUCAST 2022 and CLSI 2022 have been added for `as.sir()`. EUCAST 2022 (v12.0) is now the new default guideline for all MIC and disks diffusion interpretations, and for `eucast_rules()` to apply EUCAST Expert Rules. The default guideline (EUCAST) can now be changed with the new `AMR_guideline` option, such as: `options(AMR_guideline = "CLSI 2020")`. Interpretation guidelines older than 10 years were removed, the oldest now included guidelines of EUCAST and CLSI are from 2013. @@ -64,7 +73,7 @@ The `antibiotics` data set was greatly updated: * Updated DDDs and PubChem Compound IDs * Updated some antibiotic name spelling, now used by WHOCC (such as cephalexin -> cefalexin, and phenethicillin -> pheneticillin) * Antibiotic code "CEI" for ceftolozane/tazobactam has been replaced with "CZT" to comply with EARS-Net and WHONET 2022. The old code will still work in all cases when using `as.ab()` or any of the `ab_*()` functions. - * Support for antimicrobial interpretation of anaerobic bacteria, by adding a 'placeholder' code `B_ANAER` to the `microorganisms` data set and adding the breakpoints of anaerobics to the `rsi_interpretation` data set, which is used by `as.rsi()` for interpretion of MIC and disk diffusion values + * Support for antimicrobial interpretation of anaerobic bacteria, by adding a 'placeholder' code `B_ANAER` to the `microorganisms` data set and adding the breakpoints of anaerobics to the `clinical_breakpoints` data set, which is used by `as.sir()` for interpretion of MIC and disk diffusion values Also, we added support for using antibiotic selectors in scoped `dplyr` verbs (with or without using `vars()`), such as in: `... %>% summarise_at(aminoglycosides(), resistance)`, please see `resistance()` for examples. @@ -78,22 +87,22 @@ We now added extensive support for antiviral agents! For the first time, the `AM ### Other new functions -* Function `rsi_confidence_interval()` to add confidence intervals in AMR calculation. This is now also included in `rsi_df()` and `proportion_df()`. +* Function `sir_confidence_interval()` to add confidence intervals in AMR calculation. This is now also included in `sir_df()` and `proportion_df()`. * Function `mean_amr_distance()` to calculate the mean AMR distance. The mean AMR distance is a normalised numeric value to compare AMR test results and can help to identify similar isolates, without comparing antibiograms by hand. -* Function `rsi_interpretation_history()` to view the history of previous runs of `as.rsi()`. This returns a 'logbook' with the selected guideline, reference table and specific interpretation of each row in a data set on which `as.rsi()` was run. +* Function `sir_interpretation_history()` to view the history of previous runs of `as.sir()` (previously `as.rsi()`). This returns a 'logbook' with the selected guideline, reference table and specific interpretation of each row in a data set on which `as.sir()` was run. * Function `mo_current()` to get the currently valid taxonomic name of a microorganism * Function `add_custom_antimicrobials()` to add custom antimicrobial codes and names to the `AMR` package ## Changes -* Argument `combine_IR` has been removed from this package (affecting functions `count_df()`, `proportion_df()`, and `rsi_df()` and some plotting functions), since it was replaced with `combine_SI` three years ago +* Argument `combine_IR` has been removed from this package (affecting functions `count_df()`, `proportion_df()`, and `sir_df()` and some plotting functions), since it was replaced with `combine_SI` three years ago * Using `units` in `ab_ddd(..., units = "...")` had been deprecated for some time and is now not supported anymore. Use `ab_ddd_units()` instead. -* Support for `data.frame`-enhancing R packages, more specifically: `data.table::data.table`, `janitor::tabyl`, `tibble::tibble`, and `tsibble::tsibble`. AMR package functions that have a data set as output (such as `rsi_df()` and `bug_drug_combinations()`), will now return the same data type as the input. +* Support for `data.frame`-enhancing R packages, more specifically: `data.table::data.table`, `janitor::tabyl`, `tibble::tibble`, and `tsibble::tsibble`. AMR package functions that have a data set as output (such as `sir_df()` and `bug_drug_combinations()`), will now return the same data type as the input. * All data sets in this package are now a `tibble`, instead of base R `data.frame`s. Older R versions are still supported, even if they do not support `tibble`s. * Our data sets are now also continually exported to **Apache Feather and Apache Parquet formats**. You can find more info [in this article on our website](https://msberends.github.io/AMR/articles/datasets.html). -* For `as.rsi()`: +* For `as.sir()`: * Fixed certain EUCAST breakpoints for MIC values - * Allow `NA` values (e.g. `as.rsi(as.disk(NA), ...)`) + * Allow `NA` values (e.g. `as.sir(as.disk(NA), ...)`) * Fix for bug-drug combinations with multiple breakpoints for different body sites * Interpretation from MIC and disk zones is now more informative about availability of breakpoints and more robust * Removed the `as.integer()` method for MIC values, since MIC are not integer values and running `table()` on MIC values consequently failed for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work) @@ -103,17 +112,17 @@ We now added extensive support for antiviral agents! For the first time, the `AM * Fixes for reading in text files using `set_mo_source()`, which now also allows the source file to contain valid taxonomic names instead of only valid microorganism ID of this package * Fixed a bug for `mdro()` when using similar column names with the Magiorakos guideline * Using any `random_*()` function (such as `random_mic()`) is now possible by directly calling the package without loading it first: `AMR::random_mic(10)` -* Extended support for the `vctrs` package, used internally by the tidyverse. This allows to change values of class `mic`, `disk`, `rsi`, `mo` and `ab` in tibbles, and to use antibiotic selectors for selecting/filtering, e.g. `df[carbapenems() == "R", ]` +* Extended support for the `vctrs` package, used internally by the tidyverse. This allows to change values of class `mic`, `disk`, `sir`, `mo` and `ab` in tibbles, and to use antibiotic selectors for selecting/filtering, e.g. `df[carbapenems() == "R", ]` * Fix for using `info = FALSE` in `mdro()` -* For all interpretation guidelines using `as.rsi()` on amoxicillin, the rules for ampicillin will be used if amoxicillin rules are not available +* For all interpretation guidelines using `as.sir()` on amoxicillin, the rules for ampicillin will be used if amoxicillin rules are not available * Fix for using `ab_atc()` on non-existing ATC codes * Black and white message texts are now reversed in colour if using an RStudio dark theme * `mo_snomed()` now returns class `character`, not `numeric` anymore (to make long SNOMED codes readable) * Fix for using `as.ab()` on `NA` values * Updated support for all WHONET 2022 microorganism codes -* Antimicrobial interpretation 'SDD' (susceptible dose-dependent, coined by CLSI) will be interpreted as 'I' to comply with EUCAST's 'I' in `as.rsi()` +* Antimicrobial interpretation 'SDD' (susceptible dose-dependent, coined by CLSI) will be interpreted as 'I' to comply with EUCAST's 'I' in `as.sir()` * Fix for `mo_shortname()` in case of higher taxonomic ranks (order, class, phylum) -* Cleaning columns with `as.rsi()`, `as.mic()`, or `as.disk()` will now show the column name in the warning for invalid results +* Cleaning columns with `as.sir()`, `as.mic()`, or `as.disk()` will now show the column name in the warning for invalid results ## Other diff --git a/R/aa_amr-package.R b/R/aa_amr-package.R new file mode 100755 index 000000000..106c75d1c --- /dev/null +++ b/R/aa_amr-package.R @@ -0,0 +1,57 @@ +# ==================================================================== # +# TITLE # +# AMR: An R Package for Working with Antimicrobial Resistance Data # +# # +# SOURCE # +# https://github.com/msberends/AMR # +# # +# CITE AS # +# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # +# (2022). AMR: An R Package for Working with Antimicrobial Resistance # +# Data. Journal of Statistical Software, 104(3), 1-31. # +# doi:10.18637/jss.v104.i03 # +# # +# Developed at the University of Groningen and the University Medical # +# Center Groningen in The Netherlands, in collaboration with many # +# colleagues from around the world, see our website. # +# # +# 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 the full manual and a complete tutorial about # +# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # +# ==================================================================== # + +#' The `AMR` Package +#' +#' @description +#' Welcome to the `AMR` package. +#' +#' The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#copyright) R package with [zero dependencies](https://en.wikipedia.org/wiki/Dependency_hell) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. [Many different researchers](https://msberends.github.io/AMR/authors.html) from around the globe are continually helping us to make this a successful and durable project! +#' +#' This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)). +#' +#' After installing this package, R knows [**`r format_included_data_number(AMR::microorganisms)`**](https://msberends.github.io/AMR/reference/microorganisms.html) (updated December 2022) and all [**~600 antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl). +#' +#' The `AMR` package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages. +#' @section Reference Data Publicly Available: +#' All data sets in this `AMR` package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). +#' @source +#' To cite AMR in publications use: +#' +#' Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C (2022). "AMR: An R Package for Working with Antimicrobial Resistance Data." _Journal of Statistical Software_, *104*(3), 1-31. \doi{10.18637/jss.v104.i03}. +#' +#' A BibTeX entry for LaTeX users is: +#' +#' \preformatted{ +#' `r format(citation("AMR"), style = "bib")` +#' } +#' @name AMR +#' @keywords internal +#' @rdname AMR +"_PACKAGE" diff --git a/R/aa_globals.R b/R/aa_globals.R index b3eb77bdb..74e6ffce1 100755 --- a/R/aa_globals.R +++ b/R/aa_globals.R @@ -27,7 +27,7 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -# add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and rsi_translation +# add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and clinical_breakpoints # (sourcing "data-raw/_pre_commit_hook.R" will process the TSV file) EUCAST_VERSION_BREAKPOINTS <- list( "12.0" = list( @@ -148,8 +148,8 @@ globalVariables(c( "reference.rule_group", "reference.version", "rowid", - "rsi", - "rsi_translation", + "sir", + "clinical_breakpoints", "rule_group", "rule_name", "se_max", diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index ef4197c8d..bd0dc6a2b 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -225,6 +225,8 @@ search_type_in_df <- function(x, type, info = TRUE) { # -- mo if (type == "mo") { + add_MO_lookup_to_AMR_env() + if (any(vapply(FUN.VALUE = logical(1), x, is.mo))) { # take first 'mo' column found <- colnames(x)[vapply(FUN.VALUE = logical(1), x, is.mo)] @@ -515,7 +517,7 @@ stop_ <- function(..., call = TRUE) { if (isTRUE(call)) { call <- as.character(sys.call(-1)[1]) } else { - # so you can go back more than 1 call, as used in rsi_calc(), that now throws a reference to e.g. n_rsi() + # so you can go back more than 1 call, as used in sir_calc(), that now throws a reference to e.g. n_sir() call <- as.character(sys.call(call)[1]) } msg <- paste0("in ", call, "(): ", msg) @@ -626,7 +628,7 @@ create_eucast_ab_documentation <- function() { # separate drugs, such as `AMX` val <- as.ab(val) } else { - val <- as.rsi(NA) + val <- as.sir(NA) } ab <- c(ab, val) } @@ -666,8 +668,8 @@ vector_or <- function(v, quotes = TRUE, reverse = FALSE, sort = TRUE, initial_ca return(paste0(quotes, v, quotes)) } if (identical(v, c("I", "R", "S"))) { - # class 'rsi' should be sorted like this - v <- c("R", "S", "I") + # class 'sir' should be sorted like this + v <- c("S", "I", "R") } # all commas except for last item, so will become '"val1", "val2", "val3" or "val4"' paste0( @@ -710,7 +712,7 @@ format_class <- function(class, plural = FALSE) { if ("custom_eucast_rules" %in% class) { class <- "input created with `custom_eucast_rules()`" } - if (any(c("mo", "ab", "rsi") %in% class)) { + if (any(c("mo", "ab", "sir") %in% class)) { class <- paste0("of class <", class[1L], ">") } class[class == class.bak] <- paste0("of class <", class[class == class.bak], ">") @@ -1140,18 +1142,18 @@ font_grey_bg <- function(..., collapse = " ") { } } font_red_bg <- function(..., collapse = " ") { - # this is #ed553b (picked to be colourblind-safe with other RSI colours) + # this is #ed553b (picked to be colourblind-safe with other SIR colours) try_colour(font_black(..., collapse = collapse), before = "\033[48;5;203m", after = "\033[49m", collapse = collapse) } font_orange_bg <- function(..., collapse = " ") { - # this is #f6d55c (picked to be colourblind-safe with other RSI colours) + # this is #f6d55c (picked to be colourblind-safe with other SIR colours) try_colour(font_black(..., collapse = collapse), before = "\033[48;5;222m", after = "\033[49m", collapse = collapse) } font_yellow_bg <- function(..., collapse = " ") { try_colour(font_black(..., collapse = collapse), before = "\033[48;5;228m", after = "\033[49m", collapse = collapse) } font_green_bg <- function(..., collapse = " ") { - # this is #3caea3 (picked to be colourblind-safe with other RSI colours) + # this is #3caea3 (picked to be colourblind-safe with other SIR colours) try_colour(font_black(..., collapse = collapse), before = "\033[48;5;79m", after = "\033[49m", collapse = collapse) } font_purple_bg <- function(..., collapse = " ") { @@ -1379,6 +1381,38 @@ add_intrinsic_resistance_to_AMR_env <- function() { } } +add_MO_lookup_to_AMR_env <- function() { + # for all MO functions, saves a lot of time on package load and in package size + if (is.null(AMR_env$MO_lookup)) { + MO_lookup <- AMR::microorganisms + + MO_lookup$kingdom_index <- NA_real_ + MO_lookup[which(MO_lookup$kingdom == "Bacteria" | MO_lookup$mo == "UNKNOWN"), "kingdom_index"] <- 1 + MO_lookup[which(MO_lookup$kingdom == "Fungi"), "kingdom_index"] <- 2 + MO_lookup[which(MO_lookup$kingdom == "Protozoa"), "kingdom_index"] <- 3 + MO_lookup[which(MO_lookup$kingdom == "Archaea"), "kingdom_index"] <- 4 + # all the rest + MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5 + + # the fullname lowercase, important for the internal algorithms in as.mo() + MO_lookup$fullname_lower <- tolower(trimws(paste( + MO_lookup$genus, + MO_lookup$species, + MO_lookup$subspecies + ))) + ind <- MO_lookup$genus == "" | grepl("^[(]unknown ", MO_lookup$fullname, perl = TRUE) + MO_lookup[ind, "fullname_lower"] <- tolower(MO_lookup[ind, "fullname", drop = TRUE]) + MO_lookup$fullname_lower <- trimws(gsub("[^.a-z0-9/ \\-]+", "", MO_lookup$fullname_lower, perl = TRUE)) + # special for Salmonella - they have cities as subspecies but not the species (enterica) in the fullname: + MO_lookup$fullname_lower[which(MO_lookup$subspecies %like_case% "^[A-Z]")] <- gsub(" enterica ", " ", MO_lookup$fullname_lower[which(MO_lookup$subspecies %like_case% "^[A-Z]")], fixed = TRUE) + + MO_lookup$full_first <- substr(MO_lookup$fullname_lower, 1, 1) + MO_lookup$species_first <- tolower(substr(MO_lookup$species, 1, 1)) # tolower for groups (Streptococcus, Salmonella) + MO_lookup$subspecies_first <- tolower(substr(MO_lookup$subspecies, 1, 1)) # tolower for Salmonella serovars + AMR_env$MO_lookup <- MO_lookup + } +} + trimws2 <- function(..., whitespace = "[\u0009\u000A\u000B\u000C\u000D\u0020\u0085\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u200C\u200D\u2028\u2029\u202F\u205F\u2060\u3000\uFEFF]") { # this is even faster than trimws() itself which sets " \t\n\r". trimws(..., whitespace = whitespace) diff --git a/R/ab.R b/R/ab.R index deaba68ff..f80644f61 100755 --- a/R/ab.R +++ b/R/ab.R @@ -88,9 +88,9 @@ #' \donttest{ #' if (require("dplyr")) { #' -#' # you can quickly rename 'rsi' columns using set_ab_names() with dplyr: +#' # you can quickly rename 'sir' columns using set_ab_names() with dplyr: #' example_isolates %>% -#' set_ab_names(where(is.rsi), property = "atc") +#' set_ab_names(where(is.sir), property = "atc") #' } #' } as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) { @@ -632,7 +632,7 @@ rep.ab <- function(x, ...) { generalise_antibiotic_name <- function(x) { x <- toupper(x) # remove suffices - x <- gsub("_(MIC|RSI|DIS[CK])$", "", x, perl = TRUE) + x <- gsub("_(MIC|RSI|SIR|DIS[CK])$", "", x, perl = TRUE) # remove disk concentrations, like LVX_NM -> LVX x <- gsub("_[A-Z]{2}[0-9_.]{0,3}$", "", x, perl = TRUE) # remove part between brackets if that's followed by another string diff --git a/R/ab_property.R b/R/ab_property.R index 6ed83dbed..1d1560283 100755 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -116,7 +116,7 @@ #' head() #' #' example_isolates %>% -#' set_ab_names(where(is.rsi)) %>% +#' set_ab_names(where(is.sir)) %>% #' colnames() #' #' example_isolates %>% @@ -372,7 +372,7 @@ set_ab_names <- function(data, ..., property = "name", language = get_AMR_locale } else { df <- data } - vars <- get_column_abx(df, info = FALSE, only_rsi_columns = FALSE, sort = FALSE, fn = "set_ab_names") + vars <- get_column_abx(df, info = FALSE, only_sir_columns = FALSE, sort = FALSE, fn = "set_ab_names") if (length(vars) == 0) { message_("No columns with antibiotic results found for `set_ab_names()`, leaving names unchanged.") return(data) diff --git a/R/ab_selectors.R b/R/ab_selectors.R index 89d2d7538..ffcacd783 100755 --- a/R/ab_selectors.R +++ b/R/ab_selectors.R @@ -32,7 +32,7 @@ #' These functions allow for filtering rows and selecting columns based on antibiotic test results that are of a specific antibiotic class or group, without the need to define the columns or antibiotic abbreviations. In short, if you have a column name that resembles an antimicrobial drug, it will be picked up by any of these functions that matches its pharmaceutical class: "cefazolin", "CZO" and "J01DB04" will all be picked up by [cephalosporins()]. #' @param ab_class an antimicrobial class or a part of it, such as `"carba"` and `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value. #' @param filter an [expression] to be evaluated in the [antibiotics] data set, such as `name %like% "trim"` -#' @param only_rsi_columns a [logical] to indicate whether only columns of class `rsi` must be selected (defaults to `FALSE`), see [as.rsi()] +#' @param only_sir_columns a [logical] to indicate whether only columns of class `sir` must be selected (defaults to `FALSE`), see [as.sir()] #' @param only_treatable a [logical] to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (defaults to `TRUE`), such as gentamicin-high (`GEH`) and imipenem/EDTA (`IPE`) #' @param ... ignored, only in place to allow future extensions #' @details @@ -188,23 +188,23 @@ #' } #' } ab_class <- function(ab_class, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, only_treatable = TRUE, ...) { meet_criteria(ab_class, allow_class = "character", has_length = 1, allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) - ab_select_exec(NULL, only_rsi_columns = only_rsi_columns, ab_class_args = ab_class, only_treatable = only_treatable) + ab_select_exec(NULL, only_sir_columns = only_sir_columns, ab_class_args = ab_class, only_treatable = only_treatable) } #' @rdname antibiotic_class_selectors #' @details The [ab_selector()] function can be used to internally filter the [antibiotics] data set on any results, see *Examples*. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set. #' @export ab_selector <- function(filter, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, only_treatable = TRUE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) # get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call @@ -212,7 +212,7 @@ ab_selector <- function(filter, vars_df <- get_current_data(arg_name = NA, call = -2) # to improve speed, get_column_abx() will only run once when e.g. in a select or group call ab_in_data <- get_column_abx(vars_df, - info = FALSE, only_rsi_columns = only_rsi_columns, + info = FALSE, only_sir_columns = only_sir_columns, sort = FALSE, fn = "ab_selector" ) call <- substitute(filter) @@ -234,194 +234,194 @@ ab_selector <- function(filter, #' @rdname antibiotic_class_selectors #' @export -aminoglycosides <- function(only_rsi_columns = FALSE, only_treatable = TRUE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +aminoglycosides <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) - ab_select_exec("aminoglycosides", only_rsi_columns = only_rsi_columns, only_treatable = only_treatable) + ab_select_exec("aminoglycosides", only_sir_columns = only_sir_columns, only_treatable = only_treatable) } #' @rdname antibiotic_class_selectors #' @export -aminopenicillins <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("aminopenicillins", only_rsi_columns = only_rsi_columns) +aminopenicillins <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("aminopenicillins", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -antifungals <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("antifungals", only_rsi_columns = only_rsi_columns) +antifungals <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("antifungals", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -antimycobacterials <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("antimycobacterials", only_rsi_columns = only_rsi_columns) +antimycobacterials <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("antimycobacterials", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -betalactams <- function(only_rsi_columns = FALSE, only_treatable = TRUE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +betalactams <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) - ab_select_exec("betalactams", only_rsi_columns = only_rsi_columns, only_treatable = only_treatable) + ab_select_exec("betalactams", only_sir_columns = only_sir_columns, only_treatable = only_treatable) } #' @rdname antibiotic_class_selectors #' @export -carbapenems <- function(only_rsi_columns = FALSE, only_treatable = TRUE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +carbapenems <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) - ab_select_exec("carbapenems", only_rsi_columns = only_rsi_columns, only_treatable = only_treatable) + ab_select_exec("carbapenems", only_sir_columns = only_sir_columns, only_treatable = only_treatable) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins", only_rsi_columns = only_rsi_columns) +cephalosporins <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins_1st <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins_1st", only_rsi_columns = only_rsi_columns) +cephalosporins_1st <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins_1st", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins_2nd <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins_2nd", only_rsi_columns = only_rsi_columns) +cephalosporins_2nd <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins_2nd", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins_3rd <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins_3rd", only_rsi_columns = only_rsi_columns) +cephalosporins_3rd <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins_3rd", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins_4th <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins_4th", only_rsi_columns = only_rsi_columns) +cephalosporins_4th <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins_4th", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -cephalosporins_5th <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("cephalosporins_5th", only_rsi_columns = only_rsi_columns) +cephalosporins_5th <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("cephalosporins_5th", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -fluoroquinolones <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("fluoroquinolones", only_rsi_columns = only_rsi_columns) +fluoroquinolones <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("fluoroquinolones", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -glycopeptides <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("glycopeptides", only_rsi_columns = only_rsi_columns) +glycopeptides <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("glycopeptides", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -lincosamides <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("lincosamides", only_rsi_columns = only_rsi_columns) +lincosamides <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("lincosamides", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -lipoglycopeptides <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("lipoglycopeptides", only_rsi_columns = only_rsi_columns) +lipoglycopeptides <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("lipoglycopeptides", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -macrolides <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("macrolides", only_rsi_columns = only_rsi_columns) +macrolides <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("macrolides", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -oxazolidinones <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("oxazolidinones", only_rsi_columns = only_rsi_columns) +oxazolidinones <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("oxazolidinones", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -penicillins <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("penicillins", only_rsi_columns = only_rsi_columns) +penicillins <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("penicillins", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -polymyxins <- function(only_rsi_columns = FALSE, only_treatable = TRUE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +polymyxins <- function(only_sir_columns = FALSE, only_treatable = TRUE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(only_treatable, allow_class = "logical", has_length = 1) - ab_select_exec("polymyxins", only_rsi_columns = only_rsi_columns, only_treatable = only_treatable) + ab_select_exec("polymyxins", only_sir_columns = only_sir_columns, only_treatable = only_treatable) } #' @rdname antibiotic_class_selectors #' @export -streptogramins <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("streptogramins", only_rsi_columns = only_rsi_columns) +streptogramins <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("streptogramins", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -quinolones <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("quinolones", only_rsi_columns = only_rsi_columns) +quinolones <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("quinolones", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -tetracyclines <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("tetracyclines", only_rsi_columns = only_rsi_columns) +tetracyclines <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("tetracyclines", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -trimethoprims <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("trimethoprims", only_rsi_columns = only_rsi_columns) +trimethoprims <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("trimethoprims", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @export -ureidopenicillins <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) - ab_select_exec("ureidopenicillins", only_rsi_columns = only_rsi_columns) +ureidopenicillins <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) + ab_select_exec("ureidopenicillins", only_sir_columns = only_sir_columns) } #' @rdname antibiotic_class_selectors #' @details The [administrable_per_os()] and [administrable_iv()] functions also rely on the [antibiotics] data set - antibiotic columns will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the [antibiotics] data set. #' @export -administrable_per_os <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +administrable_per_os <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) # get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call # but it only takes a couple of milliseconds vars_df <- get_current_data(arg_name = NA, call = -2) # to improve speed, get_column_abx() will only run once when e.g. in a select or group call ab_in_data <- get_column_abx(vars_df, - info = FALSE, only_rsi_columns = only_rsi_columns, + info = FALSE, only_sir_columns = only_sir_columns, sort = FALSE, fn = "administrable_per_os" ) agents_all <- AMR_env$AB_lookup[which(!is.na(AMR_env$AB_lookup$oral_ddd)), "ab", drop = TRUE] @@ -452,14 +452,14 @@ administrable_per_os <- function(only_rsi_columns = FALSE, ...) { #' @rdname antibiotic_class_selectors #' @export -administrable_iv <- function(only_rsi_columns = FALSE, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +administrable_iv <- function(only_sir_columns = FALSE, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) # get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call # but it only takes a couple of milliseconds vars_df <- get_current_data(arg_name = NA, call = -2) # to improve speed, get_column_abx() will only run once when e.g. in a select or group call ab_in_data <- get_column_abx(vars_df, - info = FALSE, only_rsi_columns = only_rsi_columns, + info = FALSE, only_sir_columns = only_sir_columns, sort = FALSE, fn = "administrable_iv" ) agents_all <- AMR_env$AB_lookup[which(!is.na(AMR_env$AB_lookup$iv_ddd)), "ab", drop = TRUE] @@ -480,14 +480,14 @@ administrable_iv <- function(only_rsi_columns = FALSE, ...) { #' @inheritParams eucast_rules #' @details The [not_intrinsic_resistant()] function can be used to only select antibiotic columns that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of *E. coli* and *K. pneumoniae* and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies `r format_eucast_version_nr(names(EUCAST_VERSION_EXPERT_RULES[length(EUCAST_VERSION_EXPERT_RULES)]))` to determine intrinsic resistance, using the [eucast_rules()] function internally. Because of this determination, this function is quite slow in terms of performance. #' @export -not_intrinsic_resistant <- function(only_rsi_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ...) { - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) +not_intrinsic_resistant <- function(only_sir_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ...) { + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) # get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call # but it only takes a couple of milliseconds vars_df <- get_current_data(arg_name = NA, call = -2) # to improve speed, get_column_abx() will only run once when e.g. in a select or group call ab_in_data <- get_column_abx(vars_df, - info = FALSE, only_rsi_columns = only_rsi_columns, + info = FALSE, only_sir_columns = only_sir_columns, sort = FALSE, fn = "not_intrinsic_resistant" ) # intrinsic vars @@ -530,7 +530,7 @@ not_intrinsic_resistant <- function(only_rsi_columns = FALSE, col_mo = NULL, ver } ab_select_exec <- function(function_name, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, only_treatable = FALSE, ab_class_args = NULL) { # get_current_data() has to run each time, for cases where e.g., filter() and select() are used in same call @@ -538,7 +538,7 @@ ab_select_exec <- function(function_name, vars_df <- get_current_data(arg_name = NA, call = -3) # to improve speed, get_column_abx() will only run once when e.g. in a select or group call ab_in_data <- get_column_abx(vars_df, - info = FALSE, only_rsi_columns = only_rsi_columns, + info = FALSE, only_sir_columns = only_sir_columns, sort = FALSE, fn = function_name ) @@ -639,10 +639,10 @@ c.ab_selector <- function(...) { all_any_ab_selector <- function(type, ..., na.rm = TRUE) { cols_ab <- c(...) - result <- cols_ab[toupper(cols_ab) %in% c("R", "S", "I")] + result <- cols_ab[toupper(cols_ab) %in% c("S", "I", "R")] if (length(result) == 0) { - message_("Filtering ", type, " of columns ", vector_and(font_bold(cols_ab, collapse = NULL), quotes = "'"), ' to contain value "R", "S" or "I"') - result <- c("R", "S", "I") + message_("Filtering ", type, " of columns ", vector_and(font_bold(cols_ab, collapse = NULL), quotes = "'"), ' to contain value "S", "I" or "R"') + result <- c("S", "I", "R") } cols_ab <- cols_ab[!cols_ab %in% result] df <- get_current_data(arg_name = NA, call = -3) @@ -751,8 +751,8 @@ any.ab_selector_any_all <- function(..., na.rm = FALSE) { } } # this is `!=`, so turn around the values - rsi <- c("R", "S", "I") - e2 <- rsi[rsi != e2] + sir <- c("S", "I", "R") + e2 <- sir[sir != e2] structure(all_any_ab_selector(type = type, e1, e2), class = c("ab_selector_any_all", "logical") ) diff --git a/R/age.R b/R/age.R index 50910317a..72843e270 100755 --- a/R/age.R +++ b/R/age.R @@ -172,7 +172,7 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) { #' filter(mo == as.mo("Escherichia coli")) %>% #' group_by(age_group = age_groups(age)) %>% #' select(age_group, CIP) %>% -#' ggplot_rsi( +#' ggplot_sir( #' x = "age_group", #' minimum = 0, #' x.title = "Age Group", diff --git a/R/amr.R b/R/amr.R deleted file mode 100755 index 5032770d3..000000000 --- a/R/amr.R +++ /dev/null @@ -1,76 +0,0 @@ -# ==================================================================== # -# TITLE # -# AMR: An R Package for Working with Antimicrobial Resistance Data # -# # -# SOURCE # -# https://github.com/msberends/AMR # -# # -# CITE AS # -# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # -# (2022). AMR: An R Package for Working with Antimicrobial Resistance # -# Data. Journal of Statistical Software, 104(3), 1-31. # -# doi:10.18637/jss.v104.i03 # -# # -# Developed at the University of Groningen and the University Medical # -# Center Groningen in The Netherlands, in collaboration with many # -# colleagues from around the world, see our website. # -# # -# 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 the full manual and a complete tutorial about # -# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # -# ==================================================================== # - -#' The `AMR` Package -#' -#' @description -#' Welcome to the `AMR` package. -#' -#' `AMR` is a free, open-source and independent \R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. -#' -#' This work was published in the Journal of Statistical Software (Volume 104(3); \doi{10.18637/jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}). -#' -#' After installing this package, \R knows `r format_included_data_number(microorganisms)` distinct microbial species and all `r format_included_data_number(rbind(antibiotics[, "name", drop = FALSE], antivirals[, "name", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-NET, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data. -#' -#' This package is fully independent of any other \R package and works on Windows, macOS and Linux with all versions of \R since R-3.0.0 (April 2013). It was designed to work in any setting, including those with very limited resources. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the University of Groningen, in collaboration with non-profit organisations Certe Medical Diagnostics and Advice and University Medical Center Groningen. This \R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. -#' -#' This package can be used for: -#' - Reference for the taxonomy of microorganisms, since the package contains all microbial (sub)species from the List of Prokaryotic names with Standing in Nomenclature (LPSN) and the Global Biodiversity Information Facility (GBIF) -#' - Interpreting raw MIC and disk diffusion values, based on any CLSI or EUCAST guideline from the last 10 years -#' - Retrieving antimicrobial drug names, doses and forms of administration from clinical health care records -#' - Determining first isolates to be used for AMR data analysis -#' - Calculating antimicrobial resistance -#' - Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO) -#' - Calculating (empirical) susceptibility of both mono therapy and combination therapies -#' - Predicting future antimicrobial resistance using regression models -#' - Getting properties for any microorganism (such as Gram stain, species, genus or family) -#' - Getting properties for any antibiotic (such as name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) -#' - Plotting antimicrobial resistance -#' - Applying EUCAST expert rules -#' - Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code -#' - Getting LOINC codes of an antibiotic, or getting properties of an antibiotic based on a LOINC code -#' - Machine reading the EUCAST and CLSI guidelines from 2011-2020 to translate MIC values and disk diffusion diameters to R/SI -#' - Principal component analysis for AMR -#' -#' @section Reference Data Publicly Available: -#' All data sets in this `AMR` package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). -#' @source -#' To cite AMR in publications use: -#' -#' Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C (2022). "AMR: An R Package for Working with Antimicrobial Resistance Data." _Journal of Statistical Software_, *104*(3), 1-31. \doi{10.18637/jss.v104.i03}. -#' -#' A BibTeX entry for LaTeX users is: -#' -#' \preformatted{ -#' `r format(citation("AMR"), style = "bib")` -#' } -#' @name AMR -#' @keywords internal -#' @rdname AMR -"_PACKAGE" diff --git a/R/availability.R b/R/availability.R index 671df9f78..43b6cd384 100755 --- a/R/availability.R +++ b/R/availability.R @@ -41,7 +41,7 @@ #' if (require("dplyr")) { #' example_isolates %>% #' filter(mo == as.mo("Escherichia coli")) %>% -#' select_if(is.rsi) %>% +#' select_if(is.sir) %>% #' availability() #' } #' } @@ -55,7 +55,7 @@ availability <- function(tbl, width = NULL) { 1 - sum(is.na(x)) / length(x) }) n <- vapply(FUN.VALUE = double(1), tbl, function(x) length(x[!is.na(x)])) - R <- vapply(FUN.VALUE = double(1), tbl, function(x) ifelse(is.rsi(x), resistance(x, minimum = 0), NA_real_)) + R <- vapply(FUN.VALUE = double(1), tbl, function(x) ifelse(is.sir(x), resistance(x, minimum = 0), NA_real_)) R_print <- character(length(R)) R_print[!is.na(R)] <- percentage(R[!is.na(R)]) R_print[is.na(R)] <- "" diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index 01574bdcc..61bc1b1c0 100755 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -37,7 +37,7 @@ #' @param FUN the function to call on the `mo` column to transform the microorganism codes, defaults to [mo_shortname()] #' @param translate_ab a [character] of length 1 containing column names of the [antibiotics] data set #' @param ... arguments passed on to `FUN` -#' @inheritParams rsi_df +#' @inheritParams sir_df #' @inheritParams base::formatC #' @details The function [format()] calculates the resistance per bug-drug combination. Use `combine_SI = TRUE` (default) to test R vs. S+I and `combine_SI = FALSE` to test R+I vs. S. #' @export @@ -67,7 +67,7 @@ bug_drug_combinations <- function(x, col_mo = NULL, FUN = mo_shortname, ...) { - meet_criteria(x, allow_class = "data.frame", contains_column_class = "rsi") + meet_criteria(x, allow_class = "data.frame", contains_column_class = "sir") meet_criteria(col_mo, allow_class = "character", is_in = colnames(x), has_length = 1, allow_NULL = TRUE) meet_criteria(FUN, allow_class = "function", has_length = 1) @@ -90,10 +90,10 @@ bug_drug_combinations <- function(x, if (is_null_or_grouped_tbl(x.bak)) { data_has_groups <- TRUE groups <- setdiff(names(attributes(x.bak)$groups), ".rows") - x <- x[, c(groups, col_mo, colnames(x)[vapply(FUN.VALUE = logical(1), x, is.rsi)]), drop = FALSE] + x <- x[, c(groups, col_mo, colnames(x)[vapply(FUN.VALUE = logical(1), x, is.sir)]), drop = FALSE] } else { data_has_groups <- FALSE - x <- x[, c(col_mo, names(which(vapply(FUN.VALUE = logical(1), x, is.rsi)))), drop = FALSE] + x <- x[, c(col_mo, names(which(vapply(FUN.VALUE = logical(1), x, is.sir)))), drop = FALSE] } run_it <- function(x) { @@ -113,8 +113,8 @@ bug_drug_combinations <- function(x, } for (i in seq_len(length(unique_mo))) { - # filter on MO group and only select R/SI columns - x_mo_filter <- x[which(x[, col_mo, drop = TRUE] == unique_mo[i]), names(which(vapply(FUN.VALUE = logical(1), x, is.rsi))), drop = FALSE] + # filter on MO group and only select SIR columns + x_mo_filter <- x[which(x[, col_mo, drop = TRUE] == unique_mo[i]), names(which(vapply(FUN.VALUE = logical(1), x, is.sir))), drop = FALSE] # turn and merge everything pivot <- lapply(x_mo_filter, function(x) { m <- as.matrix(table(x)) diff --git a/R/count.R b/R/count.R index 1b835809a..cce82d1d1 100755 --- a/R/count.R +++ b/R/count.R @@ -32,16 +32,16 @@ #' @description These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in `summarise()` from the `dplyr` package and also support grouped variables, see *Examples*. #' #' [count_resistant()] should be used to count resistant isolates, [count_susceptible()] should be used to count susceptible isolates. -#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with [as.rsi()] if needed. +#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with [as.sir()] if needed. #' @inheritParams proportion -#' @inheritSection as.rsi Interpretation of R and S/I +#' @inheritSection as.sir Interpretation of SIR #' @details These functions are meant to count isolates. Use the [resistance()]/[susceptibility()] functions to calculate microbial resistance/susceptibility. #' #' The function [count_resistant()] is equal to the function [count_R()]. The function [count_susceptible()] is equal to the function [count_SI()]. #' -#' The function [n_rsi()] is an alias of [count_all()]. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to `n_distinct()`. Their function is equal to `count_susceptible(...) + count_resistant(...)`. +#' The function [n_sir()] is an alias of [count_all()]. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to `n_distinct()`. Their function is equal to `count_susceptible(...) + count_resistant(...)`. #' -#' The function [count_df()] takes any variable from `data` that has an [`rsi`] class (created with [as.rsi()]) and counts the number of S's, I's and R's. It also supports grouped variables. The function [rsi_df()] works exactly like [count_df()], but adds the percentage of S, I and R. +#' The function [count_df()] takes any variable from `data` that has an [`sir`] class (created with [as.sir()]) and counts the number of S's, I's and R's. It also supports grouped variables. The function [sir_df()] works exactly like [count_df()], but adds the percentage of S, I and R. #' @inheritSection proportion Combination Therapy #' @seealso [`proportion_*`][proportion] to calculate microbial resistance and susceptibility. #' @return An [integer] @@ -66,14 +66,14 @@ #' #' # Count all available isolates #' count_all(example_isolates$AMX) -#' n_rsi(example_isolates$AMX) +#' n_sir(example_isolates$AMX) #' -#' # n_rsi() is an alias of count_all(). +#' # n_sir() is an alias of count_all(). #' # Since it counts all available isolates, you can #' # calculate back to count e.g. susceptible isolates. #' # These results are the same: #' count_susceptible(example_isolates$AMX) -#' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX) +#' susceptibility(example_isolates$AMX) * n_sir(example_isolates$AMX) #' #' # dplyr ------------------------------------------------------------- #' \donttest{ @@ -85,7 +85,7 @@ #' I = count_I(CIP), #' S = count_S(CIP), #' n1 = count_all(CIP), # the actual total; sum of all three -#' n2 = n_rsi(CIP), # same - analogous to n_distinct +#' n2 = n_sir(CIP), # same - analogous to n_distinct #' total = n() #' ) # NOT the number of tested isolates! #' @@ -93,7 +93,7 @@ #' # (i.e., in this data set columns GEN, TOB, AMK, KAN) #' example_isolates %>% #' group_by(ward) %>% -#' summarise(across(aminoglycosides(), n_rsi)) +#' summarise(across(aminoglycosides(), n_sir)) #' #' # Count co-resistance between amoxicillin/clav acid and gentamicin, #' # so we can see that combination therapy does a lot more than mono therapy. @@ -121,12 +121,12 @@ #' } count_resistant <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "R", only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -134,12 +134,12 @@ count_resistant <- function(..., only_all_tested = FALSE) { #' @export count_susceptible <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I"), only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -147,12 +147,12 @@ count_susceptible <- function(..., only_all_tested = FALSE) { #' @export count_R <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "R", only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -163,12 +163,12 @@ count_IR <- function(..., only_all_tested = FALSE) { message_("Using `count_IR()` is discouraged; use `count_resistant()` instead to not consider \"I\" being resistant. This note will be shown once for this session.", as_note = FALSE) } tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("I", "R"), only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -176,12 +176,12 @@ count_IR <- function(..., only_all_tested = FALSE) { #' @export count_I <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "I", only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -189,12 +189,12 @@ count_I <- function(..., only_all_tested = FALSE) { #' @export count_SI <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I"), only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -205,12 +205,12 @@ count_S <- function(..., only_all_tested = FALSE) { message_("Using `count_S()` is discouraged; use `count_susceptible()` instead to also consider \"I\" being susceptible. This note will be shown once for this session.", as_note = FALSE) } tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "S", only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -218,18 +218,18 @@ count_S <- function(..., only_all_tested = FALSE) { #' @export count_all <- function(..., only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I", "R"), only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } #' @rdname count #' @export -n_rsi <- count_all +n_sir <- count_all #' @rdname count #' @export @@ -238,7 +238,7 @@ count_df <- function(data, language = get_AMR_locale(), combine_SI = TRUE) { tryCatch( - rsi_calc_df( + sir_calc_df( type = "count", data = data, translate_ab = translate_ab, @@ -246,6 +246,6 @@ count_df <- function(data, combine_SI = combine_SI, confidence_level = 0.95 # doesn't matter, will be removed ), - error = function(e) stop_(gsub("in rsi_calc_df(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc_df(): ", "", e$message, fixed = TRUE), call = -5) ) } diff --git a/R/custom_antimicrobials.R b/R/custom_antimicrobials.R index 211cae4ce..78a4f8afa 100755 --- a/R/custom_antimicrobials.R +++ b/R/custom_antimicrobials.R @@ -112,8 +112,8 @@ #' # even antibiotic selectors work #' x <- data.frame( #' random_column = "some value", -#' coflu = as.rsi("S"), -#' ampicillin = as.rsi("R") +#' coflu = as.sir("S"), +#' ampicillin = as.sir("R") #' ) #' x #' x[, betalactams()] @@ -165,7 +165,7 @@ add_custom_antimicrobials <- function(x) { #' @export clear_custom_antimicrobials <- function() { n <- nrow(AMR_env$AB_lookup) - AMR_env$AB_lookup <- create_AB_lookup() + AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP) n2 <- nrow(AMR_env$AB_lookup) AMR_env$custom_ab_codes <- character(0) AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(AMR_env$ab_previously_coerced$ab %in% AMR_env$AB_lookup$ab), , drop = FALSE] diff --git a/R/custom_eucast_rules.R b/R/custom_eucast_rules.R index 8f3e8267c..f77a76d0d 100755 --- a/R/custom_eucast_rules.R +++ b/R/custom_eucast_rules.R @@ -61,9 +61,9 @@ #' #' ```r #' df <- data.frame(mo = c("Escherichia coli", "Klebsiella pneumoniae"), -#' TZP = as.rsi("R"), -#' ampi = as.rsi("S"), -#' cipro = as.rsi("S")) +#' TZP = as.sir("R"), +#' ampi = as.sir("S"), +#' cipro = as.sir("S")) #' df #' #> mo TZP ampi cipro #' #> 1 Escherichia coli R S S @@ -181,10 +181,10 @@ custom_eucast_rules <- function(...) { result_value <- as.character(result)[[3]] result_value[result_value == "NA"] <- NA stop_ifnot( - result_value %in% c("R", "S", "I", NA), - "the resulting value of rule ", i, " must be either \"R\", \"S\", \"I\" or NA" + result_value %in% c("S", "I", "R", NA), + "the resulting value of rule ", i, " must be either \"S\", \"I\", \"R\" or NA" ) - result_value <- as.rsi(result_value) + result_value <- as.sir(result_value) out[[i]]$result_group <- result_group out[[i]]$result_value <- result_value diff --git a/R/custom_microorganisms.R b/R/custom_microorganisms.R index 281014d02..466d392e5 100755 --- a/R/custom_microorganisms.R +++ b/R/custom_microorganisms.R @@ -37,7 +37,7 @@ #' #' There are two ways to automate this process: #' -#' **Method 1:** Using the [option `AMR_custom_mo`][AMR-options], which is the preferred method. To use this method: +#' **Method 1:** Using the option [`AMR_custom_mo`][AMR-options], which is the preferred method. To use this method: #' #' 1. Create a data set in the structure of the [microorganisms] data set (containing at the very least column "genus") and save it with [saveRDS()] to a location of choice, e.g. `"~/my_custom_mo.rds"`, or any remote location. #' @@ -124,6 +124,8 @@ add_custom_microorganisms <- function(x) { meet_criteria(x, allow_class = "data.frame") stop_ifnot("genus" %in% tolower(colnames(x)), paste0("`x` must contain column 'genus'.")) + add_MO_lookup_to_AMR_env() + # remove any extra class/type, such as grouped tbl, or data.table: x <- as.data.frame(x, stringsAsFactors = FALSE) colnames(x) <- tolower(colnames(x)) @@ -269,7 +271,11 @@ add_custom_microorganisms <- function(x) { #' @export clear_custom_microorganisms <- function() { n <- nrow(AMR_env$MO_lookup) - AMR_env$MO_lookup <- create_MO_lookup() + + # reset + AMR_env$MO_lookup <- NULL + add_MO_lookup_to_AMR_env() + n2 <- nrow(AMR_env$MO_lookup) AMR_env$custom_mo_codes <- character(0) AMR_env$mo_previously_coerced <- AMR_env$mo_previously_coerced[which(AMR_env$mo_previously_coerced$mo %in% AMR_env$MO_lookup$mo), , drop = FALSE] diff --git a/R/data.R b/R/data.R index aa293a188..ab81c2419 100755 --- a/R/data.R +++ b/R/data.R @@ -173,7 +173,7 @@ #' - `gender`\cr Gender of the patient, either `r vector_or(example_isolates$gender)` #' - `ward`\cr Ward type where the patient was admitted, either `r vector_or(example_isolates$ward)` #' - `mo`\cr ID of microorganism created with [as.mo()], see also the [microorganisms] data set -#' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.rsi))` different antibiotics with class [`rsi`] (see [as.rsi()]); these column names occur in the [antibiotics] data set and can be translated with [set_ab_names()] or [ab_name()] +#' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.sir))` different antibiotics with class [`sir`] (see [as.sir()]); these column names occur in the [antibiotics] data set and can be translated with [set_ab_names()] or [ab_name()] #' @details #' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' @examples @@ -188,7 +188,7 @@ #' - `date`\cr date of receipt at the laboratory #' - `hospital`\cr ID of the hospital, from A to C #' - `bacteria`\cr info about microorganism that can be transformed with [as.mo()], see also [microorganisms] -#' - `AMX:GEN`\cr 4 different antibiotics that have to be transformed with [as.rsi()] +#' - `AMX:GEN`\cr 4 different antibiotics that have to be transformed with [as.sir()] #' @details #' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' @examples @@ -224,19 +224,19 @@ #' - `Inducible clindamycin resistance`\cr Clindamycin can be induced? #' - `Comment`\cr Other comments #' - `Date of data entry`\cr [Date] this data was entered in WHONET -#' - `AMP_ND10:CIP_EE`\cr `r sum(vapply(FUN.VALUE = logical(1), WHONET, is.rsi))` different antibiotics. You can lookup the abbreviations in the [antibiotics] data set, or use e.g. [`ab_name("AMP")`][ab_name()] to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using [as.rsi()]. +#' - `AMP_ND10:CIP_EE`\cr `r sum(vapply(FUN.VALUE = logical(1), WHONET, is.sir))` different antibiotics. You can lookup the abbreviations in the [antibiotics] data set, or use e.g. [`ab_name("AMP")`][ab_name()] to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using [as.sir()]. #' @details #' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw). #' @examples #' WHONET "WHONET" -#' Data Set for R/SI Interpretation +#' Data Set with Clinical Breakpoints for SIR Interpretation #' -#' Data set containing reference data to interpret MIC and disk diffusion to R/SI values, according to international guidelines. Currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`). Use [as.rsi()] to transform MICs or disks measurements to R/SI values. -#' @format A [tibble][tibble::tibble] with `r format(nrow(rsi_translation), big.mark = ",")` observations and `r ncol(rsi_translation)` variables: +#' Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. Currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). Use [as.sir()] to transform MICs or disks measurements to SIR values. +#' @format A [tibble][tibble::tibble] with `r format(nrow(clinical_breakpoints), big.mark = ",")` observations and `r ncol(clinical_breakpoints)` variables: #' - `guideline`\cr Name of the guideline -#' - `method`\cr Either `r vector_or(rsi_translation$method)` +#' - `method`\cr Either `r vector_or(clinical_breakpoints$method)` #' - `site`\cr Body site, e.g. "Oral" or "Respiratory" #' - `mo`\cr Microbial ID, see [as.mo()] #' - `rank_index`\cr Taxonomic rank index of `mo` from 1 (subspecies/infraspecies) to 5 (unknown microorganism) @@ -252,8 +252,8 @@ #' They **allow for machine reading EUCAST and CLSI guidelines**, which is almost impossible with the MS Excel and PDF files distributed by EUCAST and CLSI. #' @seealso [intrinsic_resistant] #' @examples -#' rsi_translation -"rsi_translation" +#' clinical_breakpoints +"clinical_breakpoints" #' Data Set with Bacterial Intrinsic Resistance #' diff --git a/R/deprecated.R b/R/deprecated.R deleted file mode 100755 index 6a3ddc60e..000000000 --- a/R/deprecated.R +++ /dev/null @@ -1,36 +0,0 @@ -# ==================================================================== # -# TITLE # -# AMR: An R Package for Working with Antimicrobial Resistance Data # -# # -# SOURCE # -# https://github.com/msberends/AMR # -# # -# CITE AS # -# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # -# (2022). AMR: An R Package for Working with Antimicrobial Resistance # -# Data. Journal of Statistical Software, 104(3), 1-31. # -# doi:10.18637/jss.v104.i03 # -# # -# Developed at the University of Groningen and the University Medical # -# Center Groningen in The Netherlands, in collaboration with many # -# colleagues from around the world, see our website. # -# # -# 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 the full manual and a complete tutorial about # -# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # -# ==================================================================== # - -#' Deprecated Functions -#' -#' These functions are so-called '[Deprecated]'. **They will be removed in a future release.** Using the functions will give a warning with the name of the function it has been replaced by (if there is one). -#' @keywords internal -#' @name AMR-deprecated -# @export -NULL diff --git a/R/disk.R b/R/disk.R index b5a7572bc..5be9ca65d 100755 --- a/R/disk.R +++ b/R/disk.R @@ -33,13 +33,13 @@ #' @rdname as.disk #' @param x vector #' @param na.rm a [logical] indicating whether missing values should be removed -#' @details Interpret disk values as RSI values with [as.rsi()]. It supports guidelines from EUCAST and CLSI. +#' @details Interpret disk values as SIR values with [as.sir()]. It supports guidelines from EUCAST and CLSI. #' #' Disk diffusion growth zone sizes must be between 6 and 50 millimetres. Values higher than 50 but lower than 100 will be maximised to 50. All others input values outside the 6-50 range will return `NA`. #' @return An [integer] with additional class [`disk`] #' @aliases disk #' @export -#' @seealso [as.rsi()] +#' @seealso [as.sir()] #' @examples #' # transform existing disk zones to the `disk` class (using base R) #' df <- data.frame( @@ -59,8 +59,8 @@ #' } #' } #' -#' # interpret disk values, see ?as.rsi -#' as.rsi( +#' # interpret disk values, see ?as.sir +#' as.sir( #' x = as.disk(18), #' mo = "Strep pneu", # `mo` will be coerced with as.mo() #' ab = "ampicillin", # and `ab` with as.ab() @@ -68,7 +68,7 @@ #' ) #' #' # interpret whole data set, pretend to be all from urinary tract infections: -#' as.rsi(df, uti = TRUE) +#' as.sir(df, uti = TRUE) as.disk <- function(x, na.rm = FALSE) { meet_criteria(x, allow_class = c("disk", "character", "numeric", "integer"), allow_NA = TRUE) meet_criteria(na.rm, allow_class = "logical", has_length = 1) diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 70f26fe1b..67171081a 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -69,11 +69,11 @@ format_eucast_version_nr <- function(version, markdown = TRUE) { #' @param ... column name of an antibiotic, see section *Antibiotics* below #' @param ab any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()] #' @param administration route of administration, either `r vector_or(dosage$administration)` -#' @param only_rsi_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `rsi` (see [as.rsi()]) on beforehand (defaults to `FALSE`) +#' @param only_sir_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `sir` (see [as.sir()]) on beforehand (defaults to `FALSE`) #' @param custom_rules custom rules to apply, created with [custom_eucast_rules()] #' @inheritParams first_isolate #' @details -#' **Note:** This function does not translate MIC values to RSI values. Use [as.rsi()] for that. \cr +#' **Note:** This function does not translate MIC values to SIR values. Use [as.sir()] for that. \cr #' **Note:** When ampicillin (AMP, J01CA01) is not available but amoxicillin (AMX, J01CA04) is, the latter will be used for all rules where there is a dependency on ampicillin. These drugs are interchangeable when it comes to expression of antimicrobial resistance. \cr #' #' The file containing all EUCAST rules is located here: . **Note:** Old taxonomic names are replaced with the current taxonomy where applicable. For example, *Ochrobactrum anthropi* was renamed to *Brucella anthropi* in 2020; the original EUCAST rules v3.1 and v3.2 did not yet contain this new taxonomic name. The `AMR` package contains the full microbial taxonomy updated until `r documentation_date(max(TAXONOMY_VERSION$GBIF$accessed_date, TAXONOMY_VERSION$LPSN$accessed_date))`, see [microorganisms]. @@ -168,7 +168,7 @@ eucast_rules <- function(x, version_breakpoints = 12.0, version_expertrules = 3.3, ampc_cephalosporin_resistance = NA, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, custom_rules = NULL, ...) { meet_criteria(x, allow_class = "data.frame") @@ -178,10 +178,12 @@ eucast_rules <- function(x, meet_criteria(verbose, allow_class = "logical", has_length = 1) meet_criteria(version_breakpoints, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_BREAKPOINTS))) meet_criteria(version_expertrules, allow_class = c("numeric", "integer"), has_length = 1, is_in = as.double(names(EUCAST_VERSION_EXPERT_RULES))) - meet_criteria(ampc_cephalosporin_resistance, allow_class = c("logical", "character", "rsi"), has_length = 1, allow_NA = TRUE, allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(ampc_cephalosporin_resistance, allow_class = c("logical", "character", "sir"), has_length = 1, allow_NA = TRUE, allow_NULL = TRUE) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE) + add_MO_lookup_to_AMR_env() + if ("custom" %in% rules && is.null(custom_rules)) { warning_("in `eucast_rules()`: no custom rules were set with the `custom_rules` argument", immediate = TRUE @@ -240,7 +242,7 @@ eucast_rules <- function(x, } warned <- FALSE - warn_lacking_rsi_class <- character(0) + warn_lacking_sir_class <- character(0) txt_ok <- function(n_added, n_changed, warned = FALSE) { if (warned == FALSE) { if (n_added + n_changed == 0) { @@ -309,7 +311,7 @@ eucast_rules <- function(x, hard_dependencies = NULL, verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "eucast_rules", ... ) @@ -376,11 +378,11 @@ eucast_rules <- function(x, } } } - as.rsi_no_warning <- function(x) { - if (is.rsi(x)) { + as.sir_no_warning <- function(x) { + if (is.sir(x)) { return(x) } - suppressWarnings(as.rsi(x)) + suppressWarnings(as.sir(x)) } # Preparing the data ------------------------------------------------------ @@ -389,8 +391,8 @@ eucast_rules <- function(x, rowid = character(0), col = character(0), mo_fullname = character(0), - old = as.rsi(character(0)), - new = as.rsi(character(0)), + old = as.sir(character(0)), + new = as.sir(character(0)), rule = character(0), rule_group = character(0), rule_name = character(0), @@ -493,14 +495,14 @@ eucast_rules <- function(x, extra_indent = 6 )) } - run_changes <- edit_rsi( + run_changes <- edit_sir( x = x, to = "R", rule = c( rule_current, "Other rules", "", paste0("Non-EUCAST: AMR package v", utils::packageDescription("AMR")$Version) ), - rows = which(as.rsi_no_warning(x[, col_enzyme, drop = TRUE]) == "R"), + rows = which(as.sir_no_warning(x[, col_enzyme, drop = TRUE]) == "R"), cols = col_base, last_verbose_info = verbose_info, original_data = x.bak, @@ -512,7 +514,7 @@ eucast_rules <- function(x, n_changed <- n_changed + run_changes$changed verbose_info <- run_changes$verbose_info x <- run_changes$output - warn_lacking_rsi_class <- c(warn_lacking_rsi_class, run_changes$rsi_warn) + warn_lacking_sir_class <- c(warn_lacking_sir_class, run_changes$sir_warn) # Print number of new changes if (isTRUE(info)) { # print only on last one of rules in this group @@ -534,14 +536,14 @@ eucast_rules <- function(x, extra_indent = 6 )) } - run_changes <- edit_rsi( + run_changes <- edit_sir( x = x, to = "S", rule = c( rule_current, "Other rules", "", paste0("Non-EUCAST: AMR package v", utils::packageDescription("AMR")$Version) ), - rows = which(as.rsi_no_warning(x[, col_base, drop = TRUE]) == "S"), + rows = which(as.sir_no_warning(x[, col_base, drop = TRUE]) == "S"), cols = col_enzyme, last_verbose_info = verbose_info, original_data = x.bak, @@ -553,7 +555,7 @@ eucast_rules <- function(x, n_changed <- n_changed + run_changes$changed verbose_info <- run_changes$verbose_info x <- run_changes$output - warn_lacking_rsi_class <- c(warn_lacking_rsi_class, run_changes$rsi_warn) + warn_lacking_sir_class <- c(warn_lacking_sir_class, run_changes$sir_warn) # Print number of new changes if (isTRUE(info)) { # print only on last one of rules in this group @@ -788,21 +790,21 @@ eucast_rules <- function(x, rows <- integer(0) } else if (length(source_antibiotics) == 1) { rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value & - as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]), + as.sir_no_warning(x[, source_antibiotics[1L]]) == source_value[1L]), error = function(e) integer(0) ) } else if (length(source_antibiotics) == 2) { rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value & - as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] & - as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L]), + as.sir_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] & + as.sir_no_warning(x[, source_antibiotics[2L]]) == source_value[2L]), error = function(e) integer(0) ) # nolint start # } else if (length(source_antibiotics) == 3) { # rows <- tryCatch(which(x[, if_mo_property, drop = TRUE] %like% mo_value - # & as.rsi_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] - # & as.rsi_no_warning(x[, source_antibiotics[2L]]) == source_value[2L] - # & as.rsi_no_warning(x[, source_antibiotics[3L]]) == source_value[3L]), + # & as.sir_no_warning(x[, source_antibiotics[1L]]) == source_value[1L] + # & as.sir_no_warning(x[, source_antibiotics[2L]]) == source_value[2L] + # & as.sir_no_warning(x[, source_antibiotics[3L]]) == source_value[3L]), # error = function(e) integer(0)) # nolint end } else { @@ -814,7 +816,7 @@ eucast_rules <- function(x, # Apply rule on data ------------------------------------------------------ # this will return the unique number of changes - run_changes <- edit_rsi( + run_changes <- edit_sir( x = x, to = target_value, rule = c( @@ -836,7 +838,7 @@ eucast_rules <- function(x, n_changed <- n_changed + run_changes$changed verbose_info <- run_changes$verbose_info x <- run_changes$output - warn_lacking_rsi_class <- c(warn_lacking_rsi_class, run_changes$rsi_warn) + warn_lacking_sir_class <- c(warn_lacking_sir_class, run_changes$sir_warn) # Print number of new changes --------------------------------------------- if (isTRUE(info) && rule_next != rule_current) { # print only on last one of rules in this group @@ -878,7 +880,7 @@ eucast_rules <- function(x, )) warned <- FALSE } - run_changes <- edit_rsi( + run_changes <- edit_sir( x = x, to = target_value, rule = c( @@ -902,7 +904,7 @@ eucast_rules <- function(x, n_changed <- n_changed + run_changes$changed verbose_info <- run_changes$verbose_info x <- run_changes$output - warn_lacking_rsi_class <- c(warn_lacking_rsi_class, run_changes$rsi_warn) + warn_lacking_sir_class <- c(warn_lacking_sir_class, run_changes$sir_warn) # Print number of new changes --------------------------------------------- if (isTRUE(info) && rule_next != rule_current) { # print only on last one of rules in this group @@ -1017,19 +1019,19 @@ eucast_rules <- function(x, } } - if (length(warn_lacking_rsi_class) > 0) { - warn_lacking_rsi_class <- unique(warn_lacking_rsi_class) + if (length(warn_lacking_sir_class) > 0) { + warn_lacking_sir_class <- unique(warn_lacking_sir_class) # take order from original data set - warn_lacking_rsi_class <- warn_lacking_rsi_class[order(colnames(x.bak))] - warn_lacking_rsi_class <- warn_lacking_rsi_class[!is.na(warn_lacking_rsi_class)] + warn_lacking_sir_class <- warn_lacking_sir_class[order(colnames(x.bak))] + warn_lacking_sir_class <- warn_lacking_sir_class[!is.na(warn_lacking_sir_class)] warning_( - "in `eucast_rules()`: not all columns with antimicrobial results are of class 'rsi'. Transform them on beforehand, with e.g.:\n", - " - ", x_deparsed, " %>% as.rsi(", ifelse(length(warn_lacking_rsi_class) == 1, - warn_lacking_rsi_class, - paste0(warn_lacking_rsi_class[1], ":", warn_lacking_rsi_class[length(warn_lacking_rsi_class)]) + "in `eucast_rules()`: not all columns with antimicrobial results are of class 'sir'. Transform them on beforehand, with e.g.:\n", + " - ", x_deparsed, " %>% as.sir(", ifelse(length(warn_lacking_sir_class) == 1, + warn_lacking_sir_class, + paste0(warn_lacking_sir_class[1], ":", warn_lacking_sir_class[length(warn_lacking_sir_class)]) ), ")\n", - " - ", x_deparsed, " %>% mutate_if(is.rsi.eligible, as.rsi)\n", - " - ", x_deparsed, " %>% mutate(across(where(is.rsi.eligible), as.rsi))" + " - ", x_deparsed, " %>% mutate_if(is_sir_eligible, as.sir)\n", + " - ", x_deparsed, " %>% mutate(across(where(is_sir_eligible), as.sir))" ) } @@ -1051,7 +1053,7 @@ eucast_rules <- function(x, } # helper function for editing the table ---- -edit_rsi <- function(x, +edit_sir <- function(x, to, rule, rows, @@ -1069,7 +1071,7 @@ edit_rsi <- function(x, changed = 0, output = x, verbose_info = last_verbose_info, - rsi_warn = character(0) + sir_warn = character(0) ) txt_error <- function() { @@ -1084,8 +1086,8 @@ edit_rsi <- function(x, if (length(rows) > 0 && length(cols) > 0) { new_edits <- x - if (any(!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.rsi), na.rm = TRUE)) { - track_changes$rsi_warn <- cols[!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.rsi)] + if (any(!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.sir), na.rm = TRUE)) { + track_changes$sir_warn <- cols[!vapply(FUN.VALUE = logical(1), x[, cols, drop = FALSE], is.sir)] } tryCatch( # insert into original table diff --git a/R/first_isolate.R b/R/first_isolate.R index 882afae12..06eaf8dff 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -48,7 +48,7 @@ #' @param points_threshold minimum number of points to require before differences in the antibiogram will lead to inclusion of an isolate when `type = "points"`, see *Details* #' @param info a [logical] to indicate info should be printed, defaults to `TRUE` only in interactive mode #' @param include_unknown a [logical] to indicate whether 'unknown' microorganisms should be included too, i.e. microbial code `"UNKNOWN"`, which defaults to `FALSE`. For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default. Isolates with a microbial ID of `NA` will always be excluded as first isolate. -#' @param include_untested_rsi a [logical] to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use `include_untested_rsi = FALSE` to always return `FALSE` for such rows. This checks the data set for columns of class `rsi` and consequently requires transforming columns with antibiotic results using [as.rsi()] first. +#' @param include_untested_sir a [logical] to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use `include_untested_sir = FALSE` to always return `FALSE` for such rows. This checks the data set for columns of class `sir` and consequently requires transforming columns with antibiotic results using [as.sir()] first. #' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], otherwise arguments passed on to [key_antimicrobials()] (such as `universal`, `gram_negative`, `gram_positive`) #' @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. @@ -176,7 +176,7 @@ first_isolate <- function(x = NULL, points_threshold = 2, info = interactive(), include_unknown = FALSE, - include_untested_rsi = TRUE, + include_untested_sir = TRUE, ...) { if (is_null_or_grouped_tbl(x)) { # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) @@ -228,19 +228,19 @@ first_isolate <- function(x = NULL, meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(info, allow_class = "logical", has_length = 1) meet_criteria(include_unknown, allow_class = "logical", has_length = 1) - meet_criteria(include_untested_rsi, allow_class = "logical", has_length = 1) + meet_criteria(include_untested_sir, allow_class = "logical", has_length = 1) # remove data.table, grouping from tibbles, etc. x <- as.data.frame(x, stringsAsFactors = FALSE) - any_col_contains_rsi <- any(vapply( + any_col_contains_sir <- any(vapply( FUN.VALUE = logical(1), X = x, # check only first 10,000 rows - FUN = function(x) any(as.character(x[1:10000]) %in% c("R", "S", "I"), na.rm = TRUE), + FUN = function(x) any(as.character(x[1:10000]) %in% c("S", "I", "R"), na.rm = TRUE), USE.NAMES = FALSE )) - if (method == "phenotype-based" && !any_col_contains_rsi) { + if (method == "phenotype-based" && !any_col_contains_sir) { method <- "episode-based" } if (isTRUE(info) && message_not_thrown_before("first_isolate", "method")) { @@ -285,13 +285,13 @@ first_isolate <- function(x = NULL, type <- "keyantimicrobials" } if (type == "points") { - x$keyantimicrobials <- all_antimicrobials(x, only_rsi_columns = FALSE) + x$keyantimicrobials <- all_antimicrobials(x, only_sir_columns = FALSE) col_keyantimicrobials <- "keyantimicrobials" } else if (type == "keyantimicrobials" && is.null(col_keyantimicrobials)) { col_keyantimicrobials <- search_type_in_df(x = x, type = "keyantimicrobials", info = info) if (is.null(col_keyantimicrobials)) { # still not found as a column, create it ourselves - x$keyantimicrobials <- key_antimicrobials(x, only_rsi_columns = FALSE, col_mo = col_mo, ...) + x$keyantimicrobials <- key_antimicrobials(x, only_sir_columns = FALSE, col_mo = col_mo, ...) col_keyantimicrobials <- "keyantimicrobials" } } @@ -581,13 +581,13 @@ first_isolate <- function(x = NULL, x[which(is.na(x$newvar_mo)), "newvar_first_isolate"] <- FALSE # handle isolates without antibiogram - if (include_untested_rsi == FALSE && any(is.rsi(x))) { - rsi_all_NA <- which(unname(vapply( + if (include_untested_sir == FALSE && any(is.sir(x))) { + sir_all_NA <- which(unname(vapply( FUN.VALUE = logical(1), - as.data.frame(t(x[, is.rsi(x), drop = FALSE])), - function(rsi_values) all(is.na(rsi_values)) + as.data.frame(t(x[, is.sir(x), drop = FALSE])), + function(sir_values) all(is.na(sir_values)) ))) - x[rsi_all_NA, "newvar_first_isolate"] <- FALSE + x[sir_all_NA, "newvar_first_isolate"] <- FALSE } # arrange back according to original sorting again diff --git a/R/ggplot_pca.R b/R/ggplot_pca.R index a0c1f5a7d..3c541003d 100755 --- a/R/ggplot_pca.R +++ b/R/ggplot_pca.R @@ -76,7 +76,7 @@ #' genus = mo_genus(mo) #' ) %>% # and genus as we do here; #' filter(n() >= 30) %>% # filter on only 30 results per group -#' summarise_if(is.rsi, resistance) # then get resistance of all drugs +#' summarise_if(is.sir, resistance) # then get resistance of all drugs #' #' # now conduct PCA for certain antimicrobial drugs #' pca_result <- resistance_data %>% diff --git a/R/ggplot_rsi.R b/R/ggplot_sir.R similarity index 90% rename from R/ggplot_rsi.R rename to R/ggplot_sir.R index 14d435e52..dd9dade43 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_sir.R @@ -30,7 +30,7 @@ #' AMR Plots with `ggplot2` #' #' Use these functions to create bar plots for AMR data analysis. All functions rely on [ggplot2][ggplot2::ggplot()] functions. -#' @param data a [data.frame] with column(s) of class [`rsi`] (see [as.rsi()]) +#' @param data a [data.frame] with column(s) of class [`sir`] (see [as.sir()]) #' @param position position adjustment of bars, either `"fill"`, `"stack"` or `"dodge"` #' @param x variable to show on x axis, either `"antibiotic"` (default) or `"interpretation"` or a grouping variable #' @param fill variable to categorise using the plots legend, either `"antibiotic"` (default) or `"interpretation"` or a grouping variable @@ -41,7 +41,7 @@ #' @param nrow (when using `facet`) number of rows #' @param colours a named vactor with colour to be used for filling. The default colours are colour-blind friendly. #' @param aesthetics aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size" -#' @param datalabels show datalabels using [labels_rsi_count()] +#' @param datalabels show datalabels using [labels_sir_count()] #' @param datalabels.size size of the datalabels #' @param datalabels.colour colour of the datalabels #' @param title text to show as title of the plot @@ -49,24 +49,24 @@ #' @param caption text to show as caption of the plot #' @param x.title text to show as x axis description #' @param y.title text to show as y axis description -#' @param ... other arguments passed on to [geom_rsi()] or, in case of [scale_rsi_colours()], named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See *Examples*. +#' @param ... other arguments passed on to [geom_sir()] or, in case of [scale_sir_colours()], named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See *Examples*. #' @details At default, the names of antibiotics will be shown on the plots using [ab_name()]. This can be set with the `translate_ab` argument. See [count_df()]. #' #' ### The Functions -#' [geom_rsi()] will take any variable from the data that has an [`rsi`] class (created with [as.rsi()]) using [rsi_df()] and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis. +#' [geom_sir()] will take any variable from the data that has an [`sir`] class (created with [as.sir()]) using [sir_df()] and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis. #' -#' [facet_rsi()] creates 2d plots (at default based on S/I/R) using [ggplot2::facet_wrap()]. +#' [facet_sir()] creates 2d plots (at default based on S/I/R) using [ggplot2::facet_wrap()]. #' #' [scale_y_percent()] transforms the y axis to a 0 to 100% range using [ggplot2::scale_y_continuous()]. #' -#' [scale_rsi_colours()] sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. +#' [scale_sir_colours()] sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. #' -#' [theme_rsi()] is a [ggplot2 theme][[ggplot2::theme()] with minimal distraction. +#' [theme_sir()] is a [ggplot2 theme][[ggplot2::theme()] with minimal distraction. #' -#' [labels_rsi_count()] print datalabels on the bars with percentage and amount of isolates using [ggplot2::geom_text()]. +#' [labels_sir_count()] print datalabels on the bars with percentage and amount of isolates using [ggplot2::geom_text()]. #' -#' [ggplot_rsi()] is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (`%>%`). See *Examples*. -#' @rdname ggplot_rsi +#' [ggplot_sir()] is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (`%>%`). See *Examples*. +#' @rdname ggplot_sir #' @export #' @examples #' \donttest{ @@ -74,39 +74,39 @@ #' #' # get antimicrobial results for drugs against a UTI: #' ggplot(example_isolates %>% select(AMX, NIT, FOS, TMP, CIP)) + -#' geom_rsi() +#' geom_sir() #' } #' if (require("ggplot2") && require("dplyr")) { #' #' # prettify the plot using some additional functions: #' df <- example_isolates %>% select(AMX, NIT, FOS, TMP, CIP) #' ggplot(df) + -#' geom_rsi() + +#' geom_sir() + #' scale_y_percent() + -#' scale_rsi_colours() + -#' labels_rsi_count() + -#' theme_rsi() +#' scale_sir_colours() + +#' labels_sir_count() + +#' theme_sir() #' } #' if (require("ggplot2") && require("dplyr")) { #' #' # or better yet, simplify this using the wrapper function - a single command: #' example_isolates %>% #' select(AMX, NIT, FOS, TMP, CIP) %>% -#' ggplot_rsi() +#' ggplot_sir() #' } #' if (require("ggplot2") && require("dplyr")) { #' #' # get only proportions and no counts: #' example_isolates %>% #' select(AMX, NIT, FOS, TMP, CIP) %>% -#' ggplot_rsi(datalabels = FALSE) +#' ggplot_sir(datalabels = FALSE) #' } #' if (require("ggplot2") && require("dplyr")) { #' #' # add other ggplot2 arguments as you like: #' example_isolates %>% #' select(AMX, NIT, FOS, TMP, CIP) %>% -#' ggplot_rsi( +#' ggplot_sir( #' width = 0.5, #' colour = "black", #' size = 1, @@ -119,7 +119,7 @@ #' # you can alter the colours with colour names: #' example_isolates %>% #' select(AMX) %>% -#' ggplot_rsi(colours = c(SI = "yellow")) +#' ggplot_sir(colours = c(SI = "yellow")) #' } #' if (require("ggplot2") && require("dplyr")) { #' @@ -132,7 +132,7 @@ #' ) %>% #' ggplot() + #' geom_col(aes(x = x, y = y, fill = z)) + -#' scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R") +#' scale_sir_colours(Value4 = "S", Value5 = "I", Value6 = "R") #' } #' if (require("ggplot2") && require("dplyr")) { #' @@ -146,14 +146,14 @@ #' # age_groups() is also a function in this AMR package: #' group_by(age_group = age_groups(age)) %>% #' select(age_group, CIP) %>% -#' ggplot_rsi(x = "age_group") +#' ggplot_sir(x = "age_group") #' } #' if (require("ggplot2") && require("dplyr")) { #' #' # a shorter version which also adjusts data label colours: #' example_isolates %>% #' select(AMX, NIT, FOS, TMP, CIP) %>% -#' ggplot_rsi(colours = FALSE) +#' ggplot_sir(colours = FALSE) #' } #' if (require("ggplot2") && require("dplyr")) { #' @@ -163,7 +163,7 @@ #' # select only UTI-specific drugs #' select(ward, AMX, NIT, FOS, TMP, CIP) %>% #' group_by(ward) %>% -#' ggplot_rsi( +#' ggplot_sir( #' x = "ward", #' facet = "antibiotic", #' nrow = 1, @@ -173,7 +173,7 @@ #' ) #' } #' } -ggplot_rsi <- function(data, +ggplot_sir <- function(data, position = NULL, x = "antibiotic", fill = "interpretation", @@ -203,7 +203,7 @@ ggplot_rsi <- function(data, y.title = "Proportion", ...) { stop_ifnot_installed("ggplot2") - meet_criteria(data, allow_class = "data.frame", contains_column_class = "rsi") + meet_criteria(data, allow_class = "data.frame", contains_column_class = "sir") meet_criteria(position, allow_class = "character", has_length = 1, is_in = c("fill", "stack", "dodge"), allow_NULL = TRUE) meet_criteria(x, allow_class = "character", has_length = 1) meet_criteria(fill, allow_class = "character", has_length = 1) @@ -249,15 +249,15 @@ ggplot_rsi <- function(data, } p <- ggplot2::ggplot(data = data) + - geom_rsi( + geom_sir( position = position, x = x, fill = fill, translate_ab = translate_ab, minimum = minimum, language = language, combine_SI = combine_SI, ... ) + - theme_rsi() + theme_sir() if (fill == "interpretation") { - p <- p + scale_rsi_colours(colours = colours) + p <- p + scale_sir_colours(colours = colours) } if (identical(position, "fill")) { @@ -266,7 +266,7 @@ ggplot_rsi <- function(data, } if (datalabels == TRUE) { - p <- p + labels_rsi_count( + p <- p + labels_sir_count( position = position, x = x, translate_ab = translate_ab, @@ -279,7 +279,7 @@ ggplot_rsi <- function(data, } if (!is.null(facet)) { - p <- p + facet_rsi(facet = facet, nrow = nrow) + p <- p + facet_sir(facet = facet, nrow = nrow) } p <- p + ggplot2::labs( @@ -293,9 +293,9 @@ ggplot_rsi <- function(data, p } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export -geom_rsi <- function(position = NULL, +geom_sir <- function(position = NULL, x = c("antibiotic", "interpretation"), fill = "interpretation", translate_ab = "name", @@ -334,13 +334,13 @@ geom_rsi <- function(position = NULL, if (tolower(x) %in% tolower(c("ab", "abx", "antibiotics"))) { x <- "antibiotic" - } else if (tolower(x) %in% tolower(c("SIR", "RSI", "interpretations", "result"))) { + } else if (tolower(x) %in% tolower(c("SIR", "sir", "interpretations", "result"))) { x <- "interpretation" } ggplot2::geom_col( data = function(x) { - rsi_df( + sir_df( data = x, translate_ab = translate_ab, language = language, @@ -354,9 +354,9 @@ geom_rsi <- function(position = NULL, ) } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export -facet_rsi <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { +facet_sir <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { facet <- facet[1] stop_ifnot_installed("ggplot2") meet_criteria(facet, allow_class = "character", has_length = 1) @@ -371,7 +371,7 @@ facet_rsi <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { facet <- substr(facet, 2, nchar(facet) - 1) } - if (tolower(facet) %in% tolower(c("SIR", "RSI", "interpretations", "result"))) { + if (tolower(facet) %in% tolower(c("SIR", "sir", "interpretations", "result"))) { facet <- "interpretation" } else if (tolower(facet) %in% tolower(c("ab", "abx", "antibiotics"))) { facet <- "antibiotic" @@ -380,7 +380,7 @@ facet_rsi <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { ggplot2::facet_wrap(facets = facet, scales = "free_x", nrow = nrow) } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) { stop_ifnot_installed("ggplot2") @@ -397,13 +397,13 @@ scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) { ) } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export -scale_rsi_colours <- function(..., +scale_sir_colours <- function(..., aesthetics = "fill") { stop_ifnot_installed("ggplot2") meet_criteria(aesthetics, allow_class = "character", is_in = c("alpha", "colour", "color", "fill", "linetype", "shape", "size")) - # behaviour until AMR pkg v1.5.0 and also when coming from ggplot_rsi() + # behaviour until AMR pkg v1.5.0 and also when coming from ggplot_sir() if ("colours" %in% names(list(...))) { original_cols <- c( S = "#3CAEA3", @@ -457,7 +457,7 @@ scale_rsi_colours <- function(..., original_cols <- c(susceptible, incr_exposure, resistant) dots <- c(...) - # replace S, I, R as colours: scale_rsi_colours(mydatavalue = "S") + # replace S, I, R as colours: scale_sir_colours(mydatavalue = "S") dots[dots == "S"] <- "#3CAEA3" dots[dots == "I"] <- "#F6D55C" dots[dots == "R"] <- "#ED553B" @@ -467,9 +467,9 @@ scale_rsi_colours <- function(..., ggplot2::scale_discrete_manual(aesthetics = aesthetics, values = cols, limits = force) } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export -theme_rsi <- function() { +theme_sir <- function() { stop_ifnot_installed("ggplot2") ggplot2::theme_minimal(base_size = 10) + ggplot2::theme( @@ -482,9 +482,9 @@ theme_rsi <- function() { ) } -#' @rdname ggplot_rsi +#' @rdname ggplot_sir #' @export -labels_rsi_count <- function(position = NULL, +labels_sir_count <- function(position = NULL, x = "antibiotic", translate_ab = "name", minimum = 30, @@ -521,7 +521,7 @@ labels_rsi_count <- function(position = NULL, colour = datalabels.colour, lineheight = 0.75, data = function(x) { - transformed <- rsi_df( + transformed <- sir_df( data = x, translate_ab = translate_ab, combine_SI = combine_SI, diff --git a/R/guess_ab_col.R b/R/guess_ab_col.R index dc6dccbac..e14341d58 100755 --- a/R/guess_ab_col.R +++ b/R/guess_ab_col.R @@ -33,7 +33,7 @@ #' @param x a [data.frame] #' @param search_string a text to search `x` for, will be checked with [as.ab()] if this value is not a column in `x` #' @param verbose a [logical] to indicate whether additional info should be printed -#' @param only_rsi_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `rsi` (see [as.rsi()]) on beforehand (defaults to `FALSE`) +#' @param only_sir_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `sir` (see [as.sir()]) on beforehand (defaults to `FALSE`) #' @details You can look for an antibiotic (trade) name or abbreviation and it will search `x` and the [antibiotics] data set for any column containing a name or code of that antibiotic. #' @return A column name of `x`, or `NULL` when no result is found. #' @export @@ -57,11 +57,11 @@ #' guess_ab_col(df, "ampicillin") #' guess_ab_col(df, "J01CR02") #' guess_ab_col(df, as.ab("augmentin")) -guess_ab_col <- function(x = NULL, search_string = NULL, verbose = FALSE, only_rsi_columns = FALSE) { +guess_ab_col <- function(x = NULL, search_string = NULL, verbose = FALSE, only_sir_columns = FALSE) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) meet_criteria(search_string, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(verbose, allow_class = "logical", has_length = 1) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) if (is.null(x) && is.null(search_string)) { return(as.name("guess_ab_col")) @@ -70,7 +70,7 @@ guess_ab_col <- function(x = NULL, search_string = NULL, verbose = FALSE, only_r } all_found <- get_column_abx(x, - info = verbose, only_rsi_columns = only_rsi_columns, + info = verbose, only_sir_columns = only_sir_columns, verbose = verbose, fn = "guess_ab_col" ) search_string.ab <- suppressWarnings(as.ab(search_string)) @@ -102,7 +102,7 @@ get_column_abx <- function(x, hard_dependencies = NULL, verbose = FALSE, info = TRUE, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, sort = TRUE, reuse_previous_result = TRUE, fn = NULL) { @@ -125,8 +125,8 @@ get_column_abx <- function(x, new_cols <- colnames(x)[!colnames(x) %in% AMR_env$get_column_abx.checked_cols] if (length(new_cols) > 0) { # these columns did not exist in the last call, so add them - new_cols_rsi <- get_column_abx(x[, new_cols, drop = FALSE], reuse_previous_result = FALSE, info = FALSE, sort = FALSE) - current <- c(current, new_cols_rsi) + new_cols_sir <- get_column_abx(x[, new_cols, drop = FALSE], reuse_previous_result = FALSE, info = FALSE, sort = FALSE) + current <- c(current, new_cols_sir) # order according to columns in current call current <- current[match(colnames(x)[colnames(x) %in% current], current)] } @@ -144,7 +144,7 @@ get_column_abx <- function(x, meet_criteria(hard_dependencies, allow_class = "character", allow_NULL = TRUE) meet_criteria(verbose, allow_class = "logical", has_length = 1) meet_criteria(info, allow_class = "logical", has_length = 1) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) meet_criteria(sort, allow_class = "logical", has_length = 1) if (isTRUE(info)) { @@ -153,8 +153,8 @@ get_column_abx <- function(x, x <- as.data.frame(x, stringsAsFactors = FALSE) x.bak <- x - if (only_rsi_columns == TRUE) { - x <- x[, which(is.rsi(x)), drop = FALSE] + if (only_sir_columns == TRUE) { + x <- x[, which(is.sir(x)), drop = FALSE] } if (NROW(x) > 10000) { @@ -171,7 +171,7 @@ get_column_abx <- function(x, } # only check columns that are a valid AB code, ATC code, name, abbreviation or synonym, - # or already have the 'rsi' class (as.rsi) + # or already have the 'sir' class (as.sir) # and that they have no more than 50% invalid values vectr_antibiotics <- unlist(AMR_env$AB_lookup$generalised_all) vectr_antibiotics <- vectr_antibiotics[!is.na(vectr_antibiotics) & nchar(vectr_antibiotics) >= 3] @@ -180,8 +180,8 @@ get_column_abx <- function(x, colnames(x), function(col, df = x) { if (generalise_antibiotic_name(col) %in% vectr_antibiotics || - is.rsi(x[, col, drop = TRUE]) || - is.rsi.eligible(x[, col, drop = TRUE], threshold = 0.5) + is.sir(x[, col, drop = TRUE]) || + is_sir_eligible(x[, col, drop = TRUE], threshold = 0.5) ) { return(col) } else { diff --git a/R/italicise_taxonomy.R b/R/italicise_taxonomy.R index 652bc0330..7e9758bef 100755 --- a/R/italicise_taxonomy.R +++ b/R/italicise_taxonomy.R @@ -51,6 +51,8 @@ italicise_taxonomy <- function(string, type = c("markdown", "ansi")) { meet_criteria(string, allow_class = "character") meet_criteria(type, allow_class = "character", has_length = 1, is_in = c("markdown", "ansi")) + add_MO_lookup_to_AMR_env() + if (type == "markdown") { before <- "*" after <- "*" diff --git a/R/join_microorganisms.R b/R/join_microorganisms.R index da93fa502..b29d6542a 100755 --- a/R/join_microorganisms.R +++ b/R/join_microorganisms.R @@ -127,6 +127,8 @@ anti_join_microorganisms <- function(x, by = NULL, ...) { } join_microorganisms <- function(type, x, by, suffix, ...) { + add_MO_lookup_to_AMR_env() + if (!is.data.frame(x)) { if (pkg_is_available("tibble", also_load = FALSE)) { x <- import_fn("tibble", "tibble")(mo = x) diff --git a/R/key_antimicrobials.R b/R/key_antimicrobials.R index 27236092a..875c5e654 100755 --- a/R/key_antimicrobials.R +++ b/R/key_antimicrobials.R @@ -37,7 +37,7 @@ #' @param gram_negative names of antibiotic drugs for **Gram-positives**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default antibiotic drugs #' @param gram_positive names of antibiotic drugs for **Gram-negatives**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default antibiotic drugs #' @param antifungal names of antifungal drugs for **fungi**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default antifungal drugs -#' @param only_rsi_columns a [logical] to indicate whether only columns must be included that were transformed to class `rsi` (see [as.rsi()]) on beforehand (defaults to `FALSE`) +#' @param only_sir_columns a [logical] to indicate whether only columns must be included that were transformed to class `sir` (see [as.sir()]) on beforehand (defaults to `FALSE`) #' @param ... ignored, only in place to allow future extensions #' @details #' 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*. @@ -135,7 +135,7 @@ key_antimicrobials <- function(x = NULL, "anidulafungin", "caspofungin", "fluconazole", "miconazole", "nystatin", "voriconazole" ), - only_rsi_columns = FALSE, + only_sir_columns = FALSE, ...) { if (is_null_or_grouped_tbl(x)) { # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) @@ -148,11 +148,11 @@ key_antimicrobials <- function(x = NULL, meet_criteria(gram_negative, allow_class = "character", allow_NULL = TRUE) meet_criteria(gram_positive, allow_class = "character", allow_NULL = TRUE) meet_criteria(antifungal, allow_class = "character", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) # force regular data.frame, not a tibble or data.table x <- as.data.frame(x, stringsAsFactors = FALSE) - cols <- get_column_abx(x, info = FALSE, only_rsi_columns = only_rsi_columns, fn = "key_antimicrobials") + cols <- get_column_abx(x, info = FALSE, only_sir_columns = only_sir_columns, fn = "key_antimicrobials") # try to find columns based on type # -- mo @@ -247,7 +247,7 @@ key_antimicrobials <- function(x = NULL, #' @rdname key_antimicrobials #' @export all_antimicrobials <- function(x = NULL, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, ...) { if (is_null_or_grouped_tbl(x)) { # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) @@ -255,12 +255,12 @@ all_antimicrobials <- function(x = NULL, x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x) } meet_criteria(x, allow_class = "data.frame") # also checks dimensions to be >0 - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) # force regular data.frame, not a tibble or data.table x <- as.data.frame(x, stringsAsFactors = FALSE) cols <- get_column_abx(x, - only_rsi_columns = only_rsi_columns, info = FALSE, + only_sir_columns = only_sir_columns, info = FALSE, sort = FALSE, fn = "all_antimicrobials" ) @@ -282,7 +282,7 @@ generate_antimcrobials_string <- function(df) { as.list(df), function(x) { x <- toupper(as.character(x)) - x[!x %in% c("R", "S", "I")] <- "." + x[!x %in% c("S", "I", "R")] <- "." paste(x) } ) @@ -308,7 +308,7 @@ antimicrobials_equal <- function(y, meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) stop_ifnot(length(y) == length(z), "length of `y` and `z` must be equal") - key2rsi <- function(val) { + key2sir <- function(val) { val <- strsplit(val, "", fixed = TRUE)[[1L]] val.int <- rep(NA_real_, length(val)) val.int[val == "S"] <- 1 @@ -318,7 +318,7 @@ antimicrobials_equal <- function(y, } # only run on uniques uniq <- unique(c(y, z)) - uniq_list <- lapply(uniq, key2rsi) + uniq_list <- lapply(uniq, key2sir) names(uniq_list) <- uniq y <- uniq_list[match(y, names(uniq_list))] @@ -339,12 +339,12 @@ antimicrobials_equal <- function(y, # - no change is 0 points # - I <-> S|R is 0.5 point # - S|R <-> R|S is 1 point - # use the levels of as.rsi (S = 1, I = 2, R = 3) + # use the levels of as.sir (S = 1, I = 2, R = 3) # and divide by 2 (S = 0.5, I = 1, R = 1.5) (sum(abs(a - b), na.rm = TRUE) / 2) < points_threshold } else { if (ignore_I == TRUE) { - ind <- which(a == 2 | b == 2) # since as.double(as.rsi("I")) == 2 + ind <- which(a == 2 | b == 2) # since as.double(as.sir("I")) == 2 a[ind] <- NA_real_ b[ind] <- NA_real_ } diff --git a/R/mdro.R b/R/mdro.R index ee17a05c3..8c2f4bd29 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -127,7 +127,7 @@ #' ``` #' #' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()]. -#' @inheritSection as.rsi Interpretation of R and S/I +#' @inheritSection as.sir Interpretation of SIR #' @return #' - CMI 2012 paper - function [mdr_cmi2012()] or [mdro()]:\cr #' Ordered [factor] with levels `Negative` < `Multi-drug-resistant (MDR)` < `Extensively drug-resistant (XDR)` < `Pandrug-resistant (PDR)` @@ -175,7 +175,7 @@ mdro <- function(x = NULL, pct_required_classes = 0.5, combine_SI = TRUE, verbose = FALSE, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, ...) { if (is_null_or_grouped_tbl(x)) { # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) @@ -192,10 +192,10 @@ mdro <- function(x = NULL, meet_criteria(pct_required_classes, allow_class = "numeric", has_length = 1) meet_criteria(combine_SI, allow_class = "logical", has_length = 1) meet_criteria(verbose, allow_class = "logical", has_length = 1) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) - if (!any(is.rsi.eligible(x))) { - stop_("There were no possible R/SI columns found in the data set. Transform columns with `as.rsi()` for valid antimicrobial interpretations.") + if (!any(is_sir_eligible(x))) { + stop_("There were no possible SIR columns found in the data set. Transform columns with `as.sir()` for valid antimicrobial interpretations.") } info.bak <- info @@ -325,7 +325,7 @@ mdro <- function(x = NULL, "No column found as input for `col_mo`, ", font_bold(paste0("assuming all rows contain ", font_italic("Mycobacterium tuberculosis"), ".")) ) - x$mo <- as.mo("Mycobacterium tuberculosis") # consider overkill at all times: AMR_env$MO_lookup[which(AMR_env$MO_lookup$fullname == "Mycobacterium tuberculosis"), "mo", drop = TRUE] + x$mo <- as.mo("Mycobacterium tuberculosis", keep_synonyms = TRUE) col_mo <- "mo" } stop_if(is.null(col_mo), "`col_mo` must be set") @@ -382,226 +382,60 @@ mdro <- function(x = NULL, cols_ab <- get_column_abx( x = x, soft_dependencies = c( - # [table] 1 (S aureus): - "GEN", - "RIF", - "CPT", - "OXA", - "CIP", - "MFX", - "SXT", - "FUS", - "VAN", - "TEC", - "TLV", - "TGC", - "CLI", - "DAP", - "ERY", - "LNZ", - "CHL", - "FOS", - "QDA", - "TCY", - "DOX", - "MNO", + # [table] 1 (S aureus) + "GEN", "RIF", "CPT", "OXA", "CIP", "MFX", "SXT", "FUS", "VAN", "TEC", "TLV", "TGC", "CLI", "DAP", "ERY", "LNZ", "CHL", "FOS", "QDA", "TCY", "DOX", "MNO", # [table] 2 (Enterococcus) - "GEH", - "STH", - "IPM", - "MEM", - "DOR", - "CIP", - "LVX", - "MFX", - "VAN", - "TEC", - "TGC", - "DAP", - "LNZ", - "AMP", - "QDA", - "DOX", - "MNO", + "GEH", "STH", "IPM", "MEM", "DOR", "CIP", "LVX", "MFX", "VAN", "TEC", "TGC", "DAP", "LNZ", "AMP", "QDA", "DOX", "MNO", # [table] 3 (Enterobacteriaceae) - "GEN", - "TOB", - "AMK", - "NET", - "CPT", - "TCC", - "TZP", - "ETP", - "IPM", - "MEM", - "DOR", - "CZO", - "CXM", - "CTX", - "CAZ", - "FEP", - "FOX", - "CTT", - "CIP", - "SXT", - "TGC", - "ATM", - "AMP", - "AMC", - "SAM", - "CHL", - "FOS", - "COL", - "TCY", - "DOX", - "MNO", + "GEN", "TOB", "AMK", "NET", "CPT", "TCC", "TZP", "ETP", "IPM", "MEM", "DOR", "CZO", "CXM", "CTX", "CAZ", "FEP", "FOX", "CTT", "CIP", "SXT", "TGC", "ATM", "AMP", "AMC", "SAM", "CHL", "FOS", "COL", "TCY", "DOX", "MNO", # [table] 4 (Pseudomonas) - "GEN", - "TOB", - "AMK", - "NET", - "IPM", - "MEM", - "DOR", - "CAZ", - "FEP", - "CIP", - "LVX", - "TCC", - "TZP", - "ATM", - "FOS", - "COL", - "PLB", + "GEN", "TOB", "AMK", "NET", "IPM", "MEM", "DOR", "CAZ", "FEP", "CIP", "LVX", "TCC", "TZP", "ATM", "FOS", "COL", "PLB", # [table] 5 (Acinetobacter) - "GEN", - "TOB", - "AMK", - "NET", - "IPM", - "MEM", - "DOR", - "CIP", - "LVX", - "TZP", - "TCC", - "CTX", - "CRO", - "CAZ", - "FEP", - "SXT", - "SAM", - "COL", - "PLB", - "TCY", - "DOX", - "MNO" + "GEN", "TOB", "AMK", "NET", "IPM", "MEM", "DOR", "CIP", "LVX", "TZP", "TCC", "CTX", "CRO", "CAZ", "FEP", "SXT", "SAM", "COL", "PLB", "TCY", "DOX", "MNO" ), verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) } else if (guideline$code == "eucast3.2") { cols_ab <- get_column_abx( x = x, - soft_dependencies = c( - "AMP", - "AMX", - "CIP", - "DAL", - "DAP", - "ERV", - "FDX", - "GEN", - "LNZ", - "MEM", - "MTR", - "OMC", - "ORI", - "PEN", - "QDA", - "RIF", - "TEC", - "TGC", - "TLV", - "TOB", - "TZD", - "VAN" - ), + soft_dependencies = c("AMP", "AMX", "CIP", "DAL", "DAP", "ERV", "FDX", "GEN", "LNZ", "MEM", "MTR", "OMC", "ORI", "PEN", "QDA", "RIF", "TEC", "TGC", "TLV", "TOB", "TZD", "VAN"), verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) } else if (guideline$code == "eucast3.3") { cols_ab <- get_column_abx( x = x, - soft_dependencies = c( - "AMP", - "AMX", - "CIP", - "DAL", - "DAP", - "ERV", - "FDX", - "GEN", - "LNZ", - "MEM", - "MTR", - "OMC", - "ORI", - "PEN", - "QDA", - "RIF", - "TEC", - "TGC", - "TLV", - "TOB", - "TZD", - "VAN" - ), + soft_dependencies = c("AMP", "AMX", "CIP", "DAL", "DAP", "ERV", "FDX", "GEN", "LNZ", "MEM", "MTR", "OMC", "ORI", "PEN", "QDA", "RIF", "TEC", "TGC", "TLV", "TOB", "TZD", "VAN"), verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) } else if (guideline$code == "tb") { cols_ab <- get_column_abx( x = x, - soft_dependencies = c( - "CAP", - "ETH", - "GAT", - "INH", - "PZA", - "RIF", - "RIB", - "RFP" - ), + soft_dependencies = c("CAP", "ETH", "GAT", "INH", "PZA", "RIF", "RIB", "RFP"), verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) } else if (guideline$code == "mrgn") { cols_ab <- get_column_abx( x = x, - soft_dependencies = c( - "PIP", - "CTX", - "CAZ", - "IPM", - "MEM", - "CIP" - ), + soft_dependencies = c("PIP", "CTX", "CAZ", "IPM", "MEM", "CIP"), verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) @@ -610,7 +444,7 @@ mdro <- function(x = NULL, x = x, verbose = verbose, info = info, - only_rsi_columns = only_rsi_columns, + only_sir_columns = only_sir_columns, fn = "mdro", ... ) @@ -823,7 +657,7 @@ mdro <- function(x = NULL, if (length(rows) > 0 && length(cols) > 0) { x[, cols] <- as.data.frame(lapply( x[, cols, drop = FALSE], - function(col) as.rsi(col) + function(col) as.sir(col) ), stringsAsFactors = FALSE ) @@ -883,7 +717,7 @@ mdro <- function(x = NULL, x[, lst_vector] <- as.data.frame(lapply( x[, lst_vector, drop = FALSE], - function(col) as.rsi(col) + function(col) as.sir(col) ), stringsAsFactors = FALSE ) @@ -1675,7 +1509,7 @@ mdro <- function(x = NULL, ab <- x[, ab, drop = TRUE] } } - ab <- as.character(as.rsi(ab)) + ab <- as.character(as.sir(ab)) ab[is.na(ab)] <- "" ab } @@ -1998,7 +1832,7 @@ run_custom_mdro_guideline <- function(df, guideline, info) { out <- factor(out, levels = attributes(guideline)$values, ordered = TRUE) } - columns_nonsusceptible <- as.data.frame(t(df[, is.rsi(df), drop = FALSE] == "R")) + columns_nonsusceptible <- as.data.frame(t(df[, is.sir(df), drop = FALSE] == "R")) columns_nonsusceptible <- vapply( FUN.VALUE = character(1), columns_nonsusceptible, @@ -2017,60 +1851,60 @@ run_custom_mdro_guideline <- function(df, guideline, info) { #' @rdname mdro #' @export -brmo <- function(x = NULL, only_rsi_columns = FALSE, ...) { +brmo <- function(x = NULL, only_sir_columns = FALSE, ...) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) stop_if( "guideline" %in% names(list(...)), "argument `guideline` must not be set since this is a guideline-specific function" ) - mdro(x = x, only_rsi_columns = only_rsi_columns, guideline = "BRMO", ...) + mdro(x = x, only_sir_columns = only_sir_columns, guideline = "BRMO", ...) } #' @rdname mdro #' @export -mrgn <- function(x = NULL, only_rsi_columns = FALSE, ...) { +mrgn <- function(x = NULL, only_sir_columns = FALSE, ...) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) stop_if( "guideline" %in% names(list(...)), "argument `guideline` must not be set since this is a guideline-specific function" ) - mdro(x = x, only_rsi_columns = only_rsi_columns, guideline = "MRGN", ...) + mdro(x = x, only_sir_columns = only_sir_columns, guideline = "MRGN", ...) } #' @rdname mdro #' @export -mdr_tb <- function(x = NULL, only_rsi_columns = FALSE, ...) { +mdr_tb <- function(x = NULL, only_sir_columns = FALSE, ...) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) stop_if( "guideline" %in% names(list(...)), "argument `guideline` must not be set since this is a guideline-specific function" ) - mdro(x = x, only_rsi_columns = only_rsi_columns, guideline = "TB", ...) + mdro(x = x, only_sir_columns = only_sir_columns, guideline = "TB", ...) } #' @rdname mdro #' @export -mdr_cmi2012 <- function(x = NULL, only_rsi_columns = FALSE, ...) { +mdr_cmi2012 <- function(x = NULL, only_sir_columns = FALSE, ...) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) stop_if( "guideline" %in% names(list(...)), "argument `guideline` must not be set since this is a guideline-specific function" ) - mdro(x = x, only_rsi_columns = only_rsi_columns, guideline = "CMI2012", ...) + mdro(x = x, only_sir_columns = only_sir_columns, guideline = "CMI2012", ...) } #' @rdname mdro #' @export -eucast_exceptional_phenotypes <- function(x = NULL, only_rsi_columns = FALSE, ...) { +eucast_exceptional_phenotypes <- function(x = NULL, only_sir_columns = FALSE, ...) { meet_criteria(x, allow_class = "data.frame", allow_NULL = TRUE) - meet_criteria(only_rsi_columns, allow_class = "logical", has_length = 1) + meet_criteria(only_sir_columns, allow_class = "logical", has_length = 1) stop_if( "guideline" %in% names(list(...)), "argument `guideline` must not be set since this is a guideline-specific function" ) - mdro(x = x, only_rsi_columns = only_rsi_columns, guideline = "EUCAST", ...) + mdro(x = x, only_sir_columns = only_sir_columns, guideline = "EUCAST", ...) } diff --git a/R/mean_amr_distance.R b/R/mean_amr_distance.R index 591c6bfc8..218e36da3 100755 --- a/R/mean_amr_distance.R +++ b/R/mean_amr_distance.R @@ -30,14 +30,14 @@ #' Calculate the Mean AMR Distance #' #' Calculates a normalised mean for antimicrobial resistance between multiple observations, to help to identify similar isolates without comparing antibiograms by hand. -#' @param x a vector of class [rsi][as.rsi()], [mic][as.mic()] or [disk][as.disk()], or a [data.frame] containing columns of any of these classes +#' @param x a vector of class [sir][as.sir()], [mic][as.mic()] or [disk][as.disk()], or a [data.frame] containing columns of any of these classes #' @param ... variables to select (supports [tidyselect language][tidyselect::language] such as `column1:column4` and `where(is.mic)`, and can thus also be [antibiotic selectors][ab_selector()] #' @param combine_SI a [logical] to indicate whether all values of S and I must be merged into one, so the input only consists of S+I vs. R (susceptible vs. resistant), defaults to `TRUE` #' @details The mean AMR distance is effectively [the Z-score](https://en.wikipedia.org/wiki/Standard_score); a normalised numeric value to compare AMR test results which can help to identify similar isolates, without comparing antibiograms by hand. #' #' MIC values (see [as.mic()]) are transformed with [log2()] first; their distance is thus calculated as `(log2(x) - mean(log2(x))) / sd(log2(x))`. #' -#' R/SI values (see [as.rsi()]) are transformed using `"S"` = 1, `"I"` = 2, and `"R"` = 3. If `combine_SI` is `TRUE` (default), the `"I"` will be considered to be 1. +#' SIR values (see [as.sir()]) are transformed using `"S"` = 1, `"I"` = 2, and `"R"` = 3. If `combine_SI` is `TRUE` (default), the `"I"` will be considered to be 1. #' #' For data sets, the mean AMR distance will be calculated per column, after which the mean per row will be returned, see *Examples*. #' @@ -46,9 +46,9 @@ #' Isolates with distances less than 0.01 difference from each other should be considered similar. Differences lower than 0.025 should be considered suspicious. #' @export #' @examples -#' rsi <- random_rsi(10) -#' rsi -#' mean_amr_distance(rsi) +#' sir <- random_sir(10) +#' sir +#' mean_amr_distance(sir) #' #' mic <- random_mic(10) #' mic @@ -62,7 +62,7 @@ #' #' y <- data.frame( #' id = LETTERS[1:10], -#' amox = random_rsi(10, ab = "amox", mo = "Escherichia coli"), +#' amox = random_sir(10, ab = "amox", mo = "Escherichia coli"), #' cipr = random_disk(10, ab = "cipr", mo = "Escherichia coli"), #' gent = random_mic(10, ab = "gent", mo = "Escherichia coli"), #' tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli") @@ -115,7 +115,7 @@ mean_amr_distance.disk <- function(x, ...) { #' @rdname mean_amr_distance #' @export -mean_amr_distance.rsi <- function(x, ..., combine_SI = TRUE) { +mean_amr_distance.sir <- function(x, ..., combine_SI = TRUE) { meet_criteria(combine_SI, allow_class = "logical", has_length = 1, .call_depth = -1) if (isTRUE(combine_SI)) { x[x == "I"] <- "S" diff --git a/R/mic.R b/R/mic.R index d4218b644..1b98473db 100755 --- a/R/mic.R +++ b/R/mic.R @@ -77,7 +77,7 @@ valid_mic_levels <- c( #' @param x a [character] or [numeric] vector #' @param na.rm a [logical] indicating whether missing values should be removed #' @param ... arguments passed on to methods -#' @details To interpret MIC values as RSI values, use [as.rsi()] on MIC values. It supports guidelines from EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`). +#' @details To interpret MIC values as SIR values, use [as.sir()] on MIC values. It supports guidelines from EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). #' #' This class for MIC values is a quite a special data type: formally it is an ordered [factor] with valid MIC values as [factor] levels (to make sure only valid MIC values are retained), but for any mathematical operation it acts as decimal numbers: #' @@ -123,13 +123,13 @@ valid_mic_levels <- c( #' @return Ordered [factor] with additional class [`mic`], that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a [numeric] value. #' @aliases mic #' @export -#' @seealso [as.rsi()] +#' @seealso [as.sir()] #' @examples #' mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16")) #' mic_data #' is.mic(mic_data) #' -#' # this can also coerce combined MIC/RSI values: +#' # this can also coerce combined MIC/SIR values: #' as.mic("<=0.002; S") #' #' # mathematical processing treats MICs as numeric values @@ -138,13 +138,13 @@ valid_mic_levels <- c( #' all(mic_data < 512) #' #' # interpret MIC values -#' as.rsi( +#' as.sir( #' x = as.mic(2), #' mo = as.mo("Streptococcus pneumoniae"), #' ab = "AMX", #' guideline = "EUCAST" #' ) -#' as.rsi( +#' as.sir( #' x = as.mic(c(0.01, 2, 4, 8)), #' mo = as.mo("Streptococcus pneumoniae"), #' ab = "AMX", diff --git a/R/mo.R b/R/mo.R index f4cbb64af..9d66f99d9 100755 --- a/R/mo.R +++ b/R/mo.R @@ -164,6 +164,8 @@ as.mo <- function(x, language <- validate_language(language) meet_criteria(info, allow_class = "logical", has_length = 1) + add_MO_lookup_to_AMR_env() + if (tryCatch(all(x %in% c(AMR_env$MO_lookup$mo, NA)) && isFALSE(Becker) && isFALSE(Lancefield), error = function(e) FALSE)) { @@ -492,6 +494,7 @@ mo_uncertainties <- function() { #' @rdname as.mo #' @export mo_renamed <- function() { + add_MO_lookup_to_AMR_env() x <- AMR_env$mo_renamed x$new <- synonym_mo_to_accepted_mo(x$old) @@ -547,6 +550,7 @@ mo_cleaning_regex <- function() { # will be exported using s3_register() in R/zzz.R pillar_shaft.mo <- function(x, ...) { + add_MO_lookup_to_AMR_env() out <- format(x) # grey out the kingdom (part until first "_") out[!is.na(x)] <- gsub("^([A-Z]+_)(.*)", paste0(font_subtle("\\1"), "\\2"), out[!is.na(x)], perl = TRUE) @@ -664,6 +668,7 @@ get_skimmers.mo <- function(column) { #' @export #' @noRd print.mo <- function(x, print.shortnames = FALSE, ...) { + add_MO_lookup_to_AMR_env() cat("Class 'mo'\n") x_names <- names(x) if (is.null(x_names) & print.shortnames == TRUE) { @@ -704,6 +709,7 @@ summary.mo <- function(object, ...) { #' @export #' @noRd as.data.frame.mo <- function(x, ...) { + add_MO_lookup_to_AMR_env() if (!all(x %in% c(AMR_env$MO_lookup$mo, NA))) { warning_( "The data contains old MO codes (from a previous AMR package version). ", @@ -741,6 +747,7 @@ as.data.frame.mo <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(i) # must only contain valid MOs + add_MO_lookup_to_AMR_env() return_after_integrity_check(y, "microorganism code", as.character(AMR_env$MO_lookup$mo)) } #' @method [[<- mo @@ -750,6 +757,7 @@ as.data.frame.mo <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(i) # must only contain valid MOs + add_MO_lookup_to_AMR_env() return_after_integrity_check(y, "microorganism code", as.character(AMR_env$MO_lookup$mo)) } #' @method c mo @@ -759,6 +767,7 @@ c.mo <- function(...) { x <- list(...)[[1L]] y <- NextMethod() attributes(y) <- attributes(x) + add_MO_lookup_to_AMR_env() return_after_integrity_check(y, "microorganism code", as.character(AMR_env$MO_lookup$mo)) } @@ -788,6 +797,8 @@ print.mo_uncertainties <- function(x, ...) { cat(word_wrap("No uncertainties to show. Only uncertainties of the last call of `as.mo()` or any `mo_*()` function are stored.\n\n", add_fn = font_blue)) return(invisible(NULL)) } + + add_MO_lookup_to_AMR_env() cat(word_wrap("Matching scores are based on the resemblance between the input and the full taxonomic name, and the pathogenicity in humans. See `?mo_matching_score`.\n\n", add_fn = font_blue)) if (has_colour()) { @@ -1049,6 +1060,7 @@ replace_old_mo_codes <- function(x, property) { # B_ESCH_COL (AMR v0.5.0) -> B_ESCHR_COLI ind <- x %like_case% "^[A-Z]_[A-Z_]+$" & !x %in% AMR_env$MO_lookup$mo if (any(ind, na.rm = TRUE)) { + add_MO_lookup_to_AMR_env() # get the ones that match affected <- x[ind] affected_unique <- unique(affected) diff --git a/R/mo_matching_score.R b/R/mo_matching_score.R index 42e694d1c..6b730552c 100755 --- a/R/mo_matching_score.R +++ b/R/mo_matching_score.R @@ -84,6 +84,8 @@ mo_matching_score <- function(x, n) { meet_criteria(x, allow_class = c("character", "data.frame", "list")) meet_criteria(n, allow_class = "character") + add_MO_lookup_to_AMR_env() + x <- parse_and_convert(x) # no dots and other non-whitespace characters x <- gsub("[^a-zA-Z0-9 \\(\\)]+", "", x) diff --git a/R/mo_property.R b/R/mo_property.R index 3d5572d68..268587426 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -417,6 +417,8 @@ mo_pathogenicity <- function(x, language = get_AMR_locale(), keep_synonyms = get language <- validate_language(language) meet_criteria(keep_synonyms, allow_class = "logical", has_length = 1) + add_MO_lookup_to_AMR_env() + x.mo <- as.mo(x, language = language, keep_synonyms = keep_synonyms, ...) metadata <- get_mo_uncertainties() @@ -725,6 +727,8 @@ mo_synonyms <- function(x, language = get_AMR_locale(), keep_synonyms = getOptio meet_criteria(x, allow_NA = TRUE) language <- validate_language(language) meet_criteria(keep_synonyms, allow_class = "logical", has_length = 1) + + add_MO_lookup_to_AMR_env() x.mo <- as.mo(x, language = language, keep_synonyms = keep_synonyms, ...) metadata <- get_mo_uncertainties() @@ -811,6 +815,8 @@ mo_url <- function(x, open = FALSE, language = get_AMR_locale(), keep_synonyms = meet_criteria(open, allow_class = "logical", has_length = 1) language <- validate_language(language) meet_criteria(keep_synonyms, allow_class = "logical", has_length = 1) + + add_MO_lookup_to_AMR_env() x.mo <- as.mo(x = x, language = language, keep_synonyms = keep_synonyms, ... = ...) metadata <- get_mo_uncertainties() @@ -847,7 +853,7 @@ mo_property <- function(x, property = "fullname", language = get_AMR_locale(), k x <- find_mo_col(fn = "mo_property") } meet_criteria(x, allow_NA = TRUE) - meet_criteria(property, allow_class = "character", has_length = 1, is_in = colnames(AMR_env$MO_lookup)) + meet_criteria(property, allow_class = "character", has_length = 1, is_in = colnames(AMR::microorganisms)) language <- validate_language(language) meet_criteria(keep_synonyms, allow_class = "logical", has_length = 1) @@ -855,7 +861,8 @@ mo_property <- function(x, property = "fullname", language = get_AMR_locale(), k } mo_validate <- function(x, property, language, keep_synonyms = keep_synonyms, ...) { - + add_MO_lookup_to_AMR_env() + # try to catch an error when inputting an invalid argument # so the 'call.' can be set to FALSE tryCatch(x[1L] %in% unlist(AMR_env$MO_lookup[1, property, drop = TRUE]), diff --git a/R/mo_source.R b/R/mo_source.R index c25f9012e..f55fe4946 100755 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -261,6 +261,8 @@ get_mo_source <- function(destination = getOption("AMR_mo_source", "~/mo_source. } check_validity_mo_source <- function(x, refer_to_name = "`reference_df`", stop_on_error = TRUE) { + add_MO_lookup_to_AMR_env() + if (paste(deparse(substitute(x)), collapse = "") == "get_mo_source()") { return(TRUE) } diff --git a/R/pca.R b/R/pca.R index d4501c5b4..e8b42368a 100755 --- a/R/pca.R +++ b/R/pca.R @@ -52,7 +52,7 @@ #' genus = mo_genus(mo) #' ) %>% # and genus as we do here; #' filter(n() >= 30) %>% # filter on only 30 results per group -#' summarise_if(is.rsi, resistance) # then get resistance of all drugs +#' summarise_if(is.sir, resistance) # then get resistance of all drugs #' #' # now conduct PCA for certain antimicrobial drugs #' pca_result <- resistance_data %>% diff --git a/R/plot.R b/R/plot.R index 1a4d24022..45f66387f 100755 --- a/R/plot.R +++ b/R/plot.R @@ -27,23 +27,23 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -#' Plotting for Classes `rsi`, `mic` and `disk` +#' Plotting for Classes `sir`, `mic` and `disk` #' -#' Functions to plot classes `rsi`, `mic` and `disk`, with support for base \R and `ggplot2`. +#' Functions to plot classes `sir`, `mic` and `disk`, with support for base \R and `ggplot2`. -#' @param x,object values created with [as.mic()], [as.disk()] or [as.rsi()] (or their `random_*` variants, such as [random_mic()]) +#' @param x,object values created with [as.mic()], [as.disk()] or [as.sir()] (or their `random_*` variants, such as [random_mic()]) #' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()] #' @param ab any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()] #' @param guideline interpretation guideline to use, defaults to the latest included EUCAST guideline, see *Details* #' @param main,title title of the plot #' @param xlab,ylab axis title -#' @param colours_RSI colours to use for filling in the bars, must be a vector of three values (in the order R, S and I). The default colours are colour-blind friendly. +#' @param colours_SIR colours to use for filling in the bars, must be a vector of three values (in the order S, I and R). The default colours are colour-blind friendly. #' @param language language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant', defaults to system language (see [get_AMR_locale()]) and can be overwritten by setting the option `AMR_locale`, e.g. `options(AMR_locale = "de")`, see [translate]. Use `language = NULL` or `language = ""` to prevent translation. #' @param expand a [logical] to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled. #' @details #' The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases. #' -#' For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the `guideline` argument are: `r vector_and(AMR::rsi_translation$guideline, quotes = TRUE, reverse = TRUE)`. +#' For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the `guideline` argument are: `r vector_and(AMR::clinical_breakpoints$guideline, quotes = TRUE, reverse = TRUE)`. #' #' Simply using `"CLSI"` or `"EUCAST"` as input will automatically select the latest version of that guideline. #' @name plot @@ -55,11 +55,11 @@ #' @examples #' some_mic_values <- random_mic(size = 100) #' some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") -#' some_rsi_values <- random_rsi(50, prob_RSI = c(0.30, 0.55, 0.05)) +#' some_sir_values <- random_sir(50, prob_SIR = c(0.55, 0.05, 0.30)) #' #' plot(some_mic_values) #' plot(some_disk_values) -#' plot(some_rsi_values) +#' plot(some_sir_values) #' #' # when providing the microorganism and antibiotic, colours will show interpretations: #' plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") @@ -74,7 +74,7 @@ #' autoplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") #' } #' if (require("ggplot2")) { -#' autoplot(some_rsi_values) +#' autoplot(some_sir_values) #' } #' } NULL @@ -90,7 +90,7 @@ plot.mic <- function(x, main = deparse(substitute(x)), ylab = "Frequency", xlab = "Minimum Inhibitory Concentration (mg/L)", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -100,7 +100,7 @@ plot.mic <- function(x, meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(xlab, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -112,8 +112,8 @@ plot.mic <- function(x, xlab <- translate_into_language(xlab, language = language) } - if (length(colours_RSI) == 1) { - colours_RSI <- rep(colours_RSI, 3) + if (length(colours_SIR) == 1) { + colours_SIR <- rep(colours_SIR, 3) } main <- gsub(" +", " ", paste0(main, collapse = " ")) @@ -124,7 +124,7 @@ plot.mic <- function(x, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, fn = as.mic, language = language, ... @@ -132,7 +132,7 @@ plot.mic <- function(x, barplot(x, col = cols_sub$cols, main = main, - ylim = c(0, max(x) * ifelse(any(colours_RSI %in% cols_sub$cols), 1.1, 1)), + ylim = c(0, max(x) * ifelse(any(colours_SIR %in% cols_sub$cols), 1.1, 1)), ylab = ylab, xlab = xlab, axes = FALSE @@ -142,20 +142,20 @@ plot.mic <- function(x, mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub) } - if (any(colours_RSI %in% cols_sub$cols)) { + if (any(colours_SIR %in% cols_sub$cols)) { legend_txt <- character(0) legend_col <- character(0) - if (any(cols_sub$cols == colours_RSI[2] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) { legend_txt <- "Susceptible" - legend_col <- colours_RSI[2] + legend_col <- colours_SIR[1] } - if (any(cols_sub$cols == colours_RSI[3] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) - legend_col <- c(legend_col, colours_RSI[3]) + legend_col <- c(legend_col, colours_SIR[2]) } - if (any(cols_sub$cols == colours_RSI[1] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, "Resistant") - legend_col <- c(legend_col, colours_RSI[1]) + legend_col <- c(legend_col, colours_SIR[3]) } legend("top", @@ -181,7 +181,7 @@ barplot.mic <- function(height, main = deparse(substitute(height)), ylab = "Frequency", xlab = "Minimum Inhibitory Concentration (mg/L)", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -191,7 +191,7 @@ barplot.mic <- function(height, meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -213,7 +213,7 @@ barplot.mic <- function(height, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, ... ) } @@ -228,7 +228,7 @@ autoplot.mic <- function(object, title = deparse(substitute(object)), ylab = "Frequency", xlab = "Minimum Inhibitory Concentration (mg/L)", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -239,7 +239,7 @@ autoplot.mic <- function(object, meet_criteria(title, allow_class = "character", allow_NULL = TRUE) meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(xlab, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -264,7 +264,7 @@ autoplot.mic <- function(object, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, fn = as.mic, language = language, ... @@ -272,9 +272,9 @@ autoplot.mic <- function(object, df <- as.data.frame(x, stringsAsFactors = TRUE) colnames(df) <- c("mic", "count") df$cols <- cols_sub$cols - df$cols[df$cols == colours_RSI[1]] <- "Resistant" - df$cols[df$cols == colours_RSI[2]] <- "Susceptible" - df$cols[df$cols == colours_RSI[3]] <- plot_name_of_I(cols_sub$guideline) + df$cols[df$cols == colours_SIR[1]] <- "Susceptible" + df$cols[df$cols == colours_SIR[2]] <- plot_name_of_I(cols_sub$guideline) + df$cols[df$cols == colours_SIR[3]] <- "Resistant" df$cols <- factor(translate_into_language(df$cols, language = language), levels = translate_into_language(c("Susceptible", plot_name_of_I(cols_sub$guideline), "Resistant"), language = language @@ -283,12 +283,12 @@ autoplot.mic <- function(object, ) p <- ggplot2::ggplot(df) - if (any(colours_RSI %in% cols_sub$cols)) { + if (any(colours_SIR %in% cols_sub$cols)) { vals <- c( - "Resistant" = colours_RSI[1], - "Susceptible" = colours_RSI[2], - "Susceptible, incr. exp." = colours_RSI[3], - "Intermediate" = colours_RSI[3] + "Susceptible" = colours_SIR[1], + "Susceptible, incr. exp." = colours_SIR[2], + "Intermediate" = colours_SIR[2], + "Resistant" = colours_SIR[3] ) names(vals) <- translate_into_language(names(vals), language = language) p <- p + @@ -329,7 +329,7 @@ plot.disk <- function(x, mo = NULL, ab = NULL, guideline = "EUCAST", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -339,7 +339,7 @@ plot.disk <- function(x, meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -351,8 +351,8 @@ plot.disk <- function(x, xlab <- translate_into_language(xlab, language = language) } - if (length(colours_RSI) == 1) { - colours_RSI <- rep(colours_RSI, 3) + if (length(colours_SIR) == 1) { + colours_SIR <- rep(colours_SIR, 3) } main <- gsub(" +", " ", paste0(main, collapse = " ")) @@ -363,7 +363,7 @@ plot.disk <- function(x, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, fn = as.disk, language = language, ... @@ -372,7 +372,7 @@ plot.disk <- function(x, barplot(x, col = cols_sub$cols, main = main, - ylim = c(0, max(x) * ifelse(any(colours_RSI %in% cols_sub$cols), 1.1, 1)), + ylim = c(0, max(x) * ifelse(any(colours_SIR %in% cols_sub$cols), 1.1, 1)), ylab = ylab, xlab = xlab, axes = FALSE @@ -382,20 +382,20 @@ plot.disk <- function(x, mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub) } - if (any(colours_RSI %in% cols_sub$cols)) { + if (any(colours_SIR %in% cols_sub$cols)) { legend_txt <- character(0) legend_col <- character(0) - if (any(cols_sub$cols == colours_RSI[1] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) { legend_txt <- "Resistant" - legend_col <- colours_RSI[1] + legend_col <- colours_SIR[3] } - if (any(cols_sub$cols == colours_RSI[3] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) - legend_col <- c(legend_col, colours_RSI[3]) + legend_col <- c(legend_col, colours_SIR[2]) } - if (any(cols_sub$cols == colours_RSI[2] & cols_sub$count > 0)) { + if (any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, "Susceptible") - legend_col <- c(legend_col, colours_RSI[2]) + legend_col <- c(legend_col, colours_SIR[1]) } legend("top", x.intersp = 0.5, @@ -420,7 +420,7 @@ barplot.disk <- function(height, mo = NULL, ab = NULL, guideline = "EUCAST", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -430,7 +430,7 @@ barplot.disk <- function(height, meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -452,7 +452,7 @@ barplot.disk <- function(height, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, ... ) } @@ -467,7 +467,7 @@ autoplot.disk <- function(object, ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", guideline = "EUCAST", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { @@ -478,7 +478,7 @@ autoplot.disk <- function(object, meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -503,7 +503,7 @@ autoplot.disk <- function(object, mo = mo, ab = ab, guideline = guideline, - colours_RSI = colours_RSI, + colours_SIR = colours_SIR, fn = as.disk, language = language, ... @@ -512,9 +512,9 @@ autoplot.disk <- function(object, colnames(df) <- c("disk", "count") df$cols <- cols_sub$cols - df$cols[df$cols == colours_RSI[1]] <- "Resistant" - df$cols[df$cols == colours_RSI[2]] <- "Susceptible" - df$cols[df$cols == colours_RSI[3]] <- plot_name_of_I(cols_sub$guideline) + df$cols[df$cols == colours_SIR[1]] <- "Susceptible" + df$cols[df$cols == colours_SIR[2]] <- plot_name_of_I(cols_sub$guideline) + df$cols[df$cols == colours_SIR[3]] <- "Resistant" df$cols <- factor(translate_into_language(df$cols, language = language), levels = translate_into_language(c("Susceptible", plot_name_of_I(cols_sub$guideline), "Resistant"), language = language @@ -523,12 +523,12 @@ autoplot.disk <- function(object, ) p <- ggplot2::ggplot(df) - if (any(colours_RSI %in% cols_sub$cols)) { + if (any(colours_SIR %in% cols_sub$cols)) { vals <- c( - "Resistant" = colours_RSI[1], - "Susceptible" = colours_RSI[2], - "Susceptible, incr. exp." = colours_RSI[3], - "Intermediate" = colours_RSI[3] + "Susceptible" = colours_SIR[1], + "Susceptible, incr. exp." = colours_SIR[2], + "Intermediate" = colours_SIR[2], + "Resistant" = colours_SIR[3] ) names(vals) <- translate_into_language(names(vals), language = language) p <- p + @@ -558,11 +558,11 @@ fortify.disk <- function(object, ...) { ) } -#' @method plot rsi +#' @method plot sir #' @export #' @importFrom graphics plot text axis #' @rdname plot -plot.rsi <- function(x, +plot.sir <- function(x, ylab = "Percentage", xlab = "Antimicrobial Interpretation", main = deparse(substitute(x)), @@ -627,22 +627,22 @@ plot.rsi <- function(x, } -#' @method barplot rsi +#' @method barplot sir #' @importFrom graphics barplot axis #' @export #' @noRd -barplot.rsi <- function(height, +barplot.sir <- function(height, main = deparse(substitute(height)), xlab = "Antimicrobial Interpretation", ylab = "Frequency", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ...) { meet_criteria(xlab, allow_class = "character", has_length = 1) meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(ylab, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) language <- validate_language(language) meet_criteria(expand, allow_class = "logical", has_length = 1) @@ -654,17 +654,15 @@ barplot.rsi <- function(height, xlab <- translate_into_language(xlab, language = language) } - if (length(colours_RSI) == 1) { - colours_RSI <- rep(colours_RSI, 3) - } else { - colours_RSI <- c(colours_RSI[2], colours_RSI[3], colours_RSI[1]) + if (length(colours_SIR) == 1) { + colours_SIR <- rep(colours_SIR, 3) } main <- gsub(" +", " ", paste0(main, collapse = " ")) x <- table(height) x <- x[c(1, 2, 3)] barplot(x, - col = colours_RSI, + col = colours_SIR, xlab = xlab, main = main, ylab = ylab, @@ -673,21 +671,21 @@ barplot.rsi <- function(height, axis(2, seq(0, max(x))) } -#' @method autoplot rsi +#' @method autoplot sir #' @rdname plot # will be exported using s3_register() in R/zzz.R -autoplot.rsi <- function(object, +autoplot.sir <- function(object, title = deparse(substitute(object)), xlab = "Antimicrobial Interpretation", ylab = "Frequency", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), ...) { stop_ifnot_installed("ggplot2") meet_criteria(title, allow_class = "character", allow_NULL = TRUE) meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(xlab, allow_class = "character", has_length = 1) - meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3)) # translate if not specifically set if (missing(ylab)) { @@ -704,20 +702,20 @@ autoplot.rsi <- function(object, title <- gsub(" +", " ", paste0(title, collapse = " ")) } - if (length(colours_RSI) == 1) { - colours_RSI <- rep(colours_RSI, 3) + if (length(colours_SIR) == 1) { + colours_SIR <- rep(colours_SIR, 3) } df <- as.data.frame(table(object), stringsAsFactors = TRUE) - colnames(df) <- c("rsi", "count") + colnames(df) <- c("sir", "count") ggplot2::ggplot(df) + - ggplot2::geom_col(ggplot2::aes(x = rsi, y = count, fill = rsi)) + + ggplot2::geom_col(ggplot2::aes(x = sir, y = count, fill = sir)) + # limits = force is needed because of a ggplot2 >= 3.3.4 bug (#4511) ggplot2::scale_fill_manual( values = c( - "R" = colours_RSI[1], - "S" = colours_RSI[2], - "I" = colours_RSI[3] + "S" = colours_SIR[1], + "I" = colours_SIR[2], + "R" = colours_SIR[3] ), limits = force ) + @@ -725,10 +723,10 @@ autoplot.rsi <- function(object, ggplot2::theme(legend.position = "none") } -#' @method fortify rsi +#' @method fortify sir #' @rdname plot # will be exported using s3_register() in R/zzz.R -fortify.rsi <- function(object, ...) { +fortify.sir <- function(object, ...) { stats::setNames( as.data.frame(table(object)), c("x", "y") @@ -782,18 +780,18 @@ plot_name_of_I <- function(guideline) { } } -plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_RSI, fn, language, ...) { - guideline <- get_guideline(guideline, AMR::rsi_translation) +plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, fn, language, ...) { + guideline <- get_guideline(guideline, AMR::clinical_breakpoints) if (!is.null(mo) && !is.null(ab)) { # interpret and give colour based on MIC values mo <- as.mo(mo) ab <- as.ab(ab) - rsi <- suppressWarnings(suppressMessages(as.rsi(fn(names(x)), mo = mo, ab = ab, guideline = guideline, ...))) - cols <- character(length = length(rsi)) - cols[is.na(rsi)] <- "#BEBEBE" - cols[rsi == "R"] <- colours_RSI[1] - cols[rsi == "S"] <- colours_RSI[2] - cols[rsi == "I"] <- colours_RSI[3] + sir <- suppressWarnings(suppressMessages(as.sir(fn(names(x)), mo = mo, ab = ab, guideline = guideline, ...))) + cols <- character(length = length(sir)) + cols[is.na(sir)] <- "#BEBEBE" + cols[sir == "S"] <- colours_SIR[1] + cols[sir == "I"] <- colours_SIR[2] + cols[sir == "R"] <- colours_SIR[3] moname <- mo_name(mo, language = language) abname <- ab_name(ab, language = language) if (all(cols == "#BEBEBE")) { diff --git a/R/proportion.R b/R/proportion.R index 0af65a3ce..310bb37e4 100755 --- a/R/proportion.R +++ b/R/proportion.R @@ -32,28 +32,28 @@ #' @description These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in `summarise()` from the `dplyr` package and also support grouped variables, see *Examples*. #' #' [resistance()] should be used to calculate resistance, [susceptibility()] should be used to calculate susceptibility.\cr -#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with [as.rsi()] if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See *Examples*. +#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with [as.sir()] if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See *Examples*. #' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than `minimum` will return `NA` with a warning. The default number of `30` isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see *Source*. #' @param as_percent a [logical] to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of `0.123456` will then be returned as `"12.3%"`. #' @param only_all_tested (for combination therapies, i.e. using more than one variable for `...`): a [logical] to indicate that isolates must be tested for all antibiotics, see section *Combination Therapy* below -#' @param data a [data.frame] containing columns with class [`rsi`] (see [as.rsi()]) +#' @param data a [data.frame] containing columns with class [`sir`] (see [as.sir()]) #' @param translate_ab a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()] #' @inheritParams ab_property #' @param combine_SI a [logical] to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant), defaults to `TRUE` -#' @param ab_result antibiotic results to test against, must be one of more values of "R", "S", "I" +#' @param ab_result antibiotic results to test against, must be one or more values of "S", "I", or "R" #' @param confidence_level the confidence level for the returned confidence interval. For the calculation, the number of S or SI isolates, and R isolates are compared with the total number of available isolates with R, S, or I by using [binom.test()], i.e., the Clopper-Pearson method. #' @param side the side of the confidence interval to return. Defaults to `"both"` for a length 2 vector, but can also be (abbreviated as) `"min"`/`"left"`/`"lower"`/`"less"` or `"max"`/`"right"`/`"higher"`/`"greater"`. -#' @inheritSection as.rsi Interpretation of R and S/I +#' @inheritSection as.sir Interpretation of SIR #' @details #' The function [resistance()] is equal to the function [proportion_R()]. The function [susceptibility()] is equal to the function [proportion_SI()]. #' -#' Use [rsi_confidence_interval()] to calculate the confidence interval, which relies on [binom.test()], i.e., the Clopper-Pearson method. This function returns a vector of length 2 at default for antimicrobial *resistance*. Change the `side` argument to "left"/"min" or "right"/"max" to return a single value, and change the `ab_result` argument to e.g. `c("S", "I")` to test for antimicrobial *susceptibility*, see Examples. +#' Use [sir_confidence_interval()] to calculate the confidence interval, which relies on [binom.test()], i.e., the Clopper-Pearson method. This function returns a vector of length 2 at default for antimicrobial *resistance*. Change the `side` argument to "left"/"min" or "right"/"max" to return a single value, and change the `ab_result` argument to e.g. `c("S", "I")` to test for antimicrobial *susceptibility*, see Examples. #' #' **Remember that you should filter your data to let it contain only first isolates!** This is needed to exclude duplicates and to reduce selection bias. Use [first_isolate()] to determine them in your data set. #' #' These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the [`count()`][AMR::count()] functions to count isolates. The function [susceptibility()] is essentially equal to `count_susceptible() / count_all()`. *Low counts can influence the outcome - the `proportion` functions may camouflage this, since they only return the proportion (albeit being dependent on the `minimum` argument).* #' -#' The function [proportion_df()] takes any variable from `data` that has an [`rsi`] class (created with [as.rsi()]) and calculates the proportions R, I and S. It also supports grouped variables. The function [rsi_df()] works exactly like [proportion_df()], but adds the number of isolates. +#' The function [proportion_df()] takes any variable from `data` that has an [`sir`] class (created with [as.sir()]) and calculates the proportions S, I, and R. It also supports grouped variables. The function [sir_df()] works exactly like [proportion_df()], but adds the number of isolates. #' @section Combination Therapy: #' When using more than one variable for `...` (= combination therapy), use `only_all_tested` to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Drug A and Drug B, about how [susceptibility()] works to calculate the %SI: #' @@ -102,14 +102,14 @@ #' # base R ------------------------------------------------------------ #' # determines %R #' resistance(example_isolates$AMX) -#' rsi_confidence_interval(example_isolates$AMX) -#' rsi_confidence_interval(example_isolates$AMX, +#' sir_confidence_interval(example_isolates$AMX) +#' sir_confidence_interval(example_isolates$AMX, #' confidence_level = 0.975 #' ) #' #' # determines %S+I: #' susceptibility(example_isolates$AMX) -#' rsi_confidence_interval(example_isolates$AMX, +#' sir_confidence_interval(example_isolates$AMX, #' ab_result = c("S", "I") #' ) #' @@ -127,16 +127,16 @@ #' group_by(ward) %>% #' summarise( #' r = resistance(CIP), -#' n = n_rsi(CIP) -#' ) # n_rsi works like n_distinct in dplyr, see ?n_rsi +#' n = n_sir(CIP) +#' ) # n_sir works like n_distinct in dplyr, see ?n_sir #' } #' if (require("dplyr")) { #' example_isolates %>% #' group_by(ward) %>% #' summarise( #' cipro_R = resistance(CIP), -#' ci_min = rsi_confidence_interval(CIP, side = "min"), -#' ci_max = rsi_confidence_interval(CIP, side = "max"), +#' ci_min = sir_confidence_interval(CIP, side = "min"), +#' ci_max = sir_confidence_interval(CIP, side = "max"), #' ) #' } #' if (require("dplyr")) { @@ -157,7 +157,7 @@ #' R = resistance(CIP, as_percent = TRUE), #' SI = susceptibility(CIP, as_percent = TRUE), #' n1 = count_all(CIP), # the actual total; sum of all three -#' n2 = n_rsi(CIP), # same - analogous to n_distinct +#' n2 = n_sir(CIP), # same - analogous to n_distinct #' total = n() #' ) # NOT the number of tested isolates! #' @@ -200,17 +200,17 @@ #' combination_n = count_all(CIP, GEN) #' ) #' -#' # Get proportions S/I/R immediately of all rsi columns +#' # Get proportions S/I/R immediately of all sir columns #' example_isolates %>% #' select(AMX, CIP) %>% #' proportion_df(translate = FALSE) #' #' # It also supports grouping variables -#' # (use rsi_df to also include the count) +#' # (use sir_df to also include the count) #' example_isolates %>% #' select(ward, AMX, CIP) %>% #' group_by(ward) %>% -#' rsi_df(translate = FALSE) +#' sir_df(translate = FALSE) #' } #' } resistance <- function(..., @@ -218,14 +218,14 @@ resistance <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "R", minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -236,50 +236,50 @@ susceptibility <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I"), minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } #' @rdname proportion #' @export -rsi_confidence_interval <- function(..., +sir_confidence_interval <- function(..., ab_result = "R", minimum = 30, as_percent = FALSE, only_all_tested = FALSE, confidence_level = 0.95, side = "both") { - meet_criteria(ab_result, allow_class = c("character", "rsi"), has_length = c(1, 2, 3), is_in = c("R", "S", "I")) + meet_criteria(ab_result, allow_class = c("character", "sir"), has_length = c(1, 2, 3), is_in = c("S", "I", "R")) meet_criteria(confidence_level, allow_class = "numeric", is_positive = TRUE, has_length = 1) meet_criteria(side, allow_class = "character", has_length = 1, is_in = c("both", "b", "left", "l", "lower", "lowest", "less", "min", "right", "r", "higher", "highest", "greater", "g", "max")) x <- tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = ab_result, only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) n <- tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I", "R"), only_all_tested = only_all_tested, only_count = TRUE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) if (n < minimum) { warning_("Introducing NA: ", ifelse(n == 0, "no", paste("only", n)), - " results available for `rsi_confidence_interval()` (`minimum` = ", minimum, ").", + " results available for `sir_confidence_interval()` (`minimum` = ", minimum, ").", call = FALSE ) if (as_percent == TRUE) { @@ -311,14 +311,14 @@ proportion_R <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "R", minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -329,14 +329,14 @@ proportion_IR <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("I", "R"), minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -347,14 +347,14 @@ proportion_I <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "I", minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -365,14 +365,14 @@ proportion_SI <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = c("S", "I"), minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -383,14 +383,14 @@ proportion_S <- function(..., as_percent = FALSE, only_all_tested = FALSE) { tryCatch( - rsi_calc(..., + sir_calc(..., ab_result = "S", minimum = minimum, as_percent = as_percent, only_all_tested = only_all_tested, only_count = FALSE ), - error = function(e) stop_(gsub("in rsi_calc(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc(): ", "", e$message, fixed = TRUE), call = -5) ) } @@ -404,7 +404,7 @@ proportion_df <- function(data, combine_SI = TRUE, confidence_level = 0.95) { tryCatch( - rsi_calc_df( + sir_calc_df( type = "proportion", data = data, translate_ab = translate_ab, @@ -414,6 +414,6 @@ proportion_df <- function(data, combine_SI = combine_SI, confidence_level = confidence_level ), - error = function(e) stop_(gsub("in rsi_calc_df(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc_df(): ", "", e$message, fixed = TRUE), call = -5) ) } diff --git a/R/random.R b/R/random.R index da1767219..39c6e8824 100755 --- a/R/random.R +++ b/R/random.R @@ -27,17 +27,17 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -#' Random MIC Values/Disk Zones/RSI Generation +#' Random MIC Values/Disk Zones/SIR Generation #' #' These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice. By providing a microorganism and antimicrobial drug, the generated results will reflect reality as much as possible. #' @param size desired size of the returned vector. If used in a [data.frame] call or `dplyr` verb, will get the current (group) size if left blank. #' @param mo any [character] that can be coerced to a valid microorganism code with [as.mo()] #' @param ab any [character] that can be coerced to a valid antimicrobial drug code with [as.ab()] -#' @param prob_RSI a vector of length 3: the probabilities for "R" (1st value), "S" (2nd value) and "I" (3rd value) +#' @param prob_SIR a vector of length 3: the probabilities for "S" (1st value), "I" (2nd value) and "R" (3rd value) #' @param ... ignored, only in place to allow future extensions #' @details The base \R function [sample()] is used for generating values. #' -#' Generated values are based on the EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))` guideline as implemented in the [rsi_translation] data set. To create specific generated values per bug or drug, set the `mo` and/or `ab` argument. +#' Generated values are based on the EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))` guideline as implemented in the [clinical_breakpoints] data set. To create specific generated values per bug or drug, set the `mo` and/or `ab` argument. #' @return class `mic` for [random_mic()] (see [as.mic()]) and class `disk` for [random_disk()] (see [as.disk()]) #' @name random #' @rdname random @@ -45,7 +45,7 @@ #' @examples #' random_mic(25) #' random_disk(25) -#' random_rsi(25) +#' random_sir(25) #' #' \donttest{ #' # make the random generation more realistic by setting a bug and/or drug: @@ -81,17 +81,17 @@ random_disk <- function(size = NULL, mo = NULL, ab = NULL, ...) { #' @rdname random #' @export -random_rsi <- function(size = NULL, prob_RSI = c(0.33, 0.33, 0.33), ...) { +random_sir <- function(size = NULL, prob_SIR = c(0.33, 0.33, 0.33), ...) { meet_criteria(size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE, allow_NULL = TRUE) - meet_criteria(prob_RSI, allow_class = c("numeric", "integer"), has_length = 3) + meet_criteria(prob_SIR, allow_class = c("numeric", "integer"), has_length = 3) if (is.null(size)) { size <- NROW(get_current_data(arg_name = "size", call = -3)) } - sample(as.rsi(c("R", "S", "I")), size = size, replace = TRUE, prob = prob_RSI) + sample(as.sir(c("S", "I", "R")), size = size, replace = TRUE, prob = prob_SIR) } random_exec <- function(type, size, mo = NULL, ab = NULL) { - df <- rsi_translation %pm>% + df <- clinical_breakpoints %pm>% pm_filter(guideline %like% "EUCAST") %pm>% pm_arrange(pm_desc(guideline)) %pm>% subset(guideline == max(guideline) & diff --git a/R/resistance_predict.R b/R/resistance_predict.R index da0ce7de0..7a8878b93 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -44,7 +44,7 @@ #' @param main title of the plot #' @param ribbon a [logical] to indicate whether a ribbon should be shown (default) or error bars #' @param ... arguments passed on to functions -#' @inheritSection as.rsi Interpretation of R and S/I +#' @inheritSection as.sir Interpretation of SIR #' @inheritParams first_isolate #' @inheritParams graphics::plot #' @details Valid options for the statistical model (argument `model`) are: @@ -76,7 +76,7 @@ #' plot(x) #' \donttest{ #' if (require("ggplot2")) { -#' ggplot_rsi_predict(x) +#' ggplot_sir_predict(x) #' } #' #' # using dplyr: @@ -156,7 +156,7 @@ resistance_predict <- function(x, } df <- x - df[, col_ab] <- droplevels(as.rsi(df[, col_ab, drop = TRUE])) + df[, col_ab] <- droplevels(as.sir(df[, col_ab, drop = TRUE])) if (I_as_S == TRUE) { # then I as S df[, col_ab] <- gsub("I", "S", df[, col_ab, drop = TRUE], fixed = TRUE) @@ -286,7 +286,7 @@ resistance_predict <- function(x, #' @rdname resistance_predict #' @export -rsi_predict <- resistance_predict +sir_predict <- resistance_predict #' @method plot resistance_predict #' @export @@ -341,7 +341,7 @@ plot.resistance_predict <- function(x, main = paste("Resistance Prediction of", #' @rdname resistance_predict #' @export -ggplot_rsi_predict <- function(x, +ggplot_sir_predict <- function(x, main = paste("Resistance Prediction of", x_name), ribbon = TRUE, ...) { @@ -402,7 +402,7 @@ autoplot.resistance_predict <- function(object, x_name <- paste0(ab_name(attributes(object)$ab), " (", attributes(object)$ab, ")") meet_criteria(main, allow_class = "character", has_length = 1) meet_criteria(ribbon, allow_class = "logical", has_length = 1) - ggplot_rsi_predict(x = object, main = main, ribbon = ribbon, ...) + ggplot_sir_predict(x = object, main = main, ribbon = ribbon, ...) } #' @method fortify resistance_predict diff --git a/R/rsi.R b/R/sir.R similarity index 74% rename from R/rsi.R rename to R/sir.R index 54ad546fb..69dc8b390 100755 --- a/R/rsi.R +++ b/R/sir.R @@ -27,50 +27,50 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -#' Interpret MIC and Disk Values, or Clean Raw R/SI Data +#' Translate MIC and Disk Diffusion to SIR, or Clean Existing SIR Data #' -#' Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing R/SI values. This transforms the input to a new class [`rsi`], which is an ordered [factor] with levels `S < I < R`. -#' @rdname as.rsi +#' Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing SIR values. This transforms the input to a new class [`sir`], which is an ordered [factor] with levels `S < I < R`. +#' @rdname as.sir #' @param x vector of values (for class [`mic`]: MIC values in mg/L, for class [`disk`]: a disk diffusion radius in millimetres) #' @param mo any (vector of) text that can be coerced to valid microorganism codes with [as.mo()], can be left empty to determine it automatically #' @param ab any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()] -#' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.rsi()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*. +#' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.sir()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*. #' @inheritParams first_isolate -#' @param guideline defaults to EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))` (the latest implemented EUCAST guideline in the [rsi_translation] data set), but can be set with the [option][options()] `AMR_guideline`. Supports EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`), see *Details*. +#' @param guideline defaults to EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))` (the latest implemented EUCAST guideline in the [clinical_breakpoints] data set), but can be set with the [option][options()] `AMR_guideline`. Supports EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`), see *Details*. #' @param conserve_capped_values a [logical] to indicate that MIC values starting with `">"` (but not `">="`) must always return "R" , and that MIC values starting with `"<"` (but not `"<="`) must always return "S" #' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`. -#' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [rsi_translation] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [rsi_translation] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set. +#' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [clinical_breakpoints] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [clinical_breakpoints] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set. #' @param threshold maximum fraction of invalid antimicrobial interpretations of `x`, see *Examples* -#' @param ... for using on a [data.frame]: names of columns to apply [as.rsi()] on (supports tidy selection such as `column1:column4`). Otherwise: arguments passed on to methods. +#' @param ... for using on a [data.frame]: names of columns to apply [as.sir()] on (supports tidy selection such as `column1:column4`). Otherwise: arguments passed on to methods. #' @details #' ### How it Works #' -#' The [as.rsi()] function works in four ways: +#' The [as.sir()] function works in four ways: #' -#' 1. For **cleaning raw / untransformed data**. The data will be cleaned to only contain values S, I and R and will try its best to determine this with some intelligence. For example, mixed values with R/SI interpretations and MIC values such as `"<0.25; S"` will be coerced to `"S"`. Combined interpretations for multiple test methods (as seen in laboratory records) such as `"S; S"` will be coerced to `"S"`, but a value like `"S; I"` will return `NA` with a warning that the input is unclear. +#' 1. For **cleaning raw / untransformed data**. The data will be cleaned to only contain values S, I and R and will try its best to determine this with some intelligence. For example, mixed values with SIR interpretations and MIC values such as `"<0.25; S"` will be coerced to `"S"`. Combined interpretations for multiple test methods (as seen in laboratory records) such as `"S; S"` will be coerced to `"S"`, but a value like `"S; I"` will return `NA` with a warning that the input is unclear. #' #' 2. For **interpreting minimum inhibitory concentration (MIC) values** according to EUCAST or CLSI. You must clean your MIC values first using [as.mic()], that also gives your columns the new data class [`mic`]. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the `mo` argument. -#' * Using `dplyr`, R/SI interpretation can be done very easily with either: +#' * Using `dplyr`, SIR interpretation can be done very easily with either: #' ``` -#' your_data %>% mutate_if(is.mic, as.rsi) -#' your_data %>% mutate(across(where(is.mic), as.rsi)) +#' your_data %>% mutate_if(is.mic, as.sir) +#' your_data %>% mutate(across(where(is.mic), as.sir)) #' ``` #' * Operators like "<=" will be stripped before interpretation. When using `conserve_capped_values = TRUE`, an MIC value of e.g. ">2" will always return "R", even if the breakpoint according to the chosen guideline is ">=4". This is to prevent that capped values from raw laboratory data would not be treated conservatively. The default behaviour (`conserve_capped_values = FALSE`) considers ">2" to be lower than ">=4" and might in this case return "S" or "I". #' 3. For **interpreting disk diffusion diameters** according to EUCAST or CLSI. You must clean your disk zones first using [as.disk()], that also gives your columns the new data class [`disk`]. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the `mo` argument. -#' * Using `dplyr`, R/SI interpretation can be done very easily with either: +#' * Using `dplyr`, SIR interpretation can be done very easily with either: #' ``` -#' your_data %>% mutate_if(is.disk, as.rsi) -#' your_data %>% mutate(across(where(is.disk), as.rsi)) +#' your_data %>% mutate_if(is.disk, as.sir) +#' your_data %>% mutate(across(where(is.disk), as.sir)) #' ``` -#' 4. For **interpreting a complete data set**, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running `as.rsi(your_data)`. +#' 4. For **interpreting a complete data set**, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running `as.sir(your_data)`. #' -#' For points 2, 3 and 4: Use [rsi_interpretation_history()] to retrieve a [data.frame] (or [tibble][tibble::tibble()] if the `tibble` package is installed) with all results of the last [as.rsi()] call. +#' For points 2, 3 and 4: Use [sir_interpretation_history()] to retrieve a [data.frame] (or [tibble][tibble::tibble()] if the `tibble` package is installed) with all results of the last [as.sir()] call. #' #' ### Supported Guidelines #' -#' For interpreting MIC values as well as disk diffusion diameters, currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`). +#' For interpreting MIC values as well as disk diffusion diameters, currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`). #' -#' Thus, the `guideline` argument must be set to e.g., ``r paste0('"', subset(rsi_translation, guideline %like% "EUCAST")$guideline[1], '"')`` or ``r paste0('"', subset(rsi_translation, guideline %like% "CLSI")$guideline[1], '"')``. By simply using `"EUCAST"` (the default) or `"CLSI"` as input, the latest included version of that guideline will automatically be selected. You can set your own data set using the `reference_data` argument. The `guideline` argument will then be ignored. +#' Thus, the `guideline` argument must be set to e.g., ``r paste0('"', subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline[1], '"')`` or ``r paste0('"', subset(clinical_breakpoints, guideline %like% "CLSI")$guideline[1], '"')``. By simply using `"EUCAST"` (the default) or `"CLSI"` as input, the latest included version of that guideline will automatically be selected. You can set your own data set using the `reference_data` argument. The `guideline` argument will then be ignored. #' #' You can set the default guideline with the `AMR_guideline` [option][options()] (e.g. in your `.Rprofile` file), such as: #' @@ -84,42 +84,44 @@ #' #' ### After Interpretation #' -#' After using [as.rsi()], you can use the [eucast_rules()] defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism. +#' After using [as.sir()], you can use the [eucast_rules()] defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism. #' #' ### Machine-Readable Interpretation Guidelines #' -#' The repository of this package [contains a machine-readable version](https://github.com/msberends/AMR/blob/main/data-raw/rsi_translation.txt) of all guidelines. This is a CSV file consisting of `r format(nrow(AMR::rsi_translation), big.mark = ",")` rows and `r ncol(AMR::rsi_translation)` columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial drug and the microorganism. **This allows for easy implementation of these rules in laboratory information systems (LIS)**. Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed. +#' The repository of this package [contains a machine-readable version](https://github.com/msberends/AMR/blob/main/data-raw/clinical_breakpoints.txt) of all guidelines. This is a CSV file consisting of `r format(nrow(AMR::clinical_breakpoints), big.mark = ",")` rows and `r ncol(AMR::clinical_breakpoints)` columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial drug and the microorganism. **This allows for easy implementation of these rules in laboratory information systems (LIS)**. Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed. #' #' ### Other #' -#' The function [is.rsi()] detects if the input contains class `rsi`. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector. +#' The function [is.sir()] detects if the input contains class `sir`. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector. #' -#' The function [is.rsi.eligible()] returns `TRUE` when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and `FALSE` otherwise. The threshold of 5% can be set with the `threshold` argument. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector. -#' @section Interpretation of R and S/I: -#' In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (). +#' The function [is_sir_eligible()] returns `TRUE` when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and `FALSE` otherwise. The threshold of 5% can be set with the `threshold` argument. If the input is a [data.frame], it iterates over all columns and returns a [logical] vector. +#' @section Interpretation of SIR: +#' In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (): #' +#' - **S - Susceptible, standard dosing regimen**\cr +#' A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +#' - **I - Susceptible, increased exposure** *\cr +#' A microorganism is categorised as "Susceptible, Increased exposure*" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. #' - **R = Resistant**\cr -#' A microorganism is categorised as *Resistant* when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -#' - **S = Susceptible**\cr -#' A microorganism is categorised as *Susceptible, standard dosing regimen*, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -#' - **I = Susceptible, Increased exposure**\cr -#' A microorganism is categorised as *Susceptible, Increased exposure* when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +#' A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +#' +#' * *Exposure* is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. #' #' This AMR package honours this insight. Use [susceptibility()] (equal to [proportion_SI()]) to determine antimicrobial susceptibility and [count_susceptible()] (equal to [count_SI()]) to count susceptible isolates. -#' @return Ordered [factor] with new class `rsi` -#' @aliases rsi +#' @return Ordered [factor] with new class `sir` +#' @aliases sir #' @export #' @seealso [as.mic()], [as.disk()], [as.mo()] #' @source #' For interpretations of minimum inhibitory concentration (MIC) values and disk diffusion diameters: #' -#' - **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data**, `r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`, *Clinical and Laboratory Standards Institute* (CLSI). . -#' - **M100 Performance Standard for Antimicrobial Susceptibility Testing**, `r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`, *Clinical and Laboratory Standards Institute* (CLSI). . -#' - **Breakpoint tables for interpretation of MICs and zone diameters**, `r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`, *European Committee on Antimicrobial Susceptibility Testing* (EUCAST). . +#' - **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data**, `r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`, *Clinical and Laboratory Standards Institute* (CLSI). . +#' - **M100 Performance Standard for Antimicrobial Susceptibility Testing**, `r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`, *Clinical and Laboratory Standards Institute* (CLSI). . +#' - **Breakpoint tables for interpretation of MICs and zone diameters**, `r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`, *European Committee on Antimicrobial Susceptibility Testing* (EUCAST). . #' @inheritSection AMR Reference Data Publicly Available #' @examples #' example_isolates -#' summary(example_isolates) # see all R/SI results at a glance +#' summary(example_isolates) # see all SIR results at a glance #' #' # For INTERPRETING disk diffusion and MIC values ----------------------- #' @@ -132,20 +134,20 @@ #' TOB = as.disk(16), #' ERY = "R" #' ) -#' as.rsi(df) +#' as.sir(df) #' #' # return a 'logbook' about the results: -#' rsi_interpretation_history() +#' sir_interpretation_history() #' #' # for single values -#' as.rsi( +#' as.sir( #' x = as.mic(2), #' mo = as.mo("S. pneumoniae"), #' ab = "AMP", #' guideline = "EUCAST" #' ) #' -#' as.rsi( +#' as.sir( #' x = as.disk(18), #' mo = "Strep pneu", # `mo` will be coerced with as.mo() #' ab = "ampicillin", # and `ab` with as.ab() @@ -155,14 +157,14 @@ #' \donttest{ #' # the dplyr way #' if (require("dplyr")) { -#' df %>% mutate_if(is.mic, as.rsi) -#' df %>% mutate_if(function(x) is.mic(x) | is.disk(x), as.rsi) -#' df %>% mutate(across(where(is.mic), as.rsi)) -#' df %>% mutate_at(vars(AMP:TOB), as.rsi) -#' df %>% mutate(across(AMP:TOB, as.rsi)) +#' df %>% mutate_if(is.mic, as.sir) +#' df %>% mutate_if(function(x) is.mic(x) | is.disk(x), as.sir) +#' df %>% mutate(across(where(is.mic), as.sir)) +#' df %>% mutate_at(vars(AMP:TOB), as.sir) +#' df %>% mutate(across(AMP:TOB, as.sir)) #' #' df %>% -#' mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism) +#' mutate_at(vars(AMP:TOB), as.sir, mo = .$microorganism) #' #' # to include information about urinary tract infections (UTI) #' data.frame( @@ -170,74 +172,74 @@ #' NIT = c("<= 2", 32), #' from_the_bladder = c(TRUE, FALSE) #' ) %>% -#' as.rsi(uti = "from_the_bladder") +#' as.sir(uti = "from_the_bladder") #' #' data.frame( #' mo = "E. coli", #' NIT = c("<= 2", 32), #' specimen = c("urine", "blood") #' ) %>% -#' as.rsi() # automatically determines urine isolates +#' as.sir() # automatically determines urine isolates #' #' df %>% -#' mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli", uti = TRUE) +#' mutate_at(vars(AMP:TOB), as.sir, mo = "E. coli", uti = TRUE) #' } #' -#' # For CLEANING existing R/SI values ------------------------------------ +#' # For CLEANING existing SIR values ------------------------------------ #' -#' as.rsi(c("S", "I", "R", "A", "B", "C")) -#' as.rsi("<= 0.002; S") # will return "S" -#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370))) -#' is.rsi(rsi_data) -#' plot(rsi_data) # for percentages -#' barplot(rsi_data) # for frequencies +#' as.sir(c("S", "I", "R", "A", "B", "C")) +#' as.sir("<= 0.002; S") # will return "S" +#' sir_data <- as.sir(c(rep("S", 474), rep("I", 36), rep("R", 370))) +#' is.sir(sir_data) +#' plot(sir_data) # for percentages +#' barplot(sir_data) # for frequencies #' #' # the dplyr way #' if (require("dplyr")) { #' example_isolates %>% -#' mutate_at(vars(PEN:RIF), as.rsi) +#' mutate_at(vars(PEN:RIF), as.sir) #' # same: #' example_isolates %>% -#' as.rsi(PEN:RIF) +#' as.sir(PEN:RIF) #' -#' # fastest way to transform all columns with already valid AMR results to class `rsi`: +#' # fastest way to transform all columns with already valid AMR results to class `sir`: #' example_isolates %>% -#' mutate_if(is.rsi.eligible, as.rsi) +#' mutate_if(is_sir_eligible, as.sir) #' #' # since dplyr 1.0.0, this can also be: #' # example_isolates %>% -#' # mutate(across(where(is.rsi.eligible), as.rsi)) +#' # mutate(across(where(is_sir_eligible), as.sir)) #' } #' } -as.rsi <- function(x, ...) { - UseMethod("as.rsi") +as.sir <- function(x, ...) { + UseMethod("as.sir") } -#' @rdname as.rsi -#' @details `NA_rsi_` is a missing value of the new `rsi` class, analogous to e.g. base \R's [`NA_character_`][base::NA]. +#' @rdname as.sir +#' @details `NA_sir_` is a missing value of the new `sir` class, analogous to e.g. base \R's [`NA_character_`][base::NA]. #' @export -NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE), - new_class = c("rsi", "ordered", "factor") +NA_sir_ <- set_clean_class(factor(NA_character_, levels = c("S", "I", "R"), ordered = TRUE), + new_class = c("sir", "ordered", "factor") ) -#' @rdname as.rsi +#' @rdname as.sir #' @export -is.rsi <- function(x) { +is.sir <- function(x) { if (inherits(x, "data.frame")) { - unname(vapply(FUN.VALUE = logical(1), x, is.rsi)) + unname(vapply(FUN.VALUE = logical(1), x, is.sir)) } else { - inherits(x, "rsi") + inherits(x, "sir") } } -#' @rdname as.rsi +#' @rdname as.sir #' @export -is.rsi.eligible <- function(x, threshold = 0.05) { +is_sir_eligible <- function(x, threshold = 0.05) { meet_criteria(threshold, allow_class = "numeric", has_length = 1) if (inherits(x, "data.frame")) { # iterate this function over all columns - return(unname(vapply(FUN.VALUE = logical(1), x, is.rsi.eligible))) + return(unname(vapply(FUN.VALUE = logical(1), x, is_sir_eligible))) } stop_if(NCOL(x) > 1, "`x` must be a one-dimensional vector.") @@ -256,9 +258,9 @@ is.rsi.eligible <- function(x, threshold = 0.05) { %in% class(x))) { # no transformation needed return(FALSE) - } else if (all(x %in% c("R", "S", "I", NA)) & !all(is.na(x))) { + } else if (all(x %in% c("S", "I", "R", NA)) & !all(is.na(x))) { return(TRUE) - } else if (!any(c("R", "S", "I") %in% x, na.rm = TRUE) & !all(is.na(x))) { + } else if (!any(c("S", "I", "R") %in% x, na.rm = TRUE) & !all(is.na(x))) { return(FALSE) } else { x <- x[!is.na(x) & !is.null(x) & !x %in% c("", "-", "NULL")] @@ -270,7 +272,7 @@ is.rsi.eligible <- function(x, threshold = 0.05) { if (!is.na(ab)) { # this is a valid antibiotic drug code message_( - "Column '", font_bold(cur_col), "' is as.rsi()-eligible (despite only having empty values), since it seems to be ", + "Column '", font_bold(cur_col), "' is SIR eligible (despite only having empty values), since it seems to be ", ab_name(ab, language = NULL, tolower = TRUE), " (", ab, ")" ) return(TRUE) @@ -280,7 +282,7 @@ is.rsi.eligible <- function(x, threshold = 0.05) { return(FALSE) } # transform all values and see if it meets the set threshold - checked <- suppressWarnings(as.rsi(x)) + checked <- suppressWarnings(as.sir(x)) outcome <- sum(is.na(checked)) / length(x) outcome <= threshold } @@ -288,8 +290,8 @@ is.rsi.eligible <- function(x, threshold = 0.05) { #' @export # extra param: warn (logical, to never throw a warning) -as.rsi.default <- function(x, ...) { - if (is.rsi(x)) { +as.sir.default <- function(x, ...) { + if (is.sir(x)) { return(x) } @@ -299,7 +301,7 @@ as.rsi.default <- function(x, ...) { if (inherits(x.bak, c("integer", "numeric", "double")) && all(x %in% c(1:3, NA))) { # support haven package for importing e.g., from SPSS - it adds the 'labels' attribute lbls <- attributes(x.bak)$labels - if (!is.null(lbls) && all(c("R", "S", "I") %in% names(lbls)) && all(c(1:3) %in% lbls)) { + if (!is.null(lbls) && all(c("S", "I", "R") %in% names(lbls)) && all(c(1:3) %in% lbls)) { x[x.bak == 1] <- names(lbls[lbls == 1]) x[x.bak == 2] <- names(lbls[lbls == 2]) x[x.bak == 3] <- names(lbls[lbls == 3]) @@ -312,13 +314,13 @@ as.rsi.default <- function(x, ...) { x[x.bak == "1"] <- "S" x[x.bak == "2"] <- "I" x[x.bak == "3"] <- "R" - } else if (!all(is.na(x)) && !identical(levels(x), c("R", "S", "I")) && !all(x %in% c("R", "S", "I", NA))) { + } else if (!all(is.na(x)) && !identical(levels(x), c("S", "I", "R")) && !all(x %in% c("S", "I", "R", NA))) { if (all(x %unlike% "(R|S|I)", na.rm = TRUE)) { # check if they are actually MICs or disks if (all_valid_mics(x)) { - warning_("in `as.rsi()`: the input seems to contain MIC values. You can transform them with `as.mic()` before running `as.rsi()` to interpret them.") + warning_("in `as.sir()`: the input seems to contain MIC values. You can transform them with `as.mic()` before running `as.sir()` to interpret them.") } else if (all_valid_disks(x)) { - warning_("in `as.rsi()`: the input seems to contain disk diffusion values. You can transform them with `as.disk()` before running `as.rsi()` to interpret them.") + warning_("in `as.sir()`: the input seems to contain disk diffusion values. You can transform them with `as.disk()` before running `as.sir()` to interpret them.") } } @@ -368,14 +370,14 @@ as.rsi.default <- function(x, ...) { x[!x %in% c("S", "I", "R")] <- NA_character_ na_after <- length(x[is.na(x) | x == ""]) - if (!isFALSE(list(...)$warn)) { # so as.rsi(..., warn = FALSE) will never throw a warning + if (!isFALSE(list(...)$warn)) { # so as.sir(..., warn = FALSE) will never throw a warning if (na_before != na_after) { list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ""] %pm>% unique() %pm>% sort() %pm>% vector_and(quotes = TRUE) cur_col <- get_current_column() - warning_("in `as.rsi()`: ", na_after - na_before, " result", + warning_("in `as.sir()`: ", na_after - na_before, " result", ifelse(na_after - na_before > 1, "s", ""), ifelse(is.null(cur_col), "", paste0(" in column '", cur_col, "'")), " truncated (", @@ -385,38 +387,38 @@ as.rsi.default <- function(x, ...) { call = FALSE ) } - if (any(toupper(x.bak[!is.na(x.bak)]) == "U") && message_not_thrown_before("as.rsi", "U")) { - warning_("in `as.rsi()`: 'U' was interpreted as 'S', following some laboratory systems") + if (any(toupper(x.bak[!is.na(x.bak)]) == "U") && message_not_thrown_before("as.sir", "U")) { + warning_("in `as.sir()`: 'U' was interpreted as 'S', following some laboratory systems") } - if (any(toupper(x.bak[!is.na(x.bak)]) == "D") && message_not_thrown_before("as.rsi", "D")) { - warning_("in `as.rsi()`: 'D' (dose-dependent) was interpreted as 'I', following some laboratory systems") + if (any(toupper(x.bak[!is.na(x.bak)]) == "D") && message_not_thrown_before("as.sir", "D")) { + warning_("in `as.sir()`: 'D' (dose-dependent) was interpreted as 'I', following some laboratory systems") } - if (any(toupper(x.bak[!is.na(x.bak)]) == "SDD") && message_not_thrown_before("as.rsi", "SDD")) { - warning_("in `as.rsi()`: 'SDD' (susceptible dose-dependent, coined by CLSI) was interpreted as 'I' to comply with EUCAST's 'I'") + if (any(toupper(x.bak[!is.na(x.bak)]) == "SDD") && message_not_thrown_before("as.sir", "SDD")) { + warning_("in `as.sir()`: 'SDD' (susceptible dose-dependent, coined by CLSI) was interpreted as 'I' to comply with EUCAST's 'I'") } - if (any(toupper(x.bak[!is.na(x.bak)]) == "H") && message_not_thrown_before("as.rsi", "H")) { - warning_("in `as.rsi()`: 'H' was interpreted as 'I', following some laboratory systems") + if (any(toupper(x.bak[!is.na(x.bak)]) == "H") && message_not_thrown_before("as.sir", "H")) { + warning_("in `as.sir()`: 'H' was interpreted as 'I', following some laboratory systems") } } } set_clean_class(factor(x, levels = c("S", "I", "R"), ordered = TRUE), - new_class = c("rsi", "ordered", "factor") + new_class = c("sir", "ordered", "factor") ) } -#' @rdname as.rsi +#' @rdname as.sir #' @export -as.rsi.mic <- function(x, +as.sir.mic <- function(x, mo = NULL, ab = deparse(substitute(x)), guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL, conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation, + reference_data = AMR::clinical_breakpoints, ...) { - as_rsi_method( + as_sir_method( method_short = "mic", method_long = "MIC values", x = x, @@ -431,17 +433,17 @@ as.rsi.mic <- function(x, ) } -#' @rdname as.rsi +#' @rdname as.sir #' @export -as.rsi.disk <- function(x, +as.sir.disk <- function(x, mo = NULL, ab = deparse(substitute(x)), guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation, + reference_data = AMR::clinical_breakpoints, ...) { - as_rsi_method( + as_sir_method( method_short = "disk", method_long = "disk diffusion zones", x = x, @@ -456,16 +458,16 @@ as.rsi.disk <- function(x, ) } -#' @rdname as.rsi +#' @rdname as.sir #' @export -as.rsi.data.frame <- function(x, +as.sir.data.frame <- function(x, ..., col_mo = NULL, guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL, conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation) { + reference_data = AMR::clinical_breakpoints) { meet_criteria(x, allow_class = "data.frame") # will also check for dimensions > 0 meet_criteria(col_mo, allow_class = "character", is_in = colnames(x), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) @@ -525,7 +527,7 @@ as.rsi.data.frame <- function(x, vector_and(values, quotes = TRUE), " in column '", font_bold(col_specimen), "' reflect", plural[2], " ", plural[3], "urinary tract infection", plural[1], - ".\n Use `as.rsi(uti = FALSE)` to prevent this." + ".\n Use `as.sir(uti = FALSE)` to prevent this." ) } else { # no data about UTI's found @@ -576,7 +578,7 @@ as.rsi.data.frame <- function(x, types[vapply(FUN.VALUE = logical(1), x.bak[, ab_cols, drop = FALSE], is.mic)] <- "mic" types[types == "" & vapply(FUN.VALUE = logical(1), x[, ab_cols, drop = FALSE], all_valid_disks)] <- "disk" types[types == "" & vapply(FUN.VALUE = logical(1), x[, ab_cols, drop = FALSE], all_valid_mics)] <- "mic" - types[types == "" & !vapply(FUN.VALUE = logical(1), x.bak[, ab_cols, drop = FALSE], is.rsi)] <- "rsi" + types[types == "" & !vapply(FUN.VALUE = logical(1), x.bak[, ab_cols, drop = FALSE], is.sir)] <- "sir" if (any(types %in% c("mic", "disk"), na.rm = TRUE)) { # now we need an mo column stop_if(is.null(col_mo), "`col_mo` must be set") @@ -593,7 +595,7 @@ as.rsi.data.frame <- function(x, pm_pull(ab_cols[i]) %pm>% as.character() %pm>% as.mic() %pm>% - as.rsi( + as.sir( mo = x_mo, mo.bak = x[, col_mo, drop = TRUE], ab = ab_cols[i], @@ -609,7 +611,7 @@ as.rsi.data.frame <- function(x, pm_pull(ab_cols[i]) %pm>% as.character() %pm>% as.disk() %pm>% - as.rsi( + as.sir( mo = x_mo, mo.bak = x[, col_mo, drop = TRUE], ab = ab_cols[i], @@ -619,11 +621,11 @@ as.rsi.data.frame <- function(x, reference_data = reference_data, is_data.frame = TRUE ) - } else if (types[i] == "rsi") { + } else if (types[i] == "sir") { show_message <- FALSE ab <- ab_cols[i] ab_coerced <- suppressWarnings(as.ab(ab)) - if (!all(x[, ab_cols[i], drop = TRUE] %in% c("R", "S", "I", NA), na.rm = TRUE)) { + if (!all(x[, ab_cols[i], drop = TRUE] %in% c("S", "I", "R", NA), na.rm = TRUE)) { show_message <- TRUE # only print message if values are not already clean message_("=> Cleaning values in column '", font_bold(ab), "' (", @@ -632,17 +634,17 @@ as.rsi.data.frame <- function(x, appendLF = FALSE, as_note = FALSE ) - } else if (!is.rsi(x.bak[, ab_cols[i], drop = TRUE])) { + } else if (!is.sir(x.bak[, ab_cols[i], drop = TRUE])) { show_message <- TRUE # only print message if class not already set - message_("=> Assigning class 'rsi' to already clean column '", font_bold(ab), "' (", + message_("=> Assigning class 'sir' to already clean column '", font_bold(ab), "' (", ifelse(ab_coerced != toupper(ab), paste0(ab_coerced, ", "), ""), ab_name(ab_coerced, tolower = TRUE, language = NULL), ")... ", appendLF = FALSE, as_note = FALSE ) } - x[, ab_cols[i]] <- as.rsi.default(x = as.character(x[, ab_cols[i], drop = TRUE])) + x[, ab_cols[i]] <- as.sir.default(x = as.character(x[, ab_cols[i], drop = TRUE])) if (show_message == TRUE) { message_(" OK.", add_fn = list(font_green), as_note = FALSE) } @@ -653,7 +655,7 @@ as.rsi.data.frame <- function(x, } get_guideline <- function(guideline, reference_data) { - if (!identical(reference_data, AMR::rsi_translation)) { + if (!identical(reference_data, AMR::clinical_breakpoints)) { return(guideline) } guideline_param <- toupper(guideline) @@ -674,7 +676,7 @@ get_guideline <- function(guideline, reference_data) { guideline_param } -as_rsi_method <- function(method_short, +as_sir_method <- function(method_short, method_long, x, mo, @@ -728,15 +730,15 @@ as_rsi_method <- function(method_short, ) } if (is.null(mo)) { - stop_("No information was supplied about the microorganisms (missing argument `mo` and no column of class 'mo' found). See ?as.rsi.\n\n", - "To transform certain columns with e.g. mutate(), use `data %>% mutate(across(..., as.rsi, mo = x))`, where x is your column with microorganisms.\n", - "To tranform all ", method_long, " in a data set, use `data %>% as.rsi()` or `data %>% mutate_if(is.", method_short, ", as.rsi)`.", + stop_("No information was supplied about the microorganisms (missing argument `mo` and no column of class 'mo' found). See ?as.sir.\n\n", + "To transform certain columns with e.g. mutate(), use `data %>% mutate(across(..., as.sir, mo = x))`, where x is your column with microorganisms.\n", + "To tranform all ", method_long, " in a data set, use `data %>% as.sir()` or `data %>% mutate_if(is.", method_short, ", as.sir)`.", call = FALSE ) } if (length(ab) == 1 && ab %like% paste0("as.", method_short)) { - stop_("No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.rsi.", call = FALSE) + stop_("No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.sir.", call = FALSE) } ab.bak <- ab @@ -746,7 +748,7 @@ as_rsi_method <- function(method_short, } else { mo.bak <- mo } - # be sure to take current taxonomy, as the rsi_translation data set only contains current taxonomy + # be sure to take current taxonomy, as the clinical_breakpoints data set only contains current taxonomy mo <- suppressWarnings(suppressMessages(as.mo(mo, keep_synonyms = FALSE, inf0 = FALSE))) guideline_coerced <- get_guideline(guideline, reference_data) if (is.na(ab)) { @@ -755,7 +757,7 @@ as_rsi_method <- function(method_short, add_fn = font_red, as_note = FALSE ) - return(as.rsi(rep(NA, length(x)))) + return(as.sir(rep(NA, length(x)))) } if (length(mo) == 1) { mo <- rep(mo, length(x)) @@ -768,8 +770,8 @@ as_rsi_method <- function(method_short, } if (isTRUE(add_intrinsic_resistance) && guideline_coerced %unlike% "EUCAST") { - if (message_not_thrown_before("as.rsi", "intrinsic")) { - warning_("in `as.rsi()`: using 'add_intrinsic_resistance' is only useful when using EUCAST guidelines, since the rules for intrinsic resistance are based on EUCAST.") + if (message_not_thrown_before("as.sir", "intrinsic")) { + warning_("in `as.sir()`: using 'add_intrinsic_resistance' is only useful when using EUCAST guidelines, since the rules for intrinsic resistance are based on EUCAST.") } } @@ -791,7 +793,7 @@ as_rsi_method <- function(method_short, message_("=> Interpreting ", method_long, " of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""), agent_formatted, mo_var_found, - " according to ", ifelse(identical(reference_data, AMR::rsi_translation), + " according to ", ifelse(identical(reference_data, AMR::clinical_breakpoints), font_bold(guideline_coerced), "manually defined 'reference_data'" ), @@ -814,14 +816,14 @@ as_rsi_method <- function(method_short, df <- data.frame(values = x, mo = mo, - result = NA_rsi_, + result = NA_sir_, uti = uti, stringsAsFactors = FALSE) if (method == "mic") { - # when as.rsi.mic is called directly + # when as.sir.mic is called directly df$values <- as.mic(df$values) } else if (method == "disk") { - # when as.rsi.disk is called directly + # when as.sir.disk is called directly df$values <- as.disk(df$values) } @@ -831,7 +833,7 @@ as_rsi_method <- function(method_short, ab_coerced <- ab mo_coerced <- mo - if (identical(reference_data, AMR::rsi_translation)) { + if (identical(reference_data, AMR::clinical_breakpoints)) { breakpoints <- reference_data %pm>% subset(guideline == guideline_coerced & method == method_coerced & ab == ab_coerced) if (ab_coerced == "AMX" && nrow(breakpoints) == 0) { @@ -851,7 +853,7 @@ as_rsi_method <- function(method_short, suppressMessages(suppressWarnings(ab_name(ab_coerced, language = NULL, tolower = TRUE))), " (", ab_coerced, ")")) load_mo_uncertainties(metadata_mo) - return(rep(NA_rsi_, nrow(df))) + return(rep(NA_sir_, nrow(df))) } if (guideline_coerced %like% "EUCAST") { @@ -865,7 +867,7 @@ as_rsi_method <- function(method_short, rows <- which(df$mo == mo_unique) values <- df[rows, "values", drop = TRUE] uti <- df[rows, "uti", drop = TRUE] - new_rsi <- rep(NA_rsi_, length(rows)) + new_sir <- rep(NA_sir_, length(rows)) # find different mo properties mo_current_genus <- as.mo(mo_genus(mo_unique, language = NULL)) @@ -903,7 +905,7 @@ as_rsi_method <- function(method_short, breakpoints_current <- breakpoints_current %pm>% # be as specific as possible (i.e. prefer species over genus): # the below `pm_desc(uti)` will put `TRUE` on top and FALSE on bottom - pm_arrange(rank_index, pm_desc(uti)) # 'uti' is a column in data set 'rsi_translation' + pm_arrange(rank_index, pm_desc(uti)) # 'uti' is a column in data set 'clinical_breakpoints' } else { breakpoints_current <- breakpoints_current %pm>% # sort UTI = FALSE first, then UTI = TRUE @@ -911,16 +913,16 @@ as_rsi_method <- function(method_short, } # throw notes for different body sites - if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti %in% c(FALSE, NA)) && message_not_thrown_before("as.rsi", "uti", ab_coerced)) { + if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_coerced)) { # only UTI breakpoints available - warning_("in `as.rsi()`: interpretation of ", font_bold(ab_formatted), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms, thus assuming `uti = TRUE`. See `?as.rsi`.") + warning_("in `as.sir()`: interpretation of ", font_bold(ab_formatted), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms, thus assuming `uti = TRUE`. See `?as.sir`.") rise_warning <- TRUE - } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.rsi", "siteUTI", mo_unique, ab_coerced)) { + } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_unique, ab_coerced)) { # both UTI and Non-UTI breakpoints available - msgs <- c(msgs, paste0("Breakpoints for UTI ", font_underline("and"), " non-UTI available for ", ab_formatted, " in ", mo_formatted, " - assuming non-UTI. Use argument `uti` to set which isolates are from urine. See `?as.rsi`.")) + msgs <- c(msgs, paste0("Breakpoints for UTI ", font_underline("and"), " non-UTI available for ", ab_formatted, " in ", mo_formatted, " - assuming non-UTI. Use argument `uti` to set which isolates are from urine. See `?as.sir`.")) breakpoints_current <- breakpoints_current %pm>% pm_filter(uti == FALSE) - } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.rsi", "siteOther", mo_unique, ab_coerced)) { + } else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && all(breakpoints_current$uti == FALSE, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteOther", mo_unique, ab_coerced)) { # breakpoints for multiple body sites available site <- breakpoints_current[1L, "site", drop = FALSE] # this is the one we'll take if (is.na(site)) { @@ -934,40 +936,40 @@ as_rsi_method <- function(method_short, # first check if mo is intrinsic resistant if (isTRUE(add_intrinsic_resistance) && guideline_coerced %like% "EUCAST" && paste(mo_unique, ab_coerced) %in% AMR_env$intrinsic_resistant) { msgs <- c(msgs, paste0("Intrinsic resistance applied for ", ab_formatted, " in ", mo_formatted, "")) - new_rsi <- rep(as.rsi("R"), length(rows)) + new_sir <- rep(as.sir("R"), length(rows)) } else { # then run the rules breakpoints_current <- breakpoints_current[1L, , drop = FALSE] if (method == "mic") { - new_rsi <- quick_case_when( - is.na(values) ~ NA_rsi_, - values <= breakpoints_current$breakpoint_S ~ as.rsi("S"), - guideline_coerced %like% "EUCAST" & values > breakpoints_current$breakpoint_R ~ as.rsi("R"), - guideline_coerced %like% "CLSI" & values >= breakpoints_current$breakpoint_R ~ as.rsi("R"), + new_sir <- quick_case_when( + is.na(values) ~ NA_sir_, + values <= breakpoints_current$breakpoint_S ~ as.sir("S"), + guideline_coerced %like% "EUCAST" & values > breakpoints_current$breakpoint_R ~ as.sir("R"), + guideline_coerced %like% "CLSI" & values >= breakpoints_current$breakpoint_R ~ as.sir("R"), # return "I" when breakpoints are in the middle - !is.na(breakpoints_current$breakpoint_S) & !is.na(breakpoints_current$breakpoint_R) ~ as.rsi("I"), + !is.na(breakpoints_current$breakpoint_S) & !is.na(breakpoints_current$breakpoint_R) ~ as.sir("I"), # and NA otherwise - TRUE ~ NA_rsi_ + TRUE ~ NA_sir_ ) } else if (method == "disk") { - new_rsi <- quick_case_when( - is.na(values) ~ NA_rsi_, - as.double(values) >= as.double(breakpoints_current$breakpoint_S) ~ as.rsi("S"), - guideline_coerced %like% "EUCAST" & as.double(values) < as.double(breakpoints_current$breakpoint_R) ~ as.rsi("R"), - guideline_coerced %like% "CLSI" & as.double(values) <= as.double(breakpoints_current$breakpoint_R) ~ as.rsi("R"), + new_sir <- quick_case_when( + is.na(values) ~ NA_sir_, + as.double(values) >= as.double(breakpoints_current$breakpoint_S) ~ as.sir("S"), + guideline_coerced %like% "EUCAST" & as.double(values) < as.double(breakpoints_current$breakpoint_R) ~ as.sir("R"), + guideline_coerced %like% "CLSI" & as.double(values) <= as.double(breakpoints_current$breakpoint_R) ~ as.sir("R"), # return "I" when breakpoints are in the middle - !is.na(breakpoints_current$breakpoint_S) & !is.na(breakpoints_current$breakpoint_R) ~ as.rsi("I"), + !is.na(breakpoints_current$breakpoint_S) & !is.na(breakpoints_current$breakpoint_R) ~ as.sir("I"), # and NA otherwise - TRUE ~ NA_rsi_ + TRUE ~ NA_sir_ ) } # write to verbose output - AMR_env$rsi_interpretation_history <- rbind( - AMR_env$rsi_interpretation_history, + AMR_env$sir_interpretation_history <- rbind( + AMR_env$sir_interpretation_history, # recycling 1 to 2 rows does not seem to work, which is why rep() was added data.frame( datetime = rep(Sys.time(), length(rows)), @@ -980,14 +982,14 @@ as_rsi_method <- function(method_short, ref_table = rep(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)), method = rep(method_coerced, length(rows)), input = as.double(values), - outcome = as.rsi(new_rsi), + outcome = as.sir(new_sir), breakpoint_S_R = rep(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)), stringsAsFactors = FALSE ) ) } - df[rows, "result"] <- new_rsi + df[rows, "result"] <- new_sir } if (isTRUE(rise_warning)) { @@ -1003,26 +1005,26 @@ as_rsi_method <- function(method_short, df$result } -#' @rdname as.rsi +#' @rdname as.sir #' @param clean a [logical] to indicate whether previously stored results should be forgotten after returning the 'logbook' with results #' @export -rsi_interpretation_history <- function(clean = FALSE) { +sir_interpretation_history <- function(clean = FALSE) { meet_criteria(clean, allow_class = "logical", has_length = 1) - out.bak <- AMR_env$rsi_interpretation_history + out.bak <- AMR_env$sir_interpretation_history out <- out.bak if (NROW(out) == 0) { - message_("No results to return. Run `as.rsi()` on MIC values or disk diffusion zones first to see a 'logbook' data set here.") + message_("No results to return. Run `as.sir()` on MIC values or disk diffusion zones first to see a 'logbook' data set here.") return(invisible(NULL)) } out$ab_guideline <- as.ab(out$ab_guideline) out$mo_guideline <- as.mo(out$mo_guideline) - out$outcome <- as.rsi(out$outcome) + out$outcome <- as.sir(out$outcome) # keep stored for next use if (isTRUE(clean)) { - AMR_env$rsi_interpretation_history <- AMR_env$rsi_interpretation_history[0, , drop = FALSE] + AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE] } else { - AMR_env$rsi_interpretation_history <- out.bak + AMR_env$sir_interpretation_history <- out.bak } if (pkg_is_available("tibble", also_load = FALSE)) { @@ -1033,26 +1035,26 @@ rsi_interpretation_history <- function(clean = FALSE) { } # will be exported using s3_register() in R/zzz.R -pillar_shaft.rsi <- function(x, ...) { +pillar_shaft.sir <- function(x, ...) { out <- trimws(format(x)) if (has_colour()) { # colours will anyway not work when has_colour() == FALSE, # but then the indentation should also not be applied out[is.na(x)] <- font_grey(" NA") - out[x == "R"] <- font_red_bg(" R ") out[x == "S"] <- font_green_bg(" S ") out[x == "I"] <- font_orange_bg(" I ") + out[x == "R"] <- font_red_bg(" R ") } create_pillar_column(out, align = "left", width = 5) } # will be exported using s3_register() in R/zzz.R -type_sum.rsi <- function(x, ...) { - "rsi" +type_sum.sir <- function(x, ...) { + "sir" } # will be exported using s3_register() in R/zzz.R -freq.rsi <- function(x, ...) { +freq.sir <- function(x, ...) { x_name <- deparse(substitute(x)) x_name <- gsub(".*[$]", "", x_name) if (x_name %in% c("x", ".")) { @@ -1096,7 +1098,7 @@ freq.rsi <- function(x, ...) { # will be exported using s3_register() in R/zzz.R -get_skimmers.rsi <- function(column) { +get_skimmers.sir <- function(column) { # get the variable name 'skim_variable' name_call <- function(.data) { calls <- sys.calls() @@ -1104,7 +1106,7 @@ get_skimmers.rsi <- function(column) { calls_txt <- vapply(calls, function(x) paste(deparse(x), collapse = ""), FUN.VALUE = character(1)) if (any(calls_txt %like% "skim_variable", na.rm = TRUE)) { ind <- which(calls_txt %like% "skim_variable")[1L] - vars <- tryCatch(eval(parse(text = ".data$skim_variable$rsi"), envir = frms[[ind]]), + vars <- tryCatch(eval(parse(text = ".data$skim_variable$sir"), envir = frms[[ind]]), error = function(e) NULL ) tryCatch(ab_name(as.character(calls[[length(calls)]][[2]]), language = NULL), @@ -1116,7 +1118,7 @@ get_skimmers.rsi <- function(column) { } skimr::sfl( - skim_type = "rsi", + skim_type = "sir", ab_name = name_call, count_R = count_R, count_S = count_susceptible, @@ -1127,27 +1129,27 @@ get_skimmers.rsi <- function(column) { ) } -#' @method print rsi +#' @method print sir #' @export #' @noRd -print.rsi <- function(x, ...) { - cat("Class 'rsi'\n") +print.sir <- function(x, ...) { + cat("Class 'sir'\n") print(as.character(x), quote = FALSE) } -#' @method droplevels rsi +#' @method droplevels sir #' @export #' @noRd -droplevels.rsi <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA, ...) { +droplevels.sir <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA, ...) { x <- droplevels.factor(x, exclude = exclude, ...) - class(x) <- c("rsi", "ordered", "factor") + class(x) <- c("sir", "ordered", "factor") x } -#' @method summary rsi +#' @method summary sir #' @export #' @noRd -summary.rsi <- function(object, ...) { +summary.sir <- function(object, ...) { x <- object n <- sum(!is.na(x)) S <- sum(x == "S", na.rm = TRUE) @@ -1163,7 +1165,7 @@ summary.rsi <- function(object, ...) { x } value <- c( - "Class" = "rsi", + "Class" = "sir", "%R" = paste0(pad(percentage(R / n, digits = 1)), " (n=", R, ")"), "%SI" = paste0(pad(percentage((S + I) / n, digits = 1)), " (n=", S + I, ")"), "- %S" = paste0(pad(percentage(S / n, digits = 1)), " (n=", S, ")"), @@ -1173,59 +1175,59 @@ summary.rsi <- function(object, ...) { value } -#' @method [<- rsi +#' @method [<- sir #' @export #' @noRd -"[<-.rsi" <- function(i, j, ..., value) { - value <- as.rsi(value) +"[<-.sir" <- function(i, j, ..., value) { + value <- as.sir(value) y <- NextMethod() attributes(y) <- attributes(i) y } -#' @method [[<- rsi +#' @method [[<- sir #' @export #' @noRd -"[[<-.rsi" <- function(i, j, ..., value) { - value <- as.rsi(value) +"[[<-.sir" <- function(i, j, ..., value) { + value <- as.sir(value) y <- NextMethod() attributes(y) <- attributes(i) y } -#' @method c rsi +#' @method c sir #' @export #' @noRd -c.rsi <- function(...) { - as.rsi(unlist(lapply(list(...), as.character))) +c.sir <- function(...) { + as.sir(unlist(lapply(list(...), as.character))) } -#' @method unique rsi +#' @method unique sir #' @export #' @noRd -unique.rsi <- function(x, incomparables = FALSE, ...) { +unique.sir <- function(x, incomparables = FALSE, ...) { y <- NextMethod() attributes(y) <- attributes(x) y } -#' @method rep rsi +#' @method rep sir #' @export #' @noRd -rep.rsi <- function(x, ...) { +rep.sir <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(x) y } check_reference_data <- function(reference_data) { - if (!identical(reference_data, AMR::rsi_translation)) { - class_rsi <- vapply(FUN.VALUE = character(1), rsi_translation, function(x) paste0("<", class(x), ">", collapse = " and ")) + if (!identical(reference_data, AMR::clinical_breakpoints)) { + class_sir <- vapply(FUN.VALUE = character(1), clinical_breakpoints, function(x) paste0("<", class(x), ">", collapse = " and ")) class_ref <- vapply(FUN.VALUE = character(1), reference_data, function(x) paste0("<", class(x), ">", collapse = " and ")) - if (!all(names(class_rsi) == names(class_ref))) { - stop_("`reference_data` must have the same column names as the 'rsi_translation' data set.", call = -2) + if (!all(names(class_sir) == names(class_ref))) { + stop_("`reference_data` must have the same column names as the 'clinical_breakpoints' data set.", call = -2) } - if (!all(class_rsi == class_ref)) { - class_rsi[class_rsi != class_ref][1] - stop_("`reference_data` must be the same structure as the 'rsi_translation' data set. Column '", names(class_ref[class_rsi != class_ref][1]), "' is of class ", class_ref[class_rsi != class_ref][1], ", but should be of class ", class_rsi[class_rsi != class_ref][1], ".", call = -2) + if (!all(class_sir == class_ref)) { + class_sir[class_sir != class_ref][1] + stop_("`reference_data` must be the same structure as the 'clinical_breakpoints' data set. Column '", names(class_ref[class_sir != class_ref][1]), "' is of class ", class_ref[class_sir != class_ref][1], ", but should be of class ", class_sir[class_sir != class_ref][1], ".", call = -2) } } } diff --git a/R/rsi_calc.R b/R/sir_calc.R similarity index 93% rename from R/rsi_calc.R rename to R/sir_calc.R index cc8a6510c..5b2d9713c 100755 --- a/R/rsi_calc.R +++ b/R/sir_calc.R @@ -34,7 +34,7 @@ dots2vars <- function(...) { as.character(dots)[2:length(dots)] } -rsi_calc <- function(..., +sir_calc <- function(..., ab_result, minimum = 0, as_percent = FALSE, @@ -78,7 +78,7 @@ rsi_calc <- function(..., } if (length(dots) == 0 || all(dots == "df")) { # for complete data.frames, like example_isolates %pm>% select(AMC, GEN) %pm>% proportion_S() - # and the old rsi function, which has "df" as name of the first argument + # and the old sir function, which has "df" as name of the first argument x <- dots_df } else { # get dots that are in column names already, and the ones that will be once evaluated using dots_df or global env @@ -115,21 +115,21 @@ rsi_calc <- function(..., print_warning <- FALSE - ab_result <- as.rsi(ab_result) + ab_result <- as.sir(ab_result) if (is.data.frame(x)) { - rsi_integrity_check <- character(0) + sir_integrity_check <- character(0) for (i in seq_len(ncol(x))) { - # check integrity of columns: force 'rsi' class - if (!is.rsi(x[, i, drop = TRUE])) { - rsi_integrity_check <- c(rsi_integrity_check, as.character(x[, i, drop = TRUE])) - x[, i] <- suppressWarnings(as.rsi(x[, i, drop = TRUE])) # warning will be given later + # check integrity of columns: force 'sir' class + if (!is.sir(x[, i, drop = TRUE])) { + sir_integrity_check <- c(sir_integrity_check, as.character(x[, i, drop = TRUE])) + x[, i] <- suppressWarnings(as.sir(x[, i, drop = TRUE])) # warning will be given later print_warning <- TRUE } } - if (length(rsi_integrity_check) > 0) { + if (length(sir_integrity_check) > 0) { # this will give a warning for invalid results, of all input columns (so only 1 warning) - rsi_integrity_check <- as.rsi(rsi_integrity_check) + sir_integrity_check <- as.sir(sir_integrity_check) } x_transposed <- as.list(as.data.frame(t(x), stringsAsFactors = FALSE)) @@ -150,8 +150,8 @@ rsi_calc <- function(..., } } else { # x is not a data.frame - if (!is.rsi(x)) { - x <- as.rsi(x) + if (!is.sir(x)) { + x <- as.sir(x) print_warning <- TRUE } numerator <- sum(x %in% ab_result, na.rm = TRUE) @@ -159,9 +159,9 @@ rsi_calc <- function(..., } if (print_warning == TRUE) { - if (message_not_thrown_before("rsi_calc")) { - warning_("Increase speed by transforming to class 'rsi' on beforehand:\n", - " your_data %>% mutate_if(is.rsi.eligible, as.rsi)", + if (message_not_thrown_before("sir_calc")) { + warning_("Increase speed by transforming to class 'sir' on beforehand:\n", + " your_data %>% mutate_if(is_sir_eligible, as.sir)", call = FALSE ) } @@ -213,7 +213,7 @@ rsi_calc <- function(..., } } -rsi_calc_df <- function(type, # "proportion", "count" or "both" +sir_calc_df <- function(type, # "proportion", "count" or "both" data, translate_ab = "name", language = get_AMR_locale(), @@ -222,7 +222,7 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" combine_SI = TRUE, confidence_level = 0.95) { meet_criteria(type, is_in = c("proportion", "count", "both"), has_length = 1) - meet_criteria(data, allow_class = "data.frame", contains_column_class = "rsi") + meet_criteria(data, allow_class = "data.frame", contains_column_class = "sir") meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE) meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE) @@ -237,16 +237,16 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" if (is_null_or_grouped_tbl(data)) { data_has_groups <- TRUE groups <- setdiff(names(attributes(data)$groups), ".rows") - data <- data[, c(groups, colnames(data)[vapply(FUN.VALUE = logical(1), data, is.rsi)]), drop = FALSE] + data <- data[, c(groups, colnames(data)[vapply(FUN.VALUE = logical(1), data, is.sir)]), drop = FALSE] } else { data_has_groups <- FALSE - data <- data[, colnames(data)[vapply(FUN.VALUE = logical(1), data, is.rsi)], drop = FALSE] + data <- data[, colnames(data)[vapply(FUN.VALUE = logical(1), data, is.sir)], drop = FALSE] } data <- as.data.frame(data, stringsAsFactors = FALSE) if (isTRUE(combine_SI)) { for (i in seq_len(ncol(data))) { - if (is.rsi(data[, i, drop = TRUE])) { + if (is.sir(data[, i, drop = TRUE])) { data[, i] <- as.character(data[, i, drop = TRUE]) data[, i] <- gsub("(I|S)", "SI", data[, i, drop = TRUE]) } @@ -348,7 +348,7 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" if (isTRUE(combine_SI)) { out$interpretation <- factor(out$interpretation, levels = c("SI", "R"), ordered = TRUE) } else { - # don't use as.rsi() here, as it would add the class 'rsi' and we would like + # don't use as.sir() here, as it would add the class 'sir' 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) } @@ -372,5 +372,5 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" rownames(out) <- NULL out <- as_original_data_class(out, class(data.bak)) # will remove tibble groups - structure(out, class = c("rsi_df", class(out))) + structure(out, class = c("sir_df", "rsi_df", class(out))) } diff --git a/R/rsi_df.R b/R/sir_df.R similarity index 96% rename from R/rsi_df.R rename to R/sir_df.R index 1ea0b6082..4dca351a1 100755 --- a/R/rsi_df.R +++ b/R/sir_df.R @@ -29,7 +29,7 @@ #' @rdname proportion #' @export -rsi_df <- function(data, +sir_df <- function(data, translate_ab = "name", language = get_AMR_locale(), minimum = 30, @@ -37,7 +37,7 @@ rsi_df <- function(data, combine_SI = TRUE, confidence_level = 0.95) { tryCatch( - rsi_calc_df( + sir_calc_df( type = "both", data = data, translate_ab = translate_ab, @@ -47,6 +47,6 @@ rsi_df <- function(data, combine_SI = combine_SI, confidence_level = confidence_level ), - error = function(e) stop_(gsub("in rsi_calc_df(): ", "", e$message, fixed = TRUE), call = -5) + error = function(e) stop_(gsub("in sir_calc_df(): ", "", e$message, fixed = TRUE), call = -5) ) } diff --git a/R/sysdata.rda b/R/sysdata.rda index ef3829f7b..ddff74bd6 100755 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/translate.R b/R/translate.R index d88349c03..fb076cc83 100755 --- a/R/translate.R +++ b/R/translate.R @@ -140,7 +140,11 @@ reset_AMR_locale <- function() { #' @rdname translate #' @export translate_AMR <- function(x, language = get_AMR_locale()) { - translate_into_language(x, language = language) + translate_into_language(x, + language = language, + only_unknown = FALSE, + only_affect_ab_names = FALSE, + only_affect_mo_names = FALSE) } @@ -192,6 +196,7 @@ translate_into_language <- function(from, only_unknown = FALSE, only_affect_ab_names = FALSE, only_affect_mo_names = FALSE) { + # get ISO-639-1 of language lang <- validate_language(language) if (lang == "en") { @@ -259,7 +264,7 @@ translate_into_language <- function(from, # a kind of left join to get all results back out <- from_unique_translated[match(from.bak, from_unique)] - if (!identical(from.bak, out) && message_not_thrown_before("translation", entire_session = TRUE) && interactive()) { + if (!identical(from.bak, out) && get_AMR_locale() == lang && message_not_thrown_before("translation", entire_session = TRUE) && interactive()) { message(word_wrap( "Assuming the ", LANGUAGES_SUPPORTED_NAMES[[lang]]$exonym, " language (", LANGUAGES_SUPPORTED_NAMES[[lang]]$endonym, ") for the AMR package. See `set_AMR_locale()` to change this or to silence this once-per-session note.", diff --git a/R/vctrs.R b/R/vctrs.R index eba037fef..105783793 100755 --- a/R/vctrs.R +++ b/R/vctrs.R @@ -95,6 +95,7 @@ vec_cast.character.mo <- function(x, to, ...) { as.character(x) } vec_cast.mo.character <- function(x, to, ...) { + add_MO_lookup_to_AMR_env() return_after_integrity_check(x, "microorganism code", as.character(AMR_env$MO_lookup$mo)) } @@ -141,16 +142,16 @@ vec_math.mic <- function(.fn, x, ...) { .fn(as.double(x), ...) } -# S3: rsi -vec_ptype2.character.rsi <- function(x, y, ...) { +# S3: sir +vec_ptype2.character.sir <- function(x, y, ...) { x } -vec_ptype2.rsi.character <- function(x, y, ...) { +vec_ptype2.sir.character <- function(x, y, ...) { y } -vec_cast.character.rsi <- function(x, to, ...) { +vec_cast.character.sir <- function(x, to, ...) { as.character(x) } -vec_cast.rsi.character <- function(x, to, ...) { - as.rsi(x) +vec_cast.sir.character <- function(x, to, ...) { + as.sir(x) } diff --git a/R/zz_deprecated.R b/R/zz_deprecated.R new file mode 100755 index 000000000..81325f089 --- /dev/null +++ b/R/zz_deprecated.R @@ -0,0 +1,210 @@ +# ==================================================================== # +# TITLE # +# AMR: An R Package for Working with Antimicrobial Resistance Data # +# # +# SOURCE # +# https://github.com/msberends/AMR # +# # +# CITE AS # +# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C # +# (2022). AMR: An R Package for Working with Antimicrobial Resistance # +# Data. Journal of Statistical Software, 104(3), 1-31. # +# doi:10.18637/jss.v104.i03 # +# # +# Developed at the University of Groningen and the University Medical # +# Center Groningen in The Netherlands, in collaboration with many # +# colleagues from around the world, see our website. # +# # +# 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 the full manual and a complete tutorial about # +# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # +# ==================================================================== # + +#' Deprecated Functions +#' +#' These functions are so-called '[Deprecated]'. **They will be removed in a future release.** Using the functions will give a warning with the name of the function it has been replaced by (if there is one). +#' @keywords internal +#' @name AMR-deprecated +#' @rdname AMR-deprecated +#' @export +NA_rsi_ <- set_clean_class(factor(NA_character_, levels = c("S", "I", "R"), ordered = TRUE), + new_class = c("rsi", "ordered", "factor")) +#' @rdname AMR-deprecated +#' @export +as.rsi <- function(x, ...) { + deprecation_warning("as.rsi", "as.sir") + UseMethod("as.rsi") +} +#' @noRd +#' @export +as.rsi.default <- function(...) { + as.sir.default(...) +} +#' @noRd +#' @export +as.rsi.mic <- function(...) { + as.sir.mic(...) +} +#' @noRd +#' @export +as.rsi.disk <- function(...) { + as.sir.disk(...) +} +#' @noRd +#' @export +as.rsi.data.frame <- function(...) { + as.sir.data.frame(...) +} + +#' @rdname AMR-deprecated +#' @export +facet_rsi <- function(...) { + deprecation_warning("facet_rsi", "facet_sir") + facet_sir(...) +} +#' @rdname AMR-deprecated +#' @export +geom_rsi <- function(...) { + deprecation_warning("geom_rsi", "geom_sir") + geom_sir(...) +} +#' @rdname AMR-deprecated +#' @export +ggplot_rsi <- function(...) { + deprecation_warning("ggplot_rsi", "ggplot_sir") + ggplot_sir(...) +} +#' @rdname AMR-deprecated +#' @export +ggplot_rsi_predict <- function(...) { + deprecation_warning("ggplot_rsi_predict", "ggplot_sir_predict") + ggplot_sir_predict(...) +} +#' @rdname AMR-deprecated +#' @export +is.rsi <- function(x, ...) { + # this is an exception, so mutate_if(is.rsi, as.sir) can be used + if (inherits(x, "data.frame")) { + unname(vapply(FUN.VALUE = logical(1), x, is.rsi)) + } else { + inherits(x, "rsi") + } +} +#' @rdname AMR-deprecated +#' @export +is.rsi.eligible <- function(...) { + deprecation_warning("is.rsi.eligible", "is_sir_eligible") + is_sir_eligible(...) +} +#' @rdname AMR-deprecated +#' @export +labels_rsi_count <- function(...) { + deprecation_warning("labels_rsi_count", "labels_sir_count") + labels_sir_count(...) +} +#' @rdname AMR-deprecated +#' @export +n_rsi <- function(...) { + deprecation_warning("n_rsi", "n_sir") + n_sir(...) +} +#' @rdname AMR-deprecated +#' @export +random_rsi <- function(...) { + deprecation_warning("random_rsi", "random_sir") + random_sir(...) +} +#' @rdname AMR-deprecated +#' @export +rsi_df <- function(...) { + deprecation_warning("rsi_df", "sir_df") + sir_df(...) +} +#' @rdname AMR-deprecated +#' @export +rsi_predict <- function(...) { + deprecation_warning("rsi_predict", "sir_predict") + sir_predict(...) +} +#' @rdname AMR-deprecated +#' @export +scale_rsi_colours <- function(...) { + deprecation_warning("scale_rsi_colours", "scale_sir_colours") + scale_sir_colours(...) +} +#' @rdname AMR-deprecated +#' @export +theme_rsi <- function(...) { + deprecation_warning("theme_rsi", "theme_sir") + theme_sir(...) +} + +# will be exported using s3_register() in R/zzz.R +pillar_shaft.rsi <- pillar_shaft.sir +type_sum.rsi <- function(x, ...) { + deprecation_warning(extra_msg = "* Transform your old 'rsi' class to the new 'sir' class with `as.sir()` using e.g.:\n your_data %>% mutate_if(is.rsi, as.sir)") + paste0("rsi", font_bold(font_red("[!]"))) +} + +#' @method print rsi +#' @export +#' @noRd +print.rsi <- function(x, ...) { + deprecation_warning(extra_msg = "Transform your old 'rsi' class to the new 'sir' class with `as.sir()`") + cat("Class 'rsi'", font_bold(font_red("[!]\n"))) + print(as.character(x), quote = FALSE) +} + +#' @noRd +#' @export +`[<-.rsi` <- `[<-.sir` +#' @noRd +#' @export +`[[<-.rsi` <- `[[<-.sir` +#' @noRd +#' @export +barplot.rsi <- barplot.sir +#' @noRd +#' @export +c.rsi <- c.sir +#' @noRd +#' @export +droplevels.rsi <- droplevels.sir +#' @noRd +#' @export +plot.rsi <- plot.sir +#' @noRd +#' @export +rep.rsi <- rep.sir +#' @noRd +#' @export +summary.rsi <- summary.sir +#' @noRd +#' @export +unique.rsi <- unique.sir + +deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL) { + if (is.null(old)) { + warning_(extra_msg) + } else { + env <- paste0("deprecated_", old) + if (!env %in% names(AMR_env)) { + AMR_env[[paste0("deprecated_", old)]] <- 1 + warning_(ifelse(is.null(new), + paste0("The `", old, "()` function is no longer in use"), + paste0("The `", old, "()` function has been replaced with `", new, "()`")), + ", see `?AMR-deprecated`.", + ifelse(!is.null(extra_msg), + paste0(" ", extra_msg), + ""), + "\nThis warning will be shown once per session.") + } + } +} diff --git a/R/zzz.R b/R/zzz.R index 7dd478f75..77aaa2edf 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -55,7 +55,7 @@ AMR_env$av_previously_coerced <- data.frame( av = character(0), stringsAsFactors = FALSE ) -AMR_env$rsi_interpretation_history <- data.frame( +AMR_env$sir_interpretation_history <- data.frame( datetime = Sys.time()[0], index = integer(0), ab_input = character(0), @@ -97,32 +97,34 @@ if (utf8_supported && !is_latex) { s3_register("pillar::pillar_shaft", "ab") s3_register("pillar::pillar_shaft", "av") s3_register("pillar::pillar_shaft", "mo") - s3_register("pillar::pillar_shaft", "rsi") + s3_register("pillar::pillar_shaft", "sir") + s3_register("pillar::pillar_shaft", "rsi") # remove in a later version s3_register("pillar::pillar_shaft", "mic") s3_register("pillar::pillar_shaft", "disk") s3_register("pillar::type_sum", "ab") s3_register("pillar::type_sum", "av") s3_register("pillar::type_sum", "mo") - s3_register("pillar::type_sum", "rsi") + s3_register("pillar::type_sum", "sir") + s3_register("pillar::type_sum", "rsi") # remove in a later version s3_register("pillar::type_sum", "mic") s3_register("pillar::type_sum", "disk") # Support for frequency tables from the cleaner package s3_register("cleaner::freq", "mo") - s3_register("cleaner::freq", "rsi") + s3_register("cleaner::freq", "sir") # Support for skim() from the skimr package if (pkg_is_available("skimr", also_load = FALSE, min_version = "2.0.0")) { s3_register("skimr::get_skimmers", "mo") - s3_register("skimr::get_skimmers", "rsi") + s3_register("skimr::get_skimmers", "sir") s3_register("skimr::get_skimmers", "mic") s3_register("skimr::get_skimmers", "disk") } # Support for autoplot() from the ggplot2 package - s3_register("ggplot2::autoplot", "rsi") + s3_register("ggplot2::autoplot", "sir") s3_register("ggplot2::autoplot", "mic") s3_register("ggplot2::autoplot", "disk") s3_register("ggplot2::autoplot", "resistance_predict") # Support for fortify from the ggplot2 package - s3_register("ggplot2::fortify", "rsi") + s3_register("ggplot2::fortify", "sir") s3_register("ggplot2::fortify", "mic") s3_register("ggplot2::fortify", "disk") # Support vctrs package for use in e.g. dplyr verbs @@ -164,11 +166,11 @@ if (utf8_supported && !is_latex) { s3_register("vctrs::vec_cast", "mic.character") s3_register("vctrs::vec_cast", "mic.double") s3_register("vctrs::vec_math", "mic") - # S3: rsi - s3_register("vctrs::vec_ptype2", "character.rsi") - s3_register("vctrs::vec_ptype2", "rsi.character") - s3_register("vctrs::vec_cast", "character.rsi") - s3_register("vctrs::vec_cast", "rsi.character") + # S3: sir + s3_register("vctrs::vec_ptype2", "character.sir") + s3_register("vctrs::vec_ptype2", "sir.character") + s3_register("vctrs::vec_cast", "character.sir") + s3_register("vctrs::vec_cast", "sir.character") # if mo source exists, fire it up (see mo_source()) if (tryCatch(file.exists(getOption("AMR_mo_source", "~/mo_source.rds")), error = function(e) FALSE)) { @@ -179,11 +181,10 @@ if (utf8_supported && !is_latex) { try(loadNamespace("tibble"), silent = TRUE) } - # reference data - they have additional columns compared to `antibiotics` and `microorganisms` to improve speed + # reference data - they have additional to improve algorithm speed # they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB) - AMR_env$AB_lookup <- create_AB_lookup() - AMR_env$AV_lookup <- create_AV_lookup() - AMR_env$MO_lookup <- create_MO_lookup() + AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP) + AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP) } .onAttach <- function(lib, pkg) { @@ -206,36 +207,3 @@ if (utf8_supported && !is_latex) { }, error = function(e) packageStartupMessage("Failed: ", e$message)) } } - -# Helper functions -------------------------------------------------------- - -create_AB_lookup <- function() { - cbind(AMR::antibiotics, AB_LOOKUP) -} - -create_AV_lookup <- function() { - cbind(AMR::antivirals, AV_LOOKUP) -} - -create_MO_lookup <- function() { - MO_lookup <- AMR::microorganisms - - MO_lookup$kingdom_index <- NA_real_ - MO_lookup[which(MO_lookup$kingdom == "Bacteria" | MO_lookup$mo == "UNKNOWN"), "kingdom_index"] <- 1 - MO_lookup[which(MO_lookup$kingdom == "Fungi"), "kingdom_index"] <- 2 - MO_lookup[which(MO_lookup$kingdom == "Protozoa"), "kingdom_index"] <- 3 - MO_lookup[which(MO_lookup$kingdom == "Archaea"), "kingdom_index"] <- 4 - # all the rest - MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5 - - if (length(MO_FULLNAME_LOWER) != nrow(MO_lookup)) { - packageStartupMessage("fullname_lower not same size - applied tolower(), update sysdata.rda!") - MO_lookup$fullname_lower <- tolower(MO_lookup$fullname) - } else { - MO_lookup$fullname_lower <- MO_FULLNAME_LOWER - } - MO_lookup$full_first <- substr(MO_lookup$fullname_lower, 1, 1) - MO_lookup$species_first <- tolower(substr(MO_lookup$species, 1, 1)) # tolower for groups (Streptococcus, Salmonella) - MO_lookup$subspecies_first <- tolower(substr(MO_lookup$subspecies, 1, 1)) # tolower for Salmonella serovars - MO_lookup -} diff --git a/README.md b/README.md index e1409b00e..88c9f3ce2 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This work was published in the Journal of Statistical Software (Volume 104(3); [ `AMR` is a free, open-source and independent R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. It is currently being used in over 175 countries. -After installing this package, R knows ~52,000 distinct microbial species and all ~600 antibiotic, antimycotic, and antiviral drugs by name and code (including ATC, WHONET/EARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data. Antimicrobial names and group names are available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish, and Ukrainian. +After installing this package, R knows ~52,000 distinct microbial species and all ~600 antibiotic, antimycotic, and antiviral drugs by name and code (including ATC, WHONET/EARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. It supports any data format, including WHONET/EARS-Net data. Antimicrobial names and group names are available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish, and Ukrainian. This package is fully independent of any other R package and works on Windows, macOS and Linux with all versions of R since R-3.0.0 (April 2013). It was designed to work in any setting, including those with very limited resources. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the University of Groningen, in collaboration with non-profit organisations Certe Medical Diagnostics and Advice Foundation and University Medical Center Groningen. This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. diff --git a/_pkgdown.yml b/_pkgdown.yml index 18107f43b..edda6e6b5 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -146,10 +146,10 @@ reference: - title: "Preparing data: antimicrobial resistance" desc: > With `as.mic()` and `as.disk()` you can transform your raw input to valid MIC or disk diffusion values. - Use `as.rsi()` for cleaning raw data to let it only contain "R", "I" and "S", or to interpret MIC or disk diffusion values as R/SI based on the lastest EUCAST and CLSI guidelines. + Use `as.sir()` for cleaning raw data to let it only contain "R", "I" and "S", or to interpret MIC or disk diffusion values as SIR based on the lastest EUCAST and CLSI guidelines. Afterwards, you can extend antibiotic interpretations by applying [EUCAST rules](https://www.eucast.org/expert_rules_and_intrinsic_resistance/) with `eucast_rules()`. contents: - - "`as.rsi`" + - "`as.sir`" - "`as.mic`" - "`as.disk`" - "`eucast_rules`" @@ -169,7 +169,7 @@ reference: - "`mdro`" - "`count`" - "`plot`" - - "`ggplot_rsi`" + - "`ggplot_sir`" - "`bug_drug_combinations`" - "`antibiotic_class_selectors`" - "`mean_amr_distance`" @@ -201,7 +201,7 @@ reference: - "`dosage`" - "`WHOCC`" - "`example_isolates_unclean`" - - "`rsi_translation`" + - "`clinical_breakpoints`" - "`WHONET`" - title: "Other: miscellaneous functions" diff --git a/data-raw/_pre_commit_hook.R b/data-raw/_pre_commit_hook.R index de2e808d5..8925df92d 100644 --- a/data-raw/_pre_commit_hook.R +++ b/data-raw/_pre_commit_hook.R @@ -144,21 +144,6 @@ create_species_cons_cops <- function(type = c("CoNS", "CoPS")) { ] } } -create_MO_fullname_lower <- function() { - AMR_env$MO_lookup <- AMR::microorganisms - # use this paste instead of `fullname` to work with Viridans Group Streptococci, etc. - AMR_env$MO_lookup$fullname_lower <- tolower(trimws(paste( - AMR_env$MO_lookup$genus, - AMR_env$MO_lookup$species, - AMR_env$MO_lookup$subspecies - ))) - ind <- AMR_env$MO_lookup$genus == "" | grepl("^[(]unknown ", AMR_env$MO_lookup$fullname, perl = TRUE) - AMR_env$MO_lookup[ind, "fullname_lower"] <- tolower(AMR_env$MO_lookup[ind, "fullname", drop = TRUE]) - AMR_env$MO_lookup$fullname_lower <- trimws(gsub("[^.a-z0-9/ \\-]+", "", AMR_env$MO_lookup$fullname_lower, perl = TRUE)) - # special for Salmonella - they have cities as subspecies but not the species (enterica) in the fullname: - AMR_env$MO_lookup$fullname_lower[which(AMR_env$MO_lookup$subspecies %like_case% "^[A-Z]")] <- gsub(" enterica ", " ", AMR_env$MO_lookup$fullname_lower[which(AMR_env$MO_lookup$subspecies %like_case% "^[A-Z]")], fixed = TRUE) - AMR_env$MO_lookup$fullname_lower -} MO_CONS <- create_species_cons_cops("CoNS") MO_COPS <- create_species_cons_cops("CoPS") MO_STREP_ABCG <- AMR_env$MO_lookup$mo[which(AMR_env$MO_lookup$genus == "Streptococcus" & @@ -166,7 +151,6 @@ MO_STREP_ABCG <- AMR_env$MO_lookup$mo[which(AMR_env$MO_lookup$genus == "Streptoc "pyogenes", "agalactiae", "dysgalactiae", "equi", "canis", "group A", "group B", "group C", "group G" ))] -MO_FULLNAME_LOWER <- create_MO_fullname_lower() MO_PREVALENT_GENERA <- c( "Absidia", "Acanthamoeba", "Acremonium", "Aedes", "Alternaria", "Amoeba", "Ancylostoma", "Angiostrongylus", "Anisakis", "Anopheles", "Apophysomyces", "Aspergillus", "Aureobasidium", "Basidiobolus", "Beauveria", @@ -298,7 +282,6 @@ suppressMessages(usethis::use_data(EUCAST_RULES_DF, MO_CONS, MO_COPS, MO_STREP_ABCG, - MO_FULLNAME_LOWER, MO_PREVALENT_GENERA, AB_LOOKUP, AV_LOOKUP, @@ -369,20 +352,20 @@ changed_md5 <- function(object) { } # give official names to ABs and MOs -rsi <- rsi_translation %>% +clin_break <- clinical_breakpoints %>% mutate(mo_name = mo_name(mo, language = NULL, keep_synonyms = TRUE, info = FALSE), .after = mo) %>% mutate(ab_name = ab_name(ab, language = NULL), .after = ab) -if (changed_md5(rsi)) { - usethis::ui_info(paste0("Saving {usethis::ui_value('rsi_translation')} to {usethis::ui_value('data-raw/')}")) - write_md5(rsi) - try(saveRDS(rsi, "data-raw/rsi_translation.rds", version = 2, compress = "xz"), silent = TRUE) - try(write.table(rsi, "data-raw/rsi_translation.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE) - try(haven::write_sas(rsi, "data-raw/rsi_translation.sas"), silent = TRUE) - try(haven::write_sav(rsi, "data-raw/rsi_translation.sav"), silent = TRUE) - try(haven::write_dta(rsi, "data-raw/rsi_translation.dta"), silent = TRUE) - try(openxlsx::write.xlsx(rsi, "data-raw/rsi_translation.xlsx"), silent = TRUE) - try(arrow::write_feather(rsi, "data-raw/rsi_translation.feather"), silent = TRUE) - try(arrow::write_parquet(rsi, "data-raw/rsi_translation.parquet"), silent = TRUE) +if (changed_md5(clin_break)) { + usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}")) + write_md5(clin_break) + try(saveRDS(clin_break, "data-raw/clinical_breakpoints.rds", version = 2, compress = "xz"), silent = TRUE) + try(write.table(clin_break, "data-raw/clinical_breakpoints.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE) + try(haven::write_sas(clin_break, "data-raw/clinical_breakpoints.sas"), silent = TRUE) + try(haven::write_sav(clin_break, "data-raw/clinical_breakpoints.sav"), silent = TRUE) + try(haven::write_dta(clin_break, "data-raw/clinical_breakpoints.dta"), silent = TRUE) + try(openxlsx::write.xlsx(clin_break, "data-raw/clinical_breakpoints.xlsx"), silent = TRUE) + try(arrow::write_feather(clin_break, "data-raw/clinical_breakpoints.feather"), silent = TRUE) + try(arrow::write_parquet(clin_break, "data-raw/clinical_breakpoints.parquet"), silent = TRUE) } if (changed_md5(microorganisms)) { diff --git a/data-raw/rsi.md5 b/data-raw/clin_break.md5 similarity index 100% rename from data-raw/rsi.md5 rename to data-raw/clin_break.md5 diff --git a/data-raw/rsi_translation.dta b/data-raw/clinical_breakpoints.dta similarity index 99% rename from data-raw/rsi_translation.dta rename to data-raw/clinical_breakpoints.dta index 1f5240a84..20cb0a67e 100644 Binary files a/data-raw/rsi_translation.dta and b/data-raw/clinical_breakpoints.dta differ diff --git a/data-raw/rsi_translation.feather b/data-raw/clinical_breakpoints.feather similarity index 99% rename from data-raw/rsi_translation.feather rename to data-raw/clinical_breakpoints.feather index c1a18e9b4..fe182eb45 100644 Binary files a/data-raw/rsi_translation.feather and b/data-raw/clinical_breakpoints.feather differ diff --git a/data-raw/rsi_translation.parquet b/data-raw/clinical_breakpoints.parquet similarity index 99% rename from data-raw/rsi_translation.parquet rename to data-raw/clinical_breakpoints.parquet index c43fc42dc..b18f0eeb0 100644 Binary files a/data-raw/rsi_translation.parquet and b/data-raw/clinical_breakpoints.parquet differ diff --git a/data-raw/clinical_breakpoints.rds b/data-raw/clinical_breakpoints.rds new file mode 100644 index 000000000..3fe62cc75 Binary files /dev/null and b/data-raw/clinical_breakpoints.rds differ diff --git a/data-raw/rsi_translation.sas b/data-raw/clinical_breakpoints.sas similarity index 99% rename from data-raw/rsi_translation.sas rename to data-raw/clinical_breakpoints.sas index 15961b5a4..b41c2ab5f 100644 Binary files a/data-raw/rsi_translation.sas and b/data-raw/clinical_breakpoints.sas differ diff --git a/data-raw/rsi_translation.sav b/data-raw/clinical_breakpoints.sav similarity index 99% rename from data-raw/rsi_translation.sav rename to data-raw/clinical_breakpoints.sav index 7a6d84005..5b96128b7 100644 Binary files a/data-raw/rsi_translation.sav and b/data-raw/clinical_breakpoints.sav differ diff --git a/data-raw/rsi_translation.txt b/data-raw/clinical_breakpoints.txt similarity index 100% rename from data-raw/rsi_translation.txt rename to data-raw/clinical_breakpoints.txt diff --git a/data-raw/rsi_translation.xlsx b/data-raw/clinical_breakpoints.xlsx similarity index 99% rename from data-raw/rsi_translation.xlsx rename to data-raw/clinical_breakpoints.xlsx index 68c519bcf..f9214fc36 100644 Binary files a/data-raw/rsi_translation.xlsx and b/data-raw/clinical_breakpoints.xlsx differ diff --git a/data-raw/microorganisms.txt b/data-raw/microorganisms.txt index 30cb622c9..9a1a2c8d5 100644 --- a/data-raw/microorganisms.txt +++ b/data-raw/microorganisms.txt @@ -45554,7 +45554,7 @@ "B_STRPT_ORLX" "Streptococcus oriloxodontae" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "oriloxodontae" "" "species" "Shinozaki-Kuwahara et al., 2014" "LPSN" "792340" "517118" 1.5 "" "B_STRPT_ORSS" "Streptococcus orisasini" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "orisasini" "" "species" "Takada et al., 2013" "LPSN" "790987" "517118" 1.5 "" "B_STRPT_ORSR" "Streptococcus orisratti" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "orisratti" "" "species" "Zhu et al., 2000" "LPSN" "781365" "517118" 1.5 "438034004" -"B_STRPT_RSIS" "Streptococcus orisuis" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "orisuis" "" "species" "Takada et al., 2007" "LPSN" "781314" "517118" 1.5 "6441000146108" +"B_STRPT_sirS" "Streptococcus orisuis" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "orisuis" "" "species" "Takada et al., 2007" "LPSN" "781314" "517118" 1.5 "6441000146108" "B_STRPT_OVIS" "Streptococcus ovis" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "ovis" "" "species" "Collins et al., 2001" "LPSN" "781366" "517118" 1.5 "438035003" "B_STRPT_OVBR" "Streptococcus ovuberis" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "ovuberis" "" "species" "Zamora et al., 2017" "LPSN" "796216" "517118" 1.5 "" "B_STRPT_PCFC" "Streptococcus pacificus" "accepted" "Bacteria" "Bacillota" "Bacilli" "Lactobacillales" "Streptococcaceae" "Streptococcus" "pacificus" "" "species" "Volokhov et al., 2021" "LPSN" "19573" "517118" 1.5 "" diff --git a/data-raw/read_EUCAST.R b/data-raw/read_EUCAST.R index 9495b4c9e..f96d1ffd4 100644 --- a/data-raw/read_EUCAST.R +++ b/data-raw/read_EUCAST.R @@ -230,7 +230,7 @@ read_EUCAST <- function(sheet, file, guideline_name) { mo = ifelse(mo == "", mo_sheet, mo) ) %>% filter(!(is.na(breakpoint_S) & is.na(breakpoint_R))) %>% - # comply with rsi_translation for now + # comply with clinical_breakpoints for now transmute(guideline, method, site = case_when( @@ -285,7 +285,7 @@ for (i in 2:length(sheets_to_analyse)) { } # 2021-07-12 fix for Morganellaceae (check other lines too next time) -morg <- rsi_translation %>% +morg <- clinical_breakpoints %>% as_tibble() %>% filter( ab == "IPM", @@ -298,7 +298,7 @@ morg[which(morg$method == "MIC"), "breakpoint_R"] <- 4 morg[which(morg$method == "DISK"), "breakpoint_S"] <- 50 morg[which(morg$method == "DISK"), "breakpoint_R"] <- 19 -rsi_translation <- rsi_translation %>% +clinical_breakpoints <- clinical_breakpoints %>% bind_rows(morg) %>% bind_rows(morg %>% mutate(guideline = "EUCAST 2020")) %>% diff --git a/data-raw/reproduction_of_rsi_translation.R b/data-raw/reproduction_of_clinical_breakpoints.R similarity index 96% rename from data-raw/reproduction_of_rsi_translation.R rename to data-raw/reproduction_of_clinical_breakpoints.R index 6ed1db0be..fd7fe1d5f 100644 --- a/data-raw/reproduction_of_rsi_translation.R +++ b/data-raw/reproduction_of_clinical_breakpoints.R @@ -28,7 +28,7 @@ # ==================================================================== # # This script runs in under a minute and renews all guidelines of CLSI and EUCAST! -# Run it with source("data-raw/reproduction_of_rsi_translation.R") +# Run it with source("data-raw/reproduction_of_clinical_breakpoints.R") library(dplyr) library(readr) @@ -206,11 +206,11 @@ breakpoints_new[which(is.na(breakpoints_new$breakpoint_R)), "breakpoint_R"] <- b # check again breakpoints_new %>% filter(guideline == "EUCAST 2022", ab == "AMC", mo == "B_[ORD]_ENTRBCTR", method == "MIC") # compare with current version -rsi_translation %>% filter(guideline == "EUCAST 2022", ab == "AMC", mo == "B_[ORD]_ENTRBCTR", method == "MIC") +clinical_breakpoints %>% filter(guideline == "EUCAST 2022", ab == "AMC", mo == "B_[ORD]_ENTRBCTR", method == "MIC") # Save to package ---- -rsi_translation <- breakpoints_new -usethis::use_data(rsi_translation, overwrite = TRUE, compress = "xz", version = 2) -rm(rsi_translation) +clinical_breakpoints <- breakpoints_new +usethis::use_data(clinical_breakpoints, overwrite = TRUE, compress = "xz", version = 2) +rm(clinical_breakpoints) devtools::load_all(".") diff --git a/data-raw/reproduction_of_intrinsic_resistant.R b/data-raw/reproduction_of_intrinsic_resistant.R index c1defc53b..8c0afb613 100644 --- a/data-raw/reproduction_of_intrinsic_resistant.R +++ b/data-raw/reproduction_of_intrinsic_resistant.R @@ -31,7 +31,7 @@ library(AMR) library(dplyr) int_resis <- data.frame(mo = microorganisms$mo, stringsAsFactors = FALSE) for (i in seq_len(nrow(antibiotics))) { - int_resis$new <- as.rsi("S") + int_resis$new <- as.sir("S") colnames(int_resis)[ncol(int_resis)] <- antibiotics$ab[i] } @@ -43,7 +43,7 @@ int_resis <- eucast_rules(int_resis, info = FALSE ) -int_resis2 <- int_resis[, sapply(int_resis, function(x) any(!is.rsi(x) | x == "R")), drop = FALSE] %>% +int_resis2 <- int_resis[, sapply(int_resis, function(x) any(!is.sir(x) | x == "R")), drop = FALSE] %>% tidyr::pivot_longer(-mo) %>% filter(value == "R") %>% select(mo, ab = name) diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index c5d36dac0..09a55f7f4 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -1333,7 +1333,7 @@ rm(microorganisms) # and check: these codes should not be missing (will otherwise throw a unit test error): AMR::microorganisms.codes %>% filter(!mo %in% taxonomy$mo) -AMR::rsi_translation %>% filter(!mo %in% taxonomy$mo) +AMR::clinical_breakpoints %>% filter(!mo %in% taxonomy$mo) AMR::example_isolates %>% filter(!mo %in% taxonomy$mo) AMR::intrinsic_resistant %>% filter(!mo %in% taxonomy$mo) @@ -1342,10 +1342,10 @@ devtools::load_all(".") # reset previously changed mo codes -if (!identical(rsi_translation$mo, as.mo(rsi_translation$mo, language = NULL))) { - rsi_translation$mo <- as.mo(rsi_translation$mo, language = NULL) - usethis::use_data(rsi_translation, overwrite = TRUE, version = 2, compress = "xz") - rm(rsi_translation) +if (!identical(clinical_breakpoints$mo, as.mo(clinical_breakpoints$mo, language = NULL))) { + clinical_breakpoints$mo <- as.mo(clinical_breakpoints$mo, language = NULL) + usethis::use_data(clinical_breakpoints, overwrite = TRUE, version = 2, compress = "xz") + rm(clinical_breakpoints) } if (!identical(microorganisms.codes$mo, as.mo(microorganisms.codes$mo, language = NULL))) { diff --git a/data-raw/rsi_translation.rds b/data-raw/rsi_translation.rds deleted file mode 100644 index d0563813f..000000000 Binary files a/data-raw/rsi_translation.rds and /dev/null differ diff --git a/data/clinical_breakpoints.rda b/data/clinical_breakpoints.rda new file mode 100644 index 000000000..ebd267d15 Binary files /dev/null and b/data/clinical_breakpoints.rda differ diff --git a/data/example_isolates.rda b/data/example_isolates.rda index 86956a8ef..ed5badc95 100644 Binary files a/data/example_isolates.rda and b/data/example_isolates.rda differ diff --git a/data/rsi_translation.rda b/data/rsi_translation.rda deleted file mode 100644 index c30ad0de8..000000000 Binary files a/data/rsi_translation.rda and /dev/null differ diff --git a/index.md b/index.md index 3413852f5..46d2a82ed 100644 --- a/index.md +++ b/index.md @@ -19,7 +19,7 @@ The `AMR` package is a [free and open-source](#copyright) R package with [zero d This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)). -After installing this package, R knows [**~52,000 distinct microbial species**](./reference/microorganisms.html) (updated December 2022) and all [**~600 antibiotic, antimycotic and antiviral drugs**](./reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl). +After installing this package, R knows [**~52,000 distinct microbial species**](./reference/microorganisms.html) (updated December 2022) and all [**~600 antibiotic, antimycotic and antiviral drugs**](./reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl). ##### Used in 175 countries, translated to 16 languages @@ -122,7 +122,7 @@ out %>% set_ab_names(property = "atc") This package was intended as a comprehensive toolbox for integrated AMR data analysis. This package can be used for: * Reference for the taxonomy of microorganisms, since the package contains all microbial (sub)species from the List of Prokaryotic names with Standing in Nomenclature ([LPSN]((https://lpsn.dsmz.de))) and the Global Biodiversity Information Facility ([GBIF](https://www.gbif.org)) ([manual](./reference/mo_property.html)) - * Interpreting raw MIC and disk diffusion values, based on any CLSI or EUCAST guideline from the last 10 years ([manual](./reference/as.rsi.html)) + * Interpreting raw MIC and disk diffusion values, based on any CLSI or EUCAST guideline from the last 10 years ([manual](./reference/as.sir.html)) * Retrieving antimicrobial drug names, doses and forms of administration from clinical health care records ([manual](./reference/ab_from_text.html)) * Determining first isolates to be used for AMR data analysis ([manual](./reference/first_isolate.html)) * Calculating antimicrobial resistance ([tutorial](./articles/AMR.html)) @@ -135,7 +135,7 @@ This package was intended as a comprehensive toolbox for integrated AMR data ana * Applying EUCAST expert rules ([manual](./reference/eucast_rules.html)) * Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code ([manual](./reference/mo_property.html)) * Getting LOINC codes of an antibiotic, or getting properties of an antibiotic based on a LOINC code ([manual](./reference/ab_property.html)) - * Machine reading the EUCAST and CLSI guidelines from 2011-2021 to translate MIC values and disk diffusion diameters to R/SI ([link](./articles/datasets.html)) + * Machine reading the EUCAST and CLSI guidelines from 2011-2021 to translate MIC values and disk diffusion diameters to SIR ([link](./articles/datasets.html)) * Principal component analysis for AMR ([tutorial](./articles/PCA.html)) ### Get this package diff --git a/inst/tinytest/test-count.R b/inst/tinytest/test-count.R index 09d54a184..a44cc3143 100644 --- a/inst/tinytest/test-count.R +++ b/inst/tinytest/test-count.R @@ -29,7 +29,7 @@ expect_equal(count_resistant(example_isolates$AMX), count_R(example_isolates$AMX)) expect_equal(count_susceptible(example_isolates$AMX), count_SI(example_isolates$AMX)) -expect_equal(count_all(example_isolates$AMX), n_rsi(example_isolates$AMX)) +expect_equal(count_all(example_isolates$AMX), n_sir(example_isolates$AMX)) # AMX resistance in `example_isolates` expect_equal(count_R(example_isolates$AMX), 804) @@ -103,10 +103,10 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { ) ) - # grouping in rsi_calc_df() (= backbone of rsi_df()) + # grouping in sir_calc_df() (= backbone of sir_df()) expect_true("ward" %in% (example_isolates %>% group_by(ward) %>% select(ward, AMX, CIP, gender) %>% - rsi_df() %>% + sir_df() %>% colnames())) } diff --git a/inst/tinytest/test-data.R b/inst/tinytest/test-data.R index b012f5fe1..a2c203a2f 100644 --- a/inst/tinytest/test-data.R +++ b/inst/tinytest/test-data.R @@ -38,8 +38,8 @@ expect_identical(class(antibiotics$ab), c("ab", "character")) # check cross table reference expect_true(all(microorganisms.codes$mo %in% microorganisms$mo)) expect_true(all(example_isolates$mo %in% microorganisms$mo)) -expect_true(all(rsi_translation$mo %in% microorganisms$mo)) -expect_true(all(rsi_translation$ab %in% antibiotics$ab)) +expect_true(all(clinical_breakpoints$mo %in% microorganisms$mo)) +expect_true(all(clinical_breakpoints$ab %in% antibiotics$ab)) expect_true(all(intrinsic_resistant$mo %in% microorganisms$mo)) expect_true(all(intrinsic_resistant$ab %in% antibiotics$ab)) expect_false(any(is.na(microorganisms.codes$code))) @@ -47,10 +47,10 @@ expect_false(any(is.na(microorganisms.codes$mo))) expect_true(all(dosage$ab %in% antibiotics$ab)) expect_true(all(dosage$name %in% antibiotics$name)) # check valid disks/MICs -expect_false(any(is.na(as.mic(rsi_translation[which(rsi_translation$method == "MIC"), "breakpoint_S", drop = TRUE])))) -expect_false(any(is.na(as.mic(rsi_translation[which(rsi_translation$method == "MIC"), "breakpoint_R", drop = TRUE])))) -expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "DISK"), "breakpoint_S", drop = TRUE])))) -expect_false(any(is.na(as.disk(rsi_translation[which(rsi_translation$method == "DISK"), "breakpoint_R", drop = TRUE])))) +expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_S", drop = TRUE])))) +expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_R", drop = TRUE])))) +expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_S", drop = TRUE])))) +expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_R", drop = TRUE])))) # antibiotic names must always be coercible to their original AB code expect_identical(as.ab(antibiotics$name), antibiotics$ab) diff --git a/inst/tinytest/test-eucast_rules.R b/inst/tinytest/test-eucast_rules.R index ad08c12cd..37048c5d7 100755 --- a/inst/tinytest/test-eucast_rules.R +++ b/inst/tinytest/test-eucast_rules.R @@ -104,8 +104,8 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { example_isolates %>% filter(mo_family(mo) == "Enterobacteriaceae") %>% mutate( - TIC = as.rsi("R"), - PIP = as.rsi("S") + TIC = as.sir("R"), + PIP = as.sir("S") ) %>% eucast_rules(col_mo = "mo", version_expertrules = 3.1, info = FALSE) %>% pull(PIP) %>% @@ -117,15 +117,15 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { } # azithromycin and clarythromycin must be equal to Erythromycin -a <- suppressWarnings(as.rsi(eucast_rules(data.frame( +a <- suppressWarnings(as.sir(eucast_rules(data.frame( mo = example_isolates$mo, ERY = example_isolates$ERY, - AZM = as.rsi("R"), + AZM = as.sir("R"), CLR = factor("R"), stringsAsFactors = FALSE ), version_expertrules = 3.1, -only_rsi_columns = FALSE +only_sir_columns = FALSE )$CLR)) b <- example_isolates$ERY expect_identical( @@ -162,34 +162,34 @@ expect_stdout(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, ru expect_identical( eucast_rules(data.frame( mo = c("Escherichia coli", "Enterobacter cloacae"), - cefotax = as.rsi(c("S", "S")) + cefotax = as.sir(c("S", "S")) ), ampc_cephalosporin_resistance = TRUE, info = FALSE )$cefotax, - as.rsi(c("S", "R")) + as.sir(c("S", "R")) ) expect_identical( eucast_rules(data.frame( mo = c("Escherichia coli", "Enterobacter cloacae"), - cefotax = as.rsi(c("S", "S")) + cefotax = as.sir(c("S", "S")) ), ampc_cephalosporin_resistance = NA, info = FALSE )$cefotax, - as.rsi(c("S", NA)) + as.sir(c("S", NA)) ) expect_identical( eucast_rules(data.frame( mo = c("Escherichia coli", "Enterobacter cloacae"), - cefotax = as.rsi(c("S", "S")) + cefotax = as.sir(c("S", "S")) ), ampc_cephalosporin_resistance = NULL, info = FALSE )$cefotax, - as.rsi(c("S", "S")) + as.sir(c("S", "S")) ) # EUCAST dosage ----------------------------------------------------------- diff --git a/inst/tinytest/test-first_isolate.R b/inst/tinytest/test-first_isolate.R index c8ca6858d..7cc03773b 100755 --- a/inst/tinytest/test-first_isolate.R +++ b/inst/tinytest/test-first_isolate.R @@ -214,9 +214,9 @@ expect_equal( 1108 ) -# empty rsi results +# empty sir results expect_equal( - sum(first_isolate(example_isolates, include_untested_rsi = FALSE)), + sum(first_isolate(example_isolates, include_untested_sir = FALSE)), 1366 ) diff --git a/inst/tinytest/test-ggplot_rsi.R b/inst/tinytest/test-ggplot_rsi.R index 24af561c6..cb5cd5490 100644 --- a/inst/tinytest/test-ggplot_rsi.R +++ b/inst/tinytest/test-ggplot_rsi.R @@ -34,7 +34,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa expect_equal( (example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi())$data %>% + ggplot_sir())$data %>% summarise_all(resistance) %>% as.double(), example_isolates %>% @@ -45,15 +45,15 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa expect_stdout(print(example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi(x = "interpretation", facet = "antibiotic"))) + ggplot_sir(x = "interpretation", facet = "antibiotic"))) expect_stdout(print(example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi(x = "antibiotic", facet = "interpretation"))) + ggplot_sir(x = "antibiotic", facet = "interpretation"))) expect_equal( (example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>% + ggplot_sir(x = "interpretation", facet = "antibiotic"))$data %>% summarise_all(resistance) %>% as.double(), example_isolates %>% @@ -65,7 +65,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa expect_equal( (example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% + ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(resistance) %>% as.double(), example_isolates %>% @@ -77,7 +77,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa expect_equal( (example_isolates %>% select(AMC, CIP) %>% - ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% + ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(count_resistant) %>% as.double(), example_isolates %>% @@ -124,7 +124,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0") & AMR:::pkg_is_availa z = c("Value4", "Value5", "Value6") )) + geom_col(aes(x = x, y = y, fill = z)) + - scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R"))$data, + scale_sir_colours(Value4 = "S", Value5 = "I", Value6 = "R"))$data, "data.frame" ) } diff --git a/inst/tinytest/test-mdro.R b/inst/tinytest/test-mdro.R index 87532d9d0..6dcd933e6 100755 --- a/inst/tinytest/test-mdro.R +++ b/inst/tinytest/test-mdro.R @@ -133,13 +133,13 @@ expect_equal( ) x <- data.frame( - rifampicin = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - inh = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - gatifloxacin = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - eth = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - pza = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - MFX = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)), - KAN = random_rsi(5000, prob_RSI = c(0.4, 0.1, 0.5)) + rifampicin = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + inh = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + gatifloxacin = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + eth = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + pza = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + MFX = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)), + KAN = random_sir(5000, prob_sir = c(0.4, 0.1, 0.5)) ) expect_true(length(unique(mdr_tb(x))) > 2) diff --git a/inst/tinytest/test-mean_amr_distance.R b/inst/tinytest/test-mean_amr_distance.R index 0a7290f6d..25e151af6 100644 --- a/inst/tinytest/test-mean_amr_distance.R +++ b/inst/tinytest/test-mean_amr_distance.R @@ -29,7 +29,7 @@ vctr_disk <- as.disk(c(20:25)) vctr_mic <- as.mic(2^c(0:5)) -vctr_rsi <- as.rsi(c("S", "S", "I", "I", "R", "R")) +vctr_sir <- as.sir(c("S", "S", "I", "I", "R", "R")) expect_identical( mean_amr_distance(vctr_disk), @@ -42,22 +42,22 @@ expect_identical( ) expect_identical( - mean_amr_distance(vctr_rsi, combine_SI = FALSE), + mean_amr_distance(vctr_sir, combine_SI = FALSE), (c(1, 1, 2, 2, 3, 3) - mean(c(1, 1, 2, 2, 3, 3))) / sd(c(1, 1, 2, 2, 3, 3)) ) expect_identical( - mean_amr_distance(vctr_rsi, combine_SI = TRUE), + mean_amr_distance(vctr_sir, combine_SI = TRUE), (c(1, 1, 1, 1, 3, 3) - mean(c(1, 1, 1, 1, 3, 3))) / sd(c(1, 1, 1, 1, 3, 3)) ) expect_equal( - mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_rsi, TOB = vctr_disk)), + mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_sir, TOB = vctr_disk)), c(-1.10603655, -0.74968823, -0.39333990, -0.03699158, 0.96485397, 1.32120229), tolerance = 0.00001 ) expect_equal( - mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_rsi, TOB = vctr_disk), 2:3), + mean_amr_distance(data.frame(AMX = vctr_mic, GEN = vctr_sir, TOB = vctr_disk), 2:3), c(-0.9909017, -0.7236405, -0.4563792, -0.1891180, 1.0463891, 1.3136503), tolerance = 0.00001 ) diff --git a/inst/tinytest/test-pca.R b/inst/tinytest/test-pca.R index 0286debef..02f27eebe 100644 --- a/inst/tinytest/test-pca.R +++ b/inst/tinytest/test-pca.R @@ -63,7 +63,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { order = mo_order(mo), genus = mo_genus(mo) ) %>% - summarise_if(is.rsi, resistance, minimum = 0) + summarise_if(is.sir, resistance, minimum = 0) pca_result <- resistance_data %>% pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT") expect_inherits(pca_result, "prcomp") diff --git a/inst/tinytest/test-proportion.R b/inst/tinytest/test-proportion.R index 811627405..ceaffff45 100755 --- a/inst/tinytest/test-proportion.R +++ b/inst/tinytest/test-proportion.R @@ -32,8 +32,8 @@ expect_equal(proportion_SI(example_isolates$AMX), susceptibility(example_isolate # AMX resistance in `example_isolates` expect_equal(proportion_R(example_isolates$AMX), 0.5955556, tolerance = 0.0001) expect_equal(proportion_I(example_isolates$AMX), 0.002222222, tolerance = 0.0001) -expect_equal(rsi_confidence_interval(example_isolates$AMX)[1], 0.5688204, tolerance = 0.0001) -expect_equal(rsi_confidence_interval(example_isolates$AMX)[2], 0.6218738, tolerance = 0.0001) +expect_equal(sir_confidence_interval(example_isolates$AMX)[1], 0.5688204, tolerance = 0.0001) +expect_equal(sir_confidence_interval(example_isolates$AMX)[2], 0.6218738, tolerance = 0.0001) expect_equal( 1 - proportion_R(example_isolates$AMX) - proportion_I(example_isolates$AMX), proportion_S(example_isolates$AMX) @@ -69,7 +69,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { R = proportion_R(CIP, as_percent = TRUE), I = proportion_I(CIP, as_percent = TRUE), S = proportion_S(CIP, as_percent = TRUE), - n = n_rsi(CIP), + n = n_sir(CIP), total = n() ) %>% pull(n) %>% @@ -83,11 +83,11 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { group_by(ward) %>% summarise( cipro_p = proportion_SI(CIP, as_percent = TRUE), - cipro_n = n_rsi(CIP), + cipro_n = n_sir(CIP), genta_p = proportion_SI(GEN, as_percent = TRUE), - genta_n = n_rsi(GEN), + genta_n = n_sir(GEN), combination_p = proportion_SI(CIP, GEN, as_percent = TRUE), - combination_n = n_rsi(CIP, GEN) + combination_n = n_sir(CIP, GEN) ) %>% pull(combination_n), c(1181, 577, 116) @@ -110,7 +110,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { ) ) - expect_warning(example_isolates %>% group_by(ward) %>% summarise(across(KAN, rsi_confidence_interval))) + expect_warning(example_isolates %>% group_by(ward) %>% summarise(across(KAN, sir_confidence_interval))) } expect_warning(proportion_R(as.character(example_isolates$AMC))) @@ -120,12 +120,12 @@ expect_warning(proportion_S(as.character( example_isolates$GEN ))) -expect_warning(n_rsi(as.character( +expect_warning(n_sir(as.character( example_isolates$AMC, example_isolates$GEN ))) expect_equal( - suppressWarnings(n_rsi(as.character( + suppressWarnings(n_sir(as.character( example_isolates$AMC, example_isolates$GEN ))), diff --git a/inst/tinytest/test-random.R b/inst/tinytest/test-random.R index 7e7251c01..4d427cc7d 100644 --- a/inst/tinytest/test-random.R +++ b/inst/tinytest/test-random.R @@ -37,4 +37,4 @@ expect_inherits(random_disk(100), "disk") expect_inherits(random_disk(100, mo = "Klebsiella pneumoniae"), "disk") expect_inherits(random_disk(100, mo = "Klebsiella pneumoniae", ab = "meropenem"), "disk") expect_inherits(random_disk(100, ab = "meropenem"), "disk") -expect_inherits(random_rsi(100), "rsi") +expect_inherits(random_sir(100), "sir") diff --git a/inst/tinytest/test-resistance_predict.R b/inst/tinytest/test-resistance_predict.R index 5b66f9987..658c5ffb8 100644 --- a/inst/tinytest/test-resistance_predict.R +++ b/inst/tinytest/test-resistance_predict.R @@ -30,7 +30,7 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { expect_stdout(AMX_R <- example_isolates %>% filter(mo == "B_ESCHR_COLI") %>% - rsi_predict( + sir_predict( col_ab = "AMX", col_date = "date", model = "binomial", @@ -51,25 +51,25 @@ expect_stdout(x <- suppressMessages(resistance_predict(example_isolates, pdf(NULL) # prevent Rplots.pdf being created expect_silent(plot(x)) if (AMR:::pkg_is_available("ggplot2")) { - expect_silent(ggplot_rsi_predict(x)) + expect_silent(ggplot_sir_predict(x)) expect_silent(autoplot(x)) - expect_error(ggplot_rsi_predict(example_isolates)) + expect_error(ggplot_sir_predict(example_isolates)) } -expect_stdout(rsi_predict( +expect_stdout(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "AMX", col_date = "date", info = TRUE )) -expect_stdout(rsi_predict( +expect_stdout(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "loglin", col_ab = "AMX", col_date = "date", info = TRUE )) -expect_stdout(rsi_predict( +expect_stdout(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "lin", col_ab = "AMX", @@ -77,34 +77,34 @@ expect_stdout(rsi_predict( info = TRUE )) -expect_error(rsi_predict( +expect_error(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "INVALID MODEL", col_ab = "AMX", col_date = "date", info = TRUE )) -expect_error(rsi_predict( +expect_error(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "NOT EXISTING COLUMN", col_date = "date", info = TRUE )) -expect_error(rsi_predict( +expect_error(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), model = "binomial", col_ab = "AMX", col_date = "NOT EXISTING COLUMN", info = TRUE )) -expect_error(rsi_predict( +expect_error(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), col_ab = "AMX", col_date = "NOT EXISTING COLUMN", info = TRUE )) -expect_error(rsi_predict( +expect_error(sir_predict( x = subset(example_isolates, mo == "B_ESCHR_COLI"), col_ab = "AMX", col_date = "date", diff --git a/inst/tinytest/test-rsi.R b/inst/tinytest/test-rsi.R index 5cbe24230..d7181e234 100644 --- a/inst/tinytest/test-rsi.R +++ b/inst/tinytest/test-rsi.R @@ -27,34 +27,34 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -# we must only have EUCAST and CLSI, because otherwise the rules in as.rsi() will fail +# we must only have EUCAST and CLSI, because otherwise the rules in as.sir() will fail expect_identical( - unique(gsub("[^A-Z]", "", AMR::rsi_translation$guideline)), + unique(gsub("[^A-Z]", "", AMR::clinical_breakpoints$guideline)), c("EUCAST", "CLSI") ) -expect_true(as.rsi("S") < as.rsi("I")) -expect_true(as.rsi("I") < as.rsi("R")) -expect_true(is.rsi(as.rsi("S"))) +expect_true(as.sir("S") < as.sir("I")) +expect_true(as.sir("I") < as.sir("R")) +expect_true(is.sir(as.sir("S"))) x <- example_isolates$AMX -expect_inherits(x[1], "rsi") -expect_inherits(x[[1]], "rsi") -expect_inherits(c(x[1], x[9]), "rsi") -expect_inherits(unique(x[1], x[9]), "rsi") +expect_inherits(x[1], "sir") +expect_inherits(x[[1]], "sir") +expect_inherits(c(x[1], x[9]), "sir") +expect_inherits(unique(x[1], x[9]), "sir") pdf(NULL) # prevent Rplots.pdf being created -expect_silent(barplot(as.rsi(c("S", "I", "R")))) -expect_silent(plot(as.rsi(c("S", "I", "R")))) +expect_silent(barplot(as.sir(c("S", "I", "R")))) +expect_silent(plot(as.sir(c("S", "I", "R")))) if (AMR:::pkg_is_available("ggplot2")) { - expect_inherits(autoplot(as.rsi(c("S", "I", "R"))), "gg") + expect_inherits(autoplot(as.sir(c("S", "I", "R"))), "gg") } -expect_stdout(print(as.rsi(c("S", "I", "R")))) -expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R")) -expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R")) -expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA) +expect_stdout(print(as.sir(c("S", "I", "R")))) +expect_equal(as.character(as.sir(c(1:3))), c("S", "I", "R")) +expect_equal(as.character(as.sir(c(1:3))), c("S", "I", "R")) +expect_equal(suppressWarnings(as.logical(as.sir("INVALID VALUE"))), NA) expect_equal( - summary(as.rsi(c("S", "R"))), + summary(as.sir(c("S", "R"))), structure(c( - "Class" = "rsi", + "Class" = "sir", "%R" = "50.0% (n=1)", "%SI" = "50.0% (n=1)", "- %S" = "50.0% (n=1)", @@ -62,31 +62,31 @@ expect_equal( ), class = c("summaryDefault", "table")) ) expect_identical( - as.logical(lapply(example_isolates, is.rsi.eligible)), - as.logical(lapply(example_isolates, is.rsi)) + as.logical(lapply(example_isolates, is_sir_eligible)), + as.logical(lapply(example_isolates, is.sir)) ) -expect_error(as.rsi.mic(as.mic(16))) -expect_error(as.rsi.disk(as.disk(16))) +expect_error(as.sir.mic(as.mic(16))) +expect_error(as.sir.disk(as.disk(16))) expect_error(get_guideline("this one does not exist")) if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { - # 40 rsi columns + # 40 sir columns expect_equal( example_isolates %>% mutate_at(vars(PEN:RIF), as.character) %>% - lapply(is.rsi.eligible) %>% + lapply(is_sir_eligible) %>% as.logical() %>% sum(), 40 ) - expect_equal(sum(is.rsi(example_isolates)), 40) + expect_equal(sum(is.sir(example_isolates)), 40) - expect_stdout(print(tibble(ab = as.rsi("S")))) + expect_stdout(print(tibble(ab = as.sir("S")))) expect_true(example_isolates %>% select(AMC, MEM) %>% - mutate(MEM = as.rsi(ifelse(AMC == "S", "S", MEM))) %>% + mutate(MEM = as.sir(ifelse(AMC == "S", "S", MEM))) %>% pull(MEM) %>% - is.rsi()) + is.sir()) } if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) { expect_inherits( @@ -106,12 +106,12 @@ if (AMR:::pkg_is_available("skimr", min_version = "2.0.0")) { } } -expect_equal(as.rsi(c("", "-", NA, "NULL")), c(NA_rsi_, NA_rsi_, NA_rsi_, NA_rsi_)) +expect_equal(as.sir(c("", "-", NA, "NULL")), c(NA_sir_, NA_sir_, NA_sir_, NA_sir_)) # S. pneumoniae/ampicillin in EUCAST 2020: 0.5-2 ug/ml (R is only > 2) expect_equal(suppressMessages( as.character( - as.rsi( + as.sir( x = as.mic(c(0.125, 0.5, 1, 2, 4)), mo = "B_STRPT_PNMN", ab = "AMP", @@ -123,7 +123,7 @@ expect_equal(suppressMessages( # S. pneumoniae/amoxicillin in CLSI 2019: 2-8 ug/ml (R is 8 and > 8) expect_equal(suppressMessages( as.character( - as.rsi( + as.sir( x = as.mic(c(1, 2, 4, 8, 16)), mo = "B_STRPT_PNMN", ab = "AMX", @@ -133,31 +133,31 @@ expect_equal(suppressMessages( c("S", "S", "I", "R", "R") ) -expect_true(is.data.frame(rsi_interpretation_history(clean = FALSE))) -expect_true(is.data.frame(rsi_interpretation_history(clean = TRUE))) -expect_true(is.null(rsi_interpretation_history())) +expect_true(is.data.frame(sir_interpretation_history(clean = FALSE))) +expect_true(is.data.frame(sir_interpretation_history(clean = TRUE))) +expect_true(is.null(sir_interpretation_history())) # cutoffs at MIC = 8 expect_equal( - suppressMessages(as.rsi(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020")), - as.rsi("S") + suppressMessages(as.sir(as.mic(2), "E. coli", "ampicillin", guideline = "EUCAST 2020")), + as.sir("S") ) expect_equal( - suppressMessages(as.rsi(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")), - as.rsi("R") + suppressMessages(as.sir(as.mic(32), "E. coli", "ampicillin", guideline = "EUCAST 2020")), + as.sir("R") ) if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { expect_true(suppressWarnings(example_isolates %>% mutate(amox_mic = as.mic(2)) %>% select(mo, amox_mic) %>% - as.rsi() %>% + as.sir() %>% pull(amox_mic) %>% - is.rsi())) + is.sir())) } expect_equal( as.character( - as.rsi( + as.sir( x = as.disk(22), mo = "B_STRPT_PNMN", ab = "ERY", @@ -168,7 +168,7 @@ expect_equal( ) expect_equal( as.character( - as.rsi( + as.sir( x = as.disk(18), mo = "B_STRPT_PNMN", ab = "ERY", @@ -179,7 +179,7 @@ expect_equal( ) expect_equal( as.character( - as.rsi( + as.sir( x = as.disk(10), mo = "B_STRPT_PNMN", ab = "ERY", @@ -192,9 +192,9 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0")) { expect_true(example_isolates %>% mutate(amox_disk = as.disk(15)) %>% select(mo, amox_disk) %>% - as.rsi(guideline = "CLSI") %>% + as.sir(guideline = "CLSI") %>% pull(amox_disk) %>% - is.rsi()) + is.sir()) } # frequency tables if (AMR:::pkg_is_available("cleaner")) { @@ -212,26 +212,26 @@ df <- data.frame( CLR = "V" ) # note about cleaning expect_inherits( - suppressWarnings(as.rsi(df)), + suppressWarnings(as.sir(df)), "data.frame" ) expect_inherits( - suppressWarnings(as.rsi(data.frame( + suppressWarnings(as.sir(data.frame( mo = "Escherichia coli", - amoxi = c("R", "S", "I", "invalid") + amoxi = c("S", "I", "R", "invalid") ))$amoxi), - "rsi" + "sir" ) -expect_warning(as.rsi(data.frame( +expect_warning(as.sir(data.frame( mo = "E. coli", NIT = c("<= 2", 32) ))) -expect_message(as.rsi(data.frame( +expect_message(as.sir(data.frame( mo = "E. coli", NIT = c("<= 2", 32), uti = TRUE ))) -expect_message(as.rsi(data.frame( +expect_message(as.sir(data.frame( mo = "E. coli", NIT = c("<= 2", 32), specimen = c("urine", "blood") diff --git a/inst/tinytest/test-vctrs.R b/inst/tinytest/test-vctrs.R index 046d582e6..76c5de43d 100755 --- a/inst/tinytest/test-vctrs.R +++ b/inst/tinytest/test-vctrs.R @@ -33,7 +33,7 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) { mo = as.mo("Escherichia coli"), mic = as.mic(2), disk = as.disk(20), - rsi = as.rsi("S")) + sir = as.sir("S")) check1 <- lapply(test, class) test[1, "ab"] <- "GEN" test[1, "mo"] <- "B_KLBSL_PNMN" @@ -42,11 +42,11 @@ if (AMR:::pkg_is_available("dplyr", also_load = FALSE)) { test[1, "disk"] <- "35" test[1, "disk"] <- 25 test[1, "disk"] <- 26L - test[1, "rsi"] <- "R" + test[1, "sir"] <- "R" check2 <- lapply(test, class) expect_identical(check1, check2) - test <- dplyr::tibble(cipro = as.rsi("S"), + test <- dplyr::tibble(cipro = as.sir("S"), variable = "test") expect_equal(nrow(test[quinolones() == "S", ]), 1) expect_equal(nrow(test[quinolones() == "R", ]), 0) diff --git a/man/AMR-deprecated.Rd b/man/AMR-deprecated.Rd index 07b8221ed..ab25dd7ef 100755 --- a/man/AMR-deprecated.Rd +++ b/man/AMR-deprecated.Rd @@ -1,8 +1,58 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/deprecated.R +% Please edit documentation in R/zz_deprecated.R +\docType{data} \name{AMR-deprecated} \alias{AMR-deprecated} +\alias{NA_rsi_} +\alias{as.rsi} +\alias{facet_rsi} +\alias{geom_rsi} +\alias{ggplot_rsi} +\alias{ggplot_rsi_predict} +\alias{is.rsi} +\alias{is.rsi.eligible} +\alias{labels_rsi_count} +\alias{n_rsi} +\alias{random_rsi} +\alias{rsi_df} +\alias{rsi_predict} +\alias{scale_rsi_colours} +\alias{theme_rsi} \title{Deprecated Functions} +\format{ +An object of class \code{rsi} (inherits from \code{ordered}, \code{factor}) of length 1. +} +\usage{ +NA_rsi_ + +as.rsi(x, ...) + +facet_rsi(...) + +geom_rsi(...) + +ggplot_rsi(...) + +ggplot_rsi_predict(...) + +is.rsi(x, ...) + +is.rsi.eligible(...) + +labels_rsi_count(...) + +n_rsi(...) + +random_rsi(...) + +rsi_df(...) + +rsi_predict(...) + +scale_rsi_colours(...) + +theme_rsi(...) +} \description{ These functions are so-called '\link{Deprecated}'. \strong{They will be removed in a future release.} Using the functions will give a warning with the name of the function it has been replaced by (if there is one). } diff --git a/man/AMR.Rd b/man/AMR.Rd index a1d944178..c353473bd 100755 --- a/man/AMR.Rd +++ b/man/AMR.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/amr.R +% Please edit documentation in R/aa_amr-package.R \docType{package} \name{AMR} \alias{AMR} @@ -28,37 +28,17 @@ A BibTeX entry for LaTeX users is: \description{ Welcome to the \code{AMR} package. -\code{AMR} is a free, open-source and independent \R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. +The \code{AMR} package is a \href{https://msberends.github.io/AMR/#copyright}{free and open-source} R package with \href{https://en.wikipedia.org/wiki/Dependency_hell}{zero dependencies} to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. \strong{Our aim is to provide a standard} for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. \href{https://msberends.github.io/AMR/authors.html}{Many different researchers} from around the globe are continually helping us to make this a successful and durable project! -This work was published in the Journal of Statistical Software (Volume 104(3); \doi{10.18637/jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}). +This work was published in the Journal of Statistical Software (Volume 104(3); \href{https://doi.org/10.18637/jss.v104.i03}{DOI 10.18637/jss.v104.i03}) and formed the basis of two PhD theses (\href{https://doi.org/10.33612/diss.177417131}{DOI 10.33612/diss.177417131} and \href{https://doi.org/10.33612/diss.192486375}{DOI 10.33612/diss.192486375}). -After installing this package, \R knows ~52,000 distinct microbial species and all ~600 antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-NET, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data. +After installing this package, R knows \href{https://msberends.github.io/AMR/reference/microorganisms.html}{\strong{~52,000}} (updated December 2022) and all \href{https://msberends.github.io/AMR/reference/antibiotics.html}{\strong{~600 antibiotic, antimycotic and antiviral drugs}} by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). \strong{It was designed to work in any setting, including those with very limited resources}. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the \href{https://www.rug.nl}{University of Groningen}, in collaboration with non-profit organisations \href{https://www.certe.nl}{Certe Medical Diagnostics and Advice Foundation} and \href{https://www.umcg.nl}{University Medical Center Groningen}. -This package is fully independent of any other \R package and works on Windows, macOS and Linux with all versions of \R since R-3.0.0 (April 2013). It was designed to work in any setting, including those with very limited resources. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the University of Groningen, in collaboration with non-profit organisations Certe Medical Diagnostics and Advice and University Medical Center Groningen. This \R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. - -This package can be used for: -\itemize{ -\item Reference for the taxonomy of microorganisms, since the package contains all microbial (sub)species from the List of Prokaryotic names with Standing in Nomenclature (LPSN) and the Global Biodiversity Information Facility (GBIF) -\item Interpreting raw MIC and disk diffusion values, based on any CLSI or EUCAST guideline from the last 10 years -\item Retrieving antimicrobial drug names, doses and forms of administration from clinical health care records -\item Determining first isolates to be used for AMR data analysis -\item Calculating antimicrobial resistance -\item Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO) -\item Calculating (empirical) susceptibility of both mono therapy and combination therapies -\item Predicting future antimicrobial resistance using regression models -\item Getting properties for any microorganism (such as Gram stain, species, genus or family) -\item Getting properties for any antibiotic (such as name, code of EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name) -\item Plotting antimicrobial resistance -\item Applying EUCAST expert rules -\item Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code -\item Getting LOINC codes of an antibiotic, or getting properties of an antibiotic based on a LOINC code -\item Machine reading the EUCAST and CLSI guidelines from 2011-2020 to translate MIC values and disk diffusion diameters to R/SI -\item Principal component analysis for AMR -} +The \code{AMR} package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages. } \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \seealso{ diff --git a/man/WHONET.Rd b/man/WHONET.Rd index 4539b8913..8c027a476 100755 --- a/man/WHONET.Rd +++ b/man/WHONET.Rd @@ -32,7 +32,7 @@ A \link[tibble:tibble]{tibble} with 500 observations and 53 variables: \item \verb{Inducible clindamycin resistance}\cr Clindamycin can be induced? \item \code{Comment}\cr Other comments \item \verb{Date of data entry}\cr \link{Date} this data was entered in WHONET -\item \code{AMP_ND10:CIP_EE}\cr 28 different antibiotics. You can lookup the abbreviations in the \link{antibiotics} data set, or use e.g. \code{\link[=ab_name]{ab_name("AMP")}} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link[=as.rsi]{as.rsi()}}. +\item \code{AMP_ND10:CIP_EE}\cr 0 different antibiotics. You can lookup the abbreviations in the \link{antibiotics} data set, or use e.g. \code{\link[=ab_name]{ab_name("AMP")}} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link[=as.sir]{as.sir()}}. } } \usage{ diff --git a/man/ab_property.Rd b/man/ab_property.Rd index 7a49e2b62..e1935f75a 100755 --- a/man/ab_property.Rd +++ b/man/ab_property.Rd @@ -104,7 +104,7 @@ European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{htt \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ @@ -166,7 +166,7 @@ if (require("dplyr")) { head() example_isolates \%>\% - set_ab_names(where(is.rsi)) \%>\% + set_ab_names(where(is.sir)) \%>\% colnames() example_isolates \%>\% diff --git a/man/add_custom_antimicrobials.Rd b/man/add_custom_antimicrobials.Rd index 73f47a365..c7618ac27 100755 --- a/man/add_custom_antimicrobials.Rd +++ b/man/add_custom_antimicrobials.Rd @@ -93,8 +93,8 @@ ab_name("J01CR50") # even antibiotic selectors work x <- data.frame( random_column = "some value", - coflu = as.rsi("S"), - ampicillin = as.rsi("R") + coflu = as.sir("S"), + ampicillin = as.sir("R") ) x x[, betalactams()] diff --git a/man/add_custom_microorganisms.Rd b/man/add_custom_microorganisms.Rd index e0db9432d..81f63b6e8 100755 --- a/man/add_custom_microorganisms.Rd +++ b/man/add_custom_microorganisms.Rd @@ -22,7 +22,7 @@ This function will fill in missing taxonomy for you, if specific taxonomic colum There are two ways to automate this process: -\strong{Method 1:} Using the , which is the preferred method. To use this method: +\strong{Method 1:} Using the option \code{\link[=AMR-options]{AMR_custom_mo}}, which is the preferred method. To use this method: \enumerate{ \item Create a data set in the structure of the \link{microorganisms} data set (containing at the very least column "genus") and save it with \code{\link[=saveRDS]{saveRDS()}} to a location of choice, e.g. \code{"~/my_custom_mo.rds"}, or any remote location. \item Set the file location to the \code{AMR_custom_mo} \R option: \code{options(AMR_custom_mo = "~/my_custom_mo.rds")}. This can even be a remote file location, such as an https URL. Since options are not saved between \R sessions, it is best to save this option to the \code{.Rprofile} file so that it will be loaded on start-up of \R. To do this, open the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}, add this text and save the file: diff --git a/man/age_groups.Rd b/man/age_groups.Rd index aa529535a..2e675ea86 100755 --- a/man/age_groups.Rd +++ b/man/age_groups.Rd @@ -62,7 +62,7 @@ if (require("dplyr") && require("ggplot2")) { filter(mo == as.mo("Escherichia coli")) \%>\% group_by(age_group = age_groups(age)) \%>\% select(age_group, CIP) \%>\% - ggplot_rsi( + ggplot_sir( x = "age_group", minimum = 0, x.title = "Age Group", diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd index 39e75635f..df584cbed 100755 --- a/man/antibiotic_class_selectors.Rd +++ b/man/antibiotic_class_selectors.Rd @@ -34,66 +34,66 @@ \alias{not_intrinsic_resistant} \title{Antibiotic Selectors} \usage{ -ab_class(ab_class, only_rsi_columns = FALSE, only_treatable = TRUE, ...) +ab_class(ab_class, only_sir_columns = FALSE, only_treatable = TRUE, ...) -ab_selector(filter, only_rsi_columns = FALSE, only_treatable = TRUE, ...) +ab_selector(filter, only_sir_columns = FALSE, only_treatable = TRUE, ...) -aminoglycosides(only_rsi_columns = FALSE, only_treatable = TRUE, ...) +aminoglycosides(only_sir_columns = FALSE, only_treatable = TRUE, ...) -aminopenicillins(only_rsi_columns = FALSE, ...) +aminopenicillins(only_sir_columns = FALSE, ...) -antifungals(only_rsi_columns = FALSE, ...) +antifungals(only_sir_columns = FALSE, ...) -antimycobacterials(only_rsi_columns = FALSE, ...) +antimycobacterials(only_sir_columns = FALSE, ...) -betalactams(only_rsi_columns = FALSE, only_treatable = TRUE, ...) +betalactams(only_sir_columns = FALSE, only_treatable = TRUE, ...) -carbapenems(only_rsi_columns = FALSE, only_treatable = TRUE, ...) +carbapenems(only_sir_columns = FALSE, only_treatable = TRUE, ...) -cephalosporins(only_rsi_columns = FALSE, ...) +cephalosporins(only_sir_columns = FALSE, ...) -cephalosporins_1st(only_rsi_columns = FALSE, ...) +cephalosporins_1st(only_sir_columns = FALSE, ...) -cephalosporins_2nd(only_rsi_columns = FALSE, ...) +cephalosporins_2nd(only_sir_columns = FALSE, ...) -cephalosporins_3rd(only_rsi_columns = FALSE, ...) +cephalosporins_3rd(only_sir_columns = FALSE, ...) -cephalosporins_4th(only_rsi_columns = FALSE, ...) +cephalosporins_4th(only_sir_columns = FALSE, ...) -cephalosporins_5th(only_rsi_columns = FALSE, ...) +cephalosporins_5th(only_sir_columns = FALSE, ...) -fluoroquinolones(only_rsi_columns = FALSE, ...) +fluoroquinolones(only_sir_columns = FALSE, ...) -glycopeptides(only_rsi_columns = FALSE, ...) +glycopeptides(only_sir_columns = FALSE, ...) -lincosamides(only_rsi_columns = FALSE, ...) +lincosamides(only_sir_columns = FALSE, ...) -lipoglycopeptides(only_rsi_columns = FALSE, ...) +lipoglycopeptides(only_sir_columns = FALSE, ...) -macrolides(only_rsi_columns = FALSE, ...) +macrolides(only_sir_columns = FALSE, ...) -oxazolidinones(only_rsi_columns = FALSE, ...) +oxazolidinones(only_sir_columns = FALSE, ...) -penicillins(only_rsi_columns = FALSE, ...) +penicillins(only_sir_columns = FALSE, ...) -polymyxins(only_rsi_columns = FALSE, only_treatable = TRUE, ...) +polymyxins(only_sir_columns = FALSE, only_treatable = TRUE, ...) -streptogramins(only_rsi_columns = FALSE, ...) +streptogramins(only_sir_columns = FALSE, ...) -quinolones(only_rsi_columns = FALSE, ...) +quinolones(only_sir_columns = FALSE, ...) -tetracyclines(only_rsi_columns = FALSE, ...) +tetracyclines(only_sir_columns = FALSE, ...) -trimethoprims(only_rsi_columns = FALSE, ...) +trimethoprims(only_sir_columns = FALSE, ...) -ureidopenicillins(only_rsi_columns = FALSE, ...) +ureidopenicillins(only_sir_columns = FALSE, ...) -administrable_per_os(only_rsi_columns = FALSE, ...) +administrable_per_os(only_sir_columns = FALSE, ...) -administrable_iv(only_rsi_columns = FALSE, ...) +administrable_iv(only_sir_columns = FALSE, ...) not_intrinsic_resistant( - only_rsi_columns = FALSE, + only_sir_columns = FALSE, col_mo = NULL, version_expertrules = 3.3, ... @@ -102,7 +102,7 @@ not_intrinsic_resistant( \arguments{ \item{ab_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.} -\item{only_rsi_columns}{a \link{logical} to indicate whether only columns of class \code{rsi} must be selected (defaults to \code{FALSE}), see \code{\link[=as.rsi]{as.rsi()}}} +\item{only_sir_columns}{a \link{logical} to indicate whether only columns of class \code{sir} must be selected (defaults to \code{FALSE}), see \code{\link[=as.sir]{as.sir()}}} \item{only_treatable}{a \link{logical} to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (defaults to \code{TRUE}), such as gentamicin-high (\code{GEH}) and imipenem/EDTA (\code{IPE})} @@ -166,7 +166,7 @@ The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function c \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/as.ab.Rd b/man/as.ab.Rd index 0e9462a58..2cce65e3b 100755 --- a/man/as.ab.Rd +++ b/man/as.ab.Rd @@ -62,7 +62,7 @@ The WHOCC is located in Oslo at the Norwegian Institute of Public Health and fun \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ @@ -92,9 +92,9 @@ ab_name("eryt") \donttest{ if (require("dplyr")) { - # you can quickly rename 'rsi' columns using set_ab_names() with dplyr: + # you can quickly rename 'sir' columns using set_ab_names() with dplyr: example_isolates \%>\% - set_ab_names(where(is.rsi), property = "atc") + set_ab_names(where(is.sir), property = "atc") } } } diff --git a/man/as.av.Rd b/man/as.av.Rd index 8a0967811..ad5cdeea1 100755 --- a/man/as.av.Rd +++ b/man/as.av.Rd @@ -60,7 +60,7 @@ The WHOCC is located in Oslo at the Norwegian Institute of Public Health and fun \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/as.disk.Rd b/man/as.disk.Rd index 848771f11..eddf10db9 100755 --- a/man/as.disk.Rd +++ b/man/as.disk.Rd @@ -29,7 +29,7 @@ An \link{integer} with additional class \code{\link{disk}} This transforms a vector to a new class \code{\link{disk}}, which is a disk diffusion growth zone size (around an antibiotic disk) in millimetres between 6 and 50. } \details{ -Interpret disk values as RSI values with \code{\link[=as.rsi]{as.rsi()}}. It supports guidelines from EUCAST and CLSI. +Interpret disk values as SIR values with \code{\link[=as.sir]{as.sir()}}. It supports guidelines from EUCAST and CLSI. Disk diffusion growth zone sizes must be between 6 and 50 millimetres. Values higher than 50 but lower than 100 will be maximised to 50. All others input values outside the 6-50 range will return \code{NA}. @@ -54,8 +54,8 @@ if (require("dplyr")) { } } -# interpret disk values, see ?as.rsi -as.rsi( +# interpret disk values, see ?as.sir +as.sir( x = as.disk(18), mo = "Strep pneu", # `mo` will be coerced with as.mo() ab = "ampicillin", # and `ab` with as.ab() @@ -63,9 +63,9 @@ as.rsi( ) # interpret whole data set, pretend to be all from urinary tract infections: -as.rsi(df, uti = TRUE) +as.sir(df, uti = TRUE) } \seealso{ -\code{\link[=as.rsi]{as.rsi()}} +\code{\link[=as.sir]{as.sir()}} } \keyword{datasets} diff --git a/man/as.mic.Rd b/man/as.mic.Rd index 390999ce1..d46347edf 100755 --- a/man/as.mic.Rd +++ b/man/as.mic.Rd @@ -33,7 +33,7 @@ Ordered \link{factor} with additional class \code{\link{mic}}, that in mathemati This transforms vectors to a new class \code{\link{mic}}, which treats the input as decimal numbers, while maintaining operators (such as ">=") and only allowing valid MIC values known to the field of (medical) microbiology. } \details{ -To interpret MIC values as RSI values, use \code{\link[=as.rsi]{as.rsi()}} on MIC values. It supports guidelines from EUCAST (2013-2022) and CLSI (2013-2022). +To interpret MIC values as SIR values, use \code{\link[=as.sir]{as.sir()}} on MIC values. It supports guidelines from EUCAST (2013-2022) and CLSI (2013-2022). This class for MIC values is a quite a special data type: formally it is an ordered \link{factor} with valid MIC values as \link{factor} levels (to make sure only valid MIC values are retained), but for any mathematical operation it acts as decimal numbers: @@ -82,7 +82,7 @@ mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16")) mic_data is.mic(mic_data) -# this can also coerce combined MIC/RSI values: +# this can also coerce combined MIC/SIR values: as.mic("<=0.002; S") # mathematical processing treats MICs as numeric values @@ -91,13 +91,13 @@ quantile(mic_data) all(mic_data < 512) # interpret MIC values -as.rsi( +as.sir( x = as.mic(2), mo = as.mo("Streptococcus pneumoniae"), ab = "AMX", guideline = "EUCAST" ) -as.rsi( +as.sir( x = as.mic(c(0.01, 2, 4, 8)), mo = as.mo("Streptococcus pneumoniae"), ab = "AMX", @@ -119,6 +119,6 @@ if (require("ggplot2")) { } } \seealso{ -\code{\link[=as.rsi]{as.rsi()}} +\code{\link[=as.sir]{as.sir()}} } \keyword{datasets} diff --git a/man/as.mo.Rd b/man/as.mo.Rd index cad7f4aba..88de3b72a 100755 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -167,7 +167,7 @@ All matches are sorted descending on their matching score and for all user input \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/as.rsi.Rd b/man/as.sir.Rd old mode 100755 new mode 100644 similarity index 61% rename from man/as.rsi.Rd rename to man/as.sir.Rd index c8cd5d6aa..517a69a7c --- a/man/as.rsi.Rd +++ b/man/as.sir.Rd @@ -1,19 +1,19 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rsi.R +% Please edit documentation in R/sir.R \docType{data} -\name{as.rsi} -\alias{as.rsi} -\alias{rsi} -\alias{NA_rsi_} -\alias{is.rsi} -\alias{is.rsi.eligible} -\alias{as.rsi.mic} -\alias{as.rsi.disk} -\alias{as.rsi.data.frame} -\alias{rsi_interpretation_history} -\title{Interpret MIC and Disk Values, or Clean Raw R/SI Data} +\name{as.sir} +\alias{as.sir} +\alias{sir} +\alias{NA_sir_} +\alias{is.sir} +\alias{is_sir_eligible} +\alias{as.sir.mic} +\alias{as.sir.disk} +\alias{as.sir.data.frame} +\alias{sir_interpretation_history} +\title{Translate MIC and Disk Diffusion to SIR, or Clean Existing SIR Data} \format{ -An object of class \code{rsi} (inherits from \code{ordered}, \code{factor}) of length 1. +An object of class \code{sir} (inherits from \code{ordered}, \code{factor}) of length 1. } \source{ For interpretations of minimum inhibitory concentration (MIC) values and disk diffusion diameters: @@ -24,15 +24,15 @@ For interpretations of minimum inhibitory concentration (MIC) values and disk di } } \usage{ -as.rsi(x, ...) +as.sir(x, ...) -NA_rsi_ +NA_sir_ -is.rsi(x) +is.sir(x) -is.rsi.eligible(x, threshold = 0.05) +is_sir_eligible(x, threshold = 0.05) -\method{as.rsi}{mic}( +\method{as.sir}{mic}( x, mo = NULL, ab = deparse(substitute(x)), @@ -40,22 +40,22 @@ is.rsi.eligible(x, threshold = 0.05) uti = NULL, conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation, + reference_data = AMR::clinical_breakpoints, ... ) -\method{as.rsi}{disk}( +\method{as.sir}{disk}( x, mo = NULL, ab = deparse(substitute(x)), guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation, + reference_data = AMR::clinical_breakpoints, ... ) -\method{as.rsi}{data.frame}( +\method{as.sir}{data.frame}( x, ..., col_mo = NULL, @@ -63,15 +63,15 @@ is.rsi.eligible(x, threshold = 0.05) uti = NULL, conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE, - reference_data = AMR::rsi_translation + reference_data = AMR::clinical_breakpoints ) -rsi_interpretation_history(clean = FALSE) +sir_interpretation_history(clean = FALSE) } \arguments{ \item{x}{vector of values (for class \code{\link{mic}}: MIC values in mg/L, for class \code{\link{disk}}: a disk diffusion radius in millimetres)} -\item{...}{for using on a \link{data.frame}: names of columns to apply \code{\link[=as.rsi]{as.rsi()}} on (supports tidy selection such as \code{column1:column4}). Otherwise: arguments passed on to methods.} +\item{...}{for using on a \link{data.frame}: names of columns to apply \code{\link[=as.sir]{as.sir()}} on (supports tidy selection such as \code{column1:column4}). Otherwise: arguments passed on to methods.} \item{threshold}{maximum fraction of invalid antimicrobial interpretations of \code{x}, see \emph{Examples}} @@ -79,53 +79,53 @@ rsi_interpretation_history(clean = FALSE) \item{ab}{any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}} -\item{guideline}{defaults to EUCAST 2022 (the latest implemented EUCAST guideline in the \link{rsi_translation} data set), but can be set with the \link[=options]{option} \code{AMR_guideline}. Supports EUCAST (2013-2022) and CLSI (2013-2022), see \emph{Details}.} +\item{guideline}{defaults to EUCAST 2022 (the latest implemented EUCAST guideline in the \link{clinical_breakpoints} data set), but can be set with the \link[=options]{option} \code{AMR_guideline}. Supports EUCAST (2013-2022) and CLSI (2013-2022), see \emph{Details}.} -\item{uti}{(Urinary Tract Infection) A vector with \link{logical}s (\code{TRUE} or \code{FALSE}) to specify whether a UTI specific interpretation from the guideline should be chosen. For using \code{\link[=as.rsi]{as.rsi()}} on a \link{data.frame}, this can also be a column containing \link{logical}s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See \emph{Examples}.} +\item{uti}{(Urinary Tract Infection) A vector with \link{logical}s (\code{TRUE} or \code{FALSE}) to specify whether a UTI specific interpretation from the guideline should be chosen. For using \code{\link[=as.sir]{as.sir()}} on a \link{data.frame}, this can also be a column containing \link{logical}s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See \emph{Examples}.} \item{conserve_capped_values}{a \link{logical} to indicate that MIC values starting with \code{">"} (but not \code{">="}) must always return "R" , and that MIC values starting with \code{"<"} (but not \code{"<="}) must always return "S"} \item{add_intrinsic_resistance}{\emph{(only useful when using a EUCAST guideline)} a \link{logical} to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in \emph{Klebsiella} species. Determination is based on the \link{intrinsic_resistant} data set, that itself is based on \href{https://www.eucast.org/expert_rules_and_expected_phenotypes/}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021).} -\item{reference_data}{a \link{data.frame} to be used for interpretation, which defaults to the \link{rsi_translation} data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the \link{rsi_translation} data set (same column names and column types). Please note that the \code{guideline} argument will be ignored when \code{reference_data} is manually set.} +\item{reference_data}{a \link{data.frame} to be used for interpretation, which defaults to the \link{clinical_breakpoints} data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the \link{clinical_breakpoints} data set (same column names and column types). Please note that the \code{guideline} argument will be ignored when \code{reference_data} is manually set.} \item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{clean}{a \link{logical} to indicate whether previously stored results should be forgotten after returning the 'logbook' with results} } \value{ -Ordered \link{factor} with new class \code{rsi} +Ordered \link{factor} with new class \code{sir} } \description{ -Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing R/SI values. This transforms the input to a new class \code{\link{rsi}}, which is an ordered \link{factor} with levels \verb{S < I < R}. +Interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI, or clean up existing SIR values. This transforms the input to a new class \code{\link{sir}}, which is an ordered \link{factor} with levels \verb{S < I < R}. } \details{ \subsection{How it Works}{ -The \code{\link[=as.rsi]{as.rsi()}} function works in four ways: +The \code{\link[=as.sir]{as.sir()}} function works in four ways: \enumerate{ -\item For \strong{cleaning raw / untransformed data}. The data will be cleaned to only contain values S, I and R and will try its best to determine this with some intelligence. For example, mixed values with R/SI interpretations and MIC values such as \code{"<0.25; S"} will be coerced to \code{"S"}. Combined interpretations for multiple test methods (as seen in laboratory records) such as \code{"S; S"} will be coerced to \code{"S"}, but a value like \code{"S; I"} will return \code{NA} with a warning that the input is unclear. +\item For \strong{cleaning raw / untransformed data}. The data will be cleaned to only contain values S, I and R and will try its best to determine this with some intelligence. For example, mixed values with SIR interpretations and MIC values such as \code{"<0.25; S"} will be coerced to \code{"S"}. Combined interpretations for multiple test methods (as seen in laboratory records) such as \code{"S; S"} will be coerced to \code{"S"}, but a value like \code{"S; I"} will return \code{NA} with a warning that the input is unclear. \item For \strong{interpreting minimum inhibitory concentration (MIC) values} according to EUCAST or CLSI. You must clean your MIC values first using \code{\link[=as.mic]{as.mic()}}, that also gives your columns the new data class \code{\link{mic}}. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the \code{mo} argument. \itemize{ -\item Using \code{dplyr}, R/SI interpretation can be done very easily with either: +\item Using \code{dplyr}, SIR interpretation can be done very easily with either: -\if{html}{\out{
}}\preformatted{your_data \%>\% mutate_if(is.mic, as.rsi) -your_data \%>\% mutate(across(where(is.mic), as.rsi)) +\if{html}{\out{
}}\preformatted{your_data \%>\% mutate_if(is.mic, as.sir) +your_data \%>\% mutate(across(where(is.mic), as.sir)) }\if{html}{\out{
}} \item Operators like "<=" will be stripped before interpretation. When using \code{conserve_capped_values = TRUE}, an MIC value of e.g. ">2" will always return "R", even if the breakpoint according to the chosen guideline is ">=4". This is to prevent that capped values from raw laboratory data would not be treated conservatively. The default behaviour (\code{conserve_capped_values = FALSE}) considers ">2" to be lower than ">=4" and might in this case return "S" or "I". } \item For \strong{interpreting disk diffusion diameters} according to EUCAST or CLSI. You must clean your disk zones first using \code{\link[=as.disk]{as.disk()}}, that also gives your columns the new data class \code{\link{disk}}. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the \code{mo} argument. \itemize{ -\item Using \code{dplyr}, R/SI interpretation can be done very easily with either: +\item Using \code{dplyr}, SIR interpretation can be done very easily with either: -\if{html}{\out{
}}\preformatted{your_data \%>\% mutate_if(is.disk, as.rsi) -your_data \%>\% mutate(across(where(is.disk), as.rsi)) +\if{html}{\out{
}}\preformatted{your_data \%>\% mutate_if(is.disk, as.sir) +your_data \%>\% mutate(across(where(is.disk), as.sir)) }\if{html}{\out{
}} } -\item For \strong{interpreting a complete data set}, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running \code{as.rsi(your_data)}. +\item For \strong{interpreting a complete data set}, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running \code{as.sir(your_data)}. } -For points 2, 3 and 4: Use \code{\link[=rsi_interpretation_history]{rsi_interpretation_history()}} to retrieve a \link{data.frame} (or \link[tibble:tibble]{tibble} if the \code{tibble} package is installed) with all results of the last \code{\link[=as.rsi]{as.rsi()}} call. +For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}} to retrieve a \link{data.frame} (or \link[tibble:tibble]{tibble} if the \code{tibble} package is installed) with all results of the last \code{\link[=as.sir]{as.sir()}} call. } \subsection{Supported Guidelines}{ @@ -146,33 +146,36 @@ You can set the default guideline with the \code{AMR_guideline} \link[=options]{ \subsection{After Interpretation}{ -After using \code{\link[=as.rsi]{as.rsi()}}, you can use the \code{\link[=eucast_rules]{eucast_rules()}} defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism. +After using \code{\link[=as.sir]{as.sir()}}, you can use the \code{\link[=eucast_rules]{eucast_rules()}} defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism. } \subsection{Machine-Readable Interpretation Guidelines}{ -The repository of this package \href{https://github.com/msberends/AMR/blob/main/data-raw/rsi_translation.txt}{contains a machine-readable version} of all guidelines. This is a CSV file consisting of 18,308 rows and 11 columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial drug and the microorganism. \strong{This allows for easy implementation of these rules in laboratory information systems (LIS)}. Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed. +The repository of this package \href{https://github.com/msberends/AMR/blob/main/data-raw/clinical_breakpoints.txt}{contains a machine-readable version} of all guidelines. This is a CSV file consisting of 18,308 rows and 11 columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial drug and the microorganism. \strong{This allows for easy implementation of these rules in laboratory information systems (LIS)}. Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed. } \subsection{Other}{ -The function \code{\link[=is.rsi]{is.rsi()}} detects if the input contains class \code{rsi}. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector. +The function \code{\link[=is.sir]{is.sir()}} detects if the input contains class \code{sir}. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector. -The function \code{\link[=is.rsi.eligible]{is.rsi.eligible()}} returns \code{TRUE} when a columns contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} argument. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector. +The function \code{\link[=is_sir_eligible]{is_sir_eligible()}} returns \code{TRUE} when a columns contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} argument. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector. } -\code{NA_rsi_} is a missing value of the new \code{rsi} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}. +\code{NA_sir_} is a missing value of the new \code{sir} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}. } -\section{Interpretation of R and S/I}{ +\section{Interpretation of SIR}{ -In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (\url{https://www.eucast.org/newsiandr/}). +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr/}): \itemize{ +\item \strong{S - Susceptible, standard dosing regimen}\cr +A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +\item \strong{I - Susceptible, increased exposure} \emph{\cr +A microorganism is categorised as "Susceptible, Increased exposure}" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. \item \strong{R = Resistant}\cr -A microorganism is categorised as \emph{Resistant} when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -\item \strong{S = Susceptible}\cr -A microorganism is categorised as \emph{Susceptible, standard dosing regimen}, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -\item \strong{I = Susceptible, Increased exposure}\cr -A microorganism is categorised as \emph{Susceptible, Increased exposure} when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +\itemize{ +\item \emph{Exposure} is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. +} } This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates. @@ -180,12 +183,12 @@ This AMR package honours this insight. Use \code{\link[=susceptibility]{suscepti \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ example_isolates -summary(example_isolates) # see all R/SI results at a glance +summary(example_isolates) # see all SIR results at a glance # For INTERPRETING disk diffusion and MIC values ----------------------- @@ -198,20 +201,20 @@ df <- data.frame( TOB = as.disk(16), ERY = "R" ) -as.rsi(df) +as.sir(df) # return a 'logbook' about the results: -rsi_interpretation_history() +sir_interpretation_history() # for single values -as.rsi( +as.sir( x = as.mic(2), mo = as.mo("S. pneumoniae"), ab = "AMP", guideline = "EUCAST" ) -as.rsi( +as.sir( x = as.disk(18), mo = "Strep pneu", # `mo` will be coerced with as.mo() ab = "ampicillin", # and `ab` with as.ab() @@ -221,14 +224,14 @@ as.rsi( \donttest{ # the dplyr way if (require("dplyr")) { - df \%>\% mutate_if(is.mic, as.rsi) - df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.rsi) - df \%>\% mutate(across(where(is.mic), as.rsi)) - df \%>\% mutate_at(vars(AMP:TOB), as.rsi) - df \%>\% mutate(across(AMP:TOB, as.rsi)) + df \%>\% mutate_if(is.mic, as.sir) + df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.sir) + df \%>\% mutate(across(where(is.mic), as.sir)) + df \%>\% mutate_at(vars(AMP:TOB), as.sir) + df \%>\% mutate(across(AMP:TOB, as.sir)) df \%>\% - mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism) + mutate_at(vars(AMP:TOB), as.sir, mo = .$microorganism) # to include information about urinary tract infections (UTI) data.frame( @@ -236,43 +239,43 @@ if (require("dplyr")) { NIT = c("<= 2", 32), from_the_bladder = c(TRUE, FALSE) ) \%>\% - as.rsi(uti = "from_the_bladder") + as.sir(uti = "from_the_bladder") data.frame( mo = "E. coli", NIT = c("<= 2", 32), specimen = c("urine", "blood") ) \%>\% - as.rsi() # automatically determines urine isolates + as.sir() # automatically determines urine isolates df \%>\% - mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli", uti = TRUE) + mutate_at(vars(AMP:TOB), as.sir, mo = "E. coli", uti = TRUE) } -# For CLEANING existing R/SI values ------------------------------------ +# For CLEANING existing SIR values ------------------------------------ -as.rsi(c("S", "I", "R", "A", "B", "C")) -as.rsi("<= 0.002; S") # will return "S" -rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370))) -is.rsi(rsi_data) -plot(rsi_data) # for percentages -barplot(rsi_data) # for frequencies +as.sir(c("S", "I", "R", "A", "B", "C")) +as.sir("<= 0.002; S") # will return "S" +sir_data <- as.sir(c(rep("S", 474), rep("I", 36), rep("R", 370))) +is.sir(sir_data) +plot(sir_data) # for percentages +barplot(sir_data) # for frequencies # the dplyr way if (require("dplyr")) { example_isolates \%>\% - mutate_at(vars(PEN:RIF), as.rsi) + mutate_at(vars(PEN:RIF), as.sir) # same: example_isolates \%>\% - as.rsi(PEN:RIF) + as.sir(PEN:RIF) - # fastest way to transform all columns with already valid AMR results to class `rsi`: + # fastest way to transform all columns with already valid AMR results to class `sir`: example_isolates \%>\% - mutate_if(is.rsi.eligible, as.rsi) + mutate_if(is_sir_eligible, as.sir) # since dplyr 1.0.0, this can also be: # example_isolates \%>\% - # mutate(across(where(is.rsi.eligible), as.rsi)) + # mutate(across(where(is_sir_eligible), as.sir)) } } } diff --git a/man/av_property.Rd b/man/av_property.Rd index 0874891c9..a8cb9e842 100755 --- a/man/av_property.Rd +++ b/man/av_property.Rd @@ -79,7 +79,7 @@ European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{htt \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/availability.Rd b/man/availability.Rd index 1da7df380..c4fe6dd7b 100755 --- a/man/availability.Rd +++ b/man/availability.Rd @@ -26,7 +26,7 @@ availability(example_isolates) if (require("dplyr")) { example_isolates \%>\% filter(mo == as.mo("Escherichia coli")) \%>\% - select_if(is.rsi) \%>\% + select_if(is.sir) \%>\% availability() } } diff --git a/man/rsi_translation.Rd b/man/clinical_breakpoints.Rd old mode 100755 new mode 100644 similarity index 79% rename from man/rsi_translation.Rd rename to man/clinical_breakpoints.Rd index 62917d5ce..63c800457 --- a/man/rsi_translation.Rd +++ b/man/clinical_breakpoints.Rd @@ -1,9 +1,9 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.R \docType{data} -\name{rsi_translation} -\alias{rsi_translation} -\title{Data Set for R/SI Interpretation} +\name{clinical_breakpoints} +\alias{clinical_breakpoints} +\title{Data Set with Clinical Breakpoints for SIR Interpretation} \format{ A \link[tibble:tibble]{tibble} with 18,308 observations and 11 variables: \itemize{ @@ -21,10 +21,10 @@ A \link[tibble:tibble]{tibble} with 18,308 observations and 11 variables: } } \usage{ -rsi_translation +clinical_breakpoints } \description{ -Data set containing reference data to interpret MIC and disk diffusion to R/SI values, according to international guidelines. Currently implemented guidelines are EUCAST (2013-2022) and CLSI (2013-2022). Use \code{\link[=as.rsi]{as.rsi()}} to transform MICs or disks measurements to R/SI values. +Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. Currently implemented guidelines are EUCAST (2013-2022) and CLSI (2013-2022). Use \code{\link[=as.sir]{as.sir()}} to transform MICs or disks measurements to SIR values. } \details{ Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. @@ -32,7 +32,7 @@ Like all data sets in this package, this data set is publicly available for down They \strong{allow for machine reading EUCAST and CLSI guidelines}, which is almost impossible with the MS Excel and PDF files distributed by EUCAST and CLSI. } \examples{ -rsi_translation +clinical_breakpoints } \seealso{ \link{intrinsic_resistant} diff --git a/man/count.Rd b/man/count.Rd index 2abc9344d..e2ca5c774 100755 --- a/man/count.Rd +++ b/man/count.Rd @@ -10,7 +10,7 @@ \alias{count_SI} \alias{count_S} \alias{count_all} -\alias{n_rsi} +\alias{n_sir} \alias{count_df} \title{Count Available Isolates} \usage{ @@ -30,7 +30,7 @@ count_S(..., only_all_tested = FALSE) count_all(..., only_all_tested = FALSE) -n_rsi(..., only_all_tested = FALSE) +n_sir(..., only_all_tested = FALSE) count_df( data, @@ -40,11 +40,11 @@ count_df( ) } \arguments{ -\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.rsi]{as.rsi()}} if needed.} +\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.sir]{as.sir()}} if needed.} \item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antibiotics, see section \emph{Combination Therapy} below} -\item{data}{a \link{data.frame} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})} +\item{data}{a \link{data.frame} containing columns with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})} \item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}} @@ -65,20 +65,23 @@ These functions are meant to count isolates. Use the \code{\link[=resistance]{re The function \code{\link[=count_resistant]{count_resistant()}} is equal to the function \code{\link[=count_R]{count_R()}}. The function \code{\link[=count_susceptible]{count_susceptible()}} is equal to the function \code{\link[=count_SI]{count_SI()}}. -The function \code{\link[=n_rsi]{n_rsi()}} is an alias of \code{\link[=count_all]{count_all()}}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{n_distinct()}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}. +The function \code{\link[=n_sir]{n_sir()}} is an alias of \code{\link[=count_all]{count_all()}}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{n_distinct()}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}. -The function \code{\link[=count_df]{count_df()}} takes any variable from \code{data} that has an \code{\link{rsi}} class (created with \code{\link[=as.rsi]{as.rsi()}}) and counts the number of S's, I's and R's. It also supports grouped variables. The function \code{\link[=rsi_df]{rsi_df()}} works exactly like \code{\link[=count_df]{count_df()}}, but adds the percentage of S, I and R. +The function \code{\link[=count_df]{count_df()}} takes any variable from \code{data} that has an \code{\link{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) and counts the number of S's, I's and R's. It also supports grouped variables. The function \code{\link[=sir_df]{sir_df()}} works exactly like \code{\link[=count_df]{count_df()}}, but adds the percentage of S, I and R. } -\section{Interpretation of R and S/I}{ +\section{Interpretation of SIR}{ -In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (\url{https://www.eucast.org/newsiandr/}). +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr/}): \itemize{ +\item \strong{S - Susceptible, standard dosing regimen}\cr +A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +\item \strong{I - Susceptible, increased exposure} \emph{\cr +A microorganism is categorised as "Susceptible, Increased exposure}" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. \item \strong{R = Resistant}\cr -A microorganism is categorised as \emph{Resistant} when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -\item \strong{S = Susceptible}\cr -A microorganism is categorised as \emph{Susceptible, standard dosing regimen}, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -\item \strong{I = Susceptible, Increased exposure}\cr -A microorganism is categorised as \emph{Susceptible, Increased exposure} when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +\itemize{ +\item \emph{Exposure} is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. +} } This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates. @@ -139,14 +142,14 @@ count_R(example_isolates$AMX) # Count all available isolates count_all(example_isolates$AMX) -n_rsi(example_isolates$AMX) +n_sir(example_isolates$AMX) -# n_rsi() is an alias of count_all(). +# n_sir() is an alias of count_all(). # Since it counts all available isolates, you can # calculate back to count e.g. susceptible isolates. # These results are the same: count_susceptible(example_isolates$AMX) -susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX) +susceptibility(example_isolates$AMX) * n_sir(example_isolates$AMX) # dplyr ------------------------------------------------------------- \donttest{ @@ -158,7 +161,7 @@ if (require("dplyr")) { I = count_I(CIP), S = count_S(CIP), n1 = count_all(CIP), # the actual total; sum of all three - n2 = n_rsi(CIP), # same - analogous to n_distinct + n2 = n_sir(CIP), # same - analogous to n_distinct total = n() ) # NOT the number of tested isolates! @@ -166,7 +169,7 @@ if (require("dplyr")) { # (i.e., in this data set columns GEN, TOB, AMK, KAN) example_isolates \%>\% group_by(ward) \%>\% - summarise(across(aminoglycosides(), n_rsi)) + summarise(across(aminoglycosides(), n_sir)) # Count co-resistance between amoxicillin/clav acid and gentamicin, # so we can see that combination therapy does a lot more than mono therapy. diff --git a/man/custom_eucast_rules.Rd b/man/custom_eucast_rules.Rd index 55d425033..cb989bbed 100755 --- a/man/custom_eucast_rules.Rd +++ b/man/custom_eucast_rules.Rd @@ -43,9 +43,9 @@ These are two custom EUCAST rules: if TZP (piperacillin/tazobactam) is "S", all The rules (the part \emph{before} the tilde, in above example \code{TZP == "S"} and \code{TZP == "R"}) must be evaluable in your data set: it should be able to run as a filter in your data set without errors. This means for the above example that the column \code{TZP} must exist. We will create a sample data set and test the rules set: \if{html}{\out{
}}\preformatted{df <- data.frame(mo = c("Escherichia coli", "Klebsiella pneumoniae"), - TZP = as.rsi("R"), - ampi = as.rsi("S"), - cipro = as.rsi("S")) + TZP = as.sir("R"), + ampi = as.sir("S"), + cipro = as.sir("S")) df #> mo TZP ampi cipro #> 1 Escherichia coli R S S diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd index eae346a2d..5880b55ae 100755 --- a/man/eucast_rules.Rd +++ b/man/eucast_rules.Rd @@ -28,7 +28,7 @@ eucast_rules( version_breakpoints = 12, version_expertrules = 3.3, ampc_cephalosporin_resistance = NA, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, custom_rules = NULL, ... ) @@ -52,7 +52,7 @@ eucast_dosage(ab, administration = "iv", version_breakpoints = 12) \item{ampc_cephalosporin_resistance}{a \link{character} value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants, defaults to \code{NA}. Currently only works when \code{version_expertrules} is \code{3.2} and higher; these version of '\emph{EUCAST Expert Rules on Enterobacterales}' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of \code{NA} (the default) for this argument will remove results for these three drugs, while e.g. a value of \code{"R"} will make the results for these drugs resistant. Use \code{NULL} or \code{FALSE} to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using \code{TRUE} is equal to using \code{"R"}. \cr For \emph{EUCAST Expert Rules} v3.2, this rule applies to: \emph{Citrobacter braakii}, \emph{Citrobacter freundii}, \emph{Citrobacter gillenii}, \emph{Citrobacter murliniae}, \emph{Citrobacter rodenticum}, \emph{Citrobacter sedlakii}, \emph{Citrobacter werkmanii}, \emph{Citrobacter youngae}, \emph{Enterobacter}, \emph{Hafnia alvei}, \emph{Klebsiella aerogenes}, \emph{Morganella morganii}, \emph{Providencia} and \emph{Serratia}.} -\item{only_rsi_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{rsi} (see \code{\link[=as.rsi]{as.rsi()}}) on beforehand (defaults to \code{FALSE})} +\item{only_sir_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{sir} (see \code{\link[=as.sir]{as.sir()}}) on beforehand (defaults to \code{FALSE})} \item{custom_rules}{custom rules to apply, created with \code{\link[=custom_eucast_rules]{custom_eucast_rules()}}} @@ -71,7 +71,7 @@ Apply rules for clinical breakpoints and intrinsic resistance as defined by the To improve the interpretation of the antibiogram before EUCAST rules are applied, some non-EUCAST rules can applied at default, see \emph{Details}. } \details{ -\strong{Note:} This function does not translate MIC values to RSI values. Use \code{\link[=as.rsi]{as.rsi()}} for that. \cr +\strong{Note:} This function does not translate MIC values to SIR values. Use \code{\link[=as.sir]{as.sir()}} for that. \cr \strong{Note:} When ampicillin (AMP, J01CA01) is not available but amoxicillin (AMX, J01CA04) is, the latter will be used for all rules where there is a dependency on ampicillin. These drugs are interchangeable when it comes to expression of antimicrobial resistance. \cr The file containing all EUCAST rules is located here: \url{https://github.com/msberends/AMR/blob/main/data-raw/eucast_rules.tsv}. \strong{Note:} Old taxonomic names are replaced with the current taxonomy where applicable. For example, \emph{Ochrobactrum anthropi} was renamed to \emph{Brucella anthropi} in 2020; the original EUCAST rules v3.1 and v3.2 did not yet contain this new taxonomic name. The \code{AMR} package contains the full microbial taxonomy updated until 11 December, 2022, see \link{microorganisms}. @@ -110,7 +110,7 @@ Amikacin (\code{AMK}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB06&sho \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/example_isolates.Rd b/man/example_isolates.Rd index 34f0d87c2..4e6e59b9f 100755 --- a/man/example_isolates.Rd +++ b/man/example_isolates.Rd @@ -13,7 +13,7 @@ A \link[tibble:tibble]{tibble} with 2,000 observations and 46 variables: \item \code{gender}\cr Gender of the patient, either "F" or "M" \item \code{ward}\cr Ward type where the patient was admitted, either "Clinical", "ICU" or "Outpatient" \item \code{mo}\cr ID of microorganism created with \code{\link[=as.mo]{as.mo()}}, see also the \link{microorganisms} data set -\item \code{PEN:RIF}\cr 40 different antibiotics with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}}); these column names occur in the \link{antibiotics} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}} +\item \code{PEN:RIF}\cr 40 different antibiotics with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}); these column names occur in the \link{antibiotics} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}} } } \usage{ diff --git a/man/example_isolates_unclean.Rd b/man/example_isolates_unclean.Rd index aa620b9b6..0c0b24775 100755 --- a/man/example_isolates_unclean.Rd +++ b/man/example_isolates_unclean.Rd @@ -11,7 +11,7 @@ A \link[tibble:tibble]{tibble} with 3,000 observations and 8 variables: \item \code{date}\cr date of receipt at the laboratory \item \code{hospital}\cr ID of the hospital, from A to C \item \code{bacteria}\cr info about microorganism that can be transformed with \code{\link[=as.mo]{as.mo()}}, see also \link{microorganisms} -\item \code{AMX:GEN}\cr 4 different antibiotics that have to be transformed with \code{\link[=as.rsi]{as.rsi()}} +\item \code{AMX:GEN}\cr 4 different antibiotics that have to be transformed with \code{\link[=as.sir]{as.sir()}} } } \usage{ diff --git a/man/first_isolate.Rd b/man/first_isolate.Rd index 607d6b78b..d8eb9e036 100755 --- a/man/first_isolate.Rd +++ b/man/first_isolate.Rd @@ -31,7 +31,7 @@ first_isolate( points_threshold = 2, info = interactive(), include_unknown = FALSE, - include_untested_rsi = TRUE, + include_untested_sir = TRUE, ... ) @@ -82,7 +82,7 @@ filter_first_isolate( \item{include_unknown}{a \link{logical} to indicate whether 'unknown' microorganisms should be included too, i.e. microbial code \code{"UNKNOWN"}, which defaults to \code{FALSE}. For WHONET users, this means that all records with organism code \code{"con"} (\emph{contamination}) will be excluded at default. Isolates with a microbial ID of \code{NA} will always be excluded as first isolate.} -\item{include_untested_rsi}{a \link{logical} to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use \code{include_untested_rsi = FALSE} to always return \code{FALSE} for such rows. This checks the data set for columns of class \code{rsi} and consequently requires transforming columns with antibiotic results using \code{\link[=as.rsi]{as.rsi()}} first.} +\item{include_untested_sir}{a \link{logical} to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use \code{include_untested_sir = FALSE} to always return \code{FALSE} for such rows. This checks the data set for columns of class \code{sir} and consequently requires transforming columns with antibiotic results using \code{\link[=as.sir]{as.sir()}} first.} \item{...}{arguments passed on to \code{\link[=first_isolate]{first_isolate()}} when using \code{\link[=filter_first_isolate]{filter_first_isolate()}}, otherwise arguments passed on to \code{\link[=key_antimicrobials]{key_antimicrobials()}} (such as \code{universal}, \code{gram_negative}, \code{gram_positive})} } diff --git a/man/ggplot_pca.Rd b/man/ggplot_pca.Rd index c1adbb299..3693bc07f 100755 --- a/man/ggplot_pca.Rd +++ b/man/ggplot_pca.Rd @@ -121,7 +121,7 @@ if (require("dplyr")) { genus = mo_genus(mo) ) \%>\% # and genus as we do here; filter(n() >= 30) \%>\% # filter on only 30 results per group - summarise_if(is.rsi, resistance) # then get resistance of all drugs + summarise_if(is.sir, resistance) # then get resistance of all drugs # now conduct PCA for certain antimicrobial drugs pca_result <- resistance_data \%>\% diff --git a/man/ggplot_rsi.Rd b/man/ggplot_sir.Rd old mode 100755 new mode 100644 similarity index 81% rename from man/ggplot_rsi.Rd rename to man/ggplot_sir.Rd index 2032f78fa..98bd36651 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_sir.Rd @@ -1,16 +1,16 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ggplot_rsi.R -\name{ggplot_rsi} -\alias{ggplot_rsi} -\alias{geom_rsi} -\alias{facet_rsi} +% Please edit documentation in R/ggplot_sir.R +\name{ggplot_sir} +\alias{ggplot_sir} +\alias{geom_sir} +\alias{facet_sir} \alias{scale_y_percent} -\alias{scale_rsi_colours} -\alias{theme_rsi} -\alias{labels_rsi_count} +\alias{scale_sir_colours} +\alias{theme_sir} +\alias{labels_sir_count} \title{AMR Plots with \code{ggplot2}} \usage{ -ggplot_rsi( +ggplot_sir( data, position = NULL, x = "antibiotic", @@ -36,7 +36,7 @@ ggplot_rsi( ... ) -geom_rsi( +geom_sir( position = NULL, x = c("antibiotic", "interpretation"), fill = "interpretation", @@ -47,15 +47,15 @@ geom_rsi( ... ) -facet_rsi(facet = c("interpretation", "antibiotic"), nrow = NULL) +facet_sir(facet = c("interpretation", "antibiotic"), nrow = NULL) scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL) -scale_rsi_colours(..., aesthetics = "fill") +scale_sir_colours(..., aesthetics = "fill") -theme_rsi() +theme_sir() -labels_rsi_count( +labels_sir_count( position = NULL, x = "antibiotic", translate_ab = "name", @@ -67,7 +67,7 @@ labels_rsi_count( ) } \arguments{ -\item{data}{a \link{data.frame} with column(s) of class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})} +\item{data}{a \link{data.frame} with column(s) of class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})} \item{position}{position adjustment of bars, either \code{"fill"}, \code{"stack"} or \code{"dodge"}} @@ -93,7 +93,7 @@ labels_rsi_count( \item{colours}{a named vactor with colour to be used for filling. The default colours are colour-blind friendly.} -\item{datalabels}{show datalabels using \code{\link[=labels_rsi_count]{labels_rsi_count()}}} +\item{datalabels}{show datalabels using \code{\link[=labels_sir_count]{labels_sir_count()}}} \item{datalabels.size}{size of the datalabels} @@ -109,7 +109,7 @@ labels_rsi_count( \item{y.title}{text to show as y axis description} -\item{...}{other arguments passed on to \code{\link[=geom_rsi]{geom_rsi()}} or, in case of \code{\link[=scale_rsi_colours]{scale_rsi_colours()}}, named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See \emph{Examples}.} +\item{...}{other arguments passed on to \code{\link[=geom_sir]{geom_sir()}} or, in case of \code{\link[=scale_sir_colours]{scale_sir_colours()}}, named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See \emph{Examples}.} \item{aesthetics}{aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size"} } @@ -120,19 +120,19 @@ Use these functions to create bar plots for AMR data analysis. All functions rel At default, the names of antibiotics will be shown on the plots using \code{\link[=ab_name]{ab_name()}}. This can be set with the \code{translate_ab} argument. See \code{\link[=count_df]{count_df()}}. \subsection{The Functions}{ -\code{\link[=geom_rsi]{geom_rsi()}} will take any variable from the data that has an \code{\link{rsi}} class (created with \code{\link[=as.rsi]{as.rsi()}}) using \code{\link[=rsi_df]{rsi_df()}} and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis. +\code{\link[=geom_sir]{geom_sir()}} will take any variable from the data that has an \code{\link{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) using \code{\link[=sir_df]{sir_df()}} and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis. -\code{\link[=facet_rsi]{facet_rsi()}} creates 2d plots (at default based on S/I/R) using \code{\link[ggplot2:facet_wrap]{ggplot2::facet_wrap()}}. +\code{\link[=facet_sir]{facet_sir()}} creates 2d plots (at default based on S/I/R) using \code{\link[ggplot2:facet_wrap]{ggplot2::facet_wrap()}}. \code{\link[=scale_y_percent]{scale_y_percent()}} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2:scale_continuous]{ggplot2::scale_y_continuous()}}. -\code{\link[=scale_rsi_colours]{scale_rsi_colours()}} sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. +\code{\link[=scale_sir_colours]{scale_sir_colours()}} sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. -\code{\link[=theme_rsi]{theme_rsi()}} is a [ggplot2 theme][\code{\link[ggplot2:theme]{ggplot2::theme()}} with minimal distraction. +\code{\link[=theme_sir]{theme_sir()}} is a [ggplot2 theme][\code{\link[ggplot2:theme]{ggplot2::theme()}} with minimal distraction. -\code{\link[=labels_rsi_count]{labels_rsi_count()}} print datalabels on the bars with percentage and amount of isolates using \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}. +\code{\link[=labels_sir_count]{labels_sir_count()}} print datalabels on the bars with percentage and amount of isolates using \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}. -\code{\link[=ggplot_rsi]{ggplot_rsi()}} is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (\verb{\%>\%}). See \emph{Examples}. +\code{\link[=ggplot_sir]{ggplot_sir()}} is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (\verb{\%>\%}). See \emph{Examples}. } } \examples{ @@ -141,39 +141,39 @@ if (require("ggplot2") && require("dplyr")) { # get antimicrobial results for drugs against a UTI: ggplot(example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP)) + - geom_rsi() + geom_sir() } if (require("ggplot2") && require("dplyr")) { # prettify the plot using some additional functions: df <- example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP) ggplot(df) + - geom_rsi() + + geom_sir() + scale_y_percent() + - scale_rsi_colours() + - labels_rsi_count() + - theme_rsi() + scale_sir_colours() + + labels_sir_count() + + theme_sir() } if (require("ggplot2") && require("dplyr")) { # or better yet, simplify this using the wrapper function - a single command: example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP) \%>\% - ggplot_rsi() + ggplot_sir() } if (require("ggplot2") && require("dplyr")) { # get only proportions and no counts: example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP) \%>\% - ggplot_rsi(datalabels = FALSE) + ggplot_sir(datalabels = FALSE) } if (require("ggplot2") && require("dplyr")) { # add other ggplot2 arguments as you like: example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP) \%>\% - ggplot_rsi( + ggplot_sir( width = 0.5, colour = "black", size = 1, @@ -186,7 +186,7 @@ if (require("ggplot2") && require("dplyr")) { # you can alter the colours with colour names: example_isolates \%>\% select(AMX) \%>\% - ggplot_rsi(colours = c(SI = "yellow")) + ggplot_sir(colours = c(SI = "yellow")) } if (require("ggplot2") && require("dplyr")) { @@ -199,7 +199,7 @@ if (require("ggplot2") && require("dplyr")) { ) \%>\% ggplot() + geom_col(aes(x = x, y = y, fill = z)) + - scale_rsi_colours(Value4 = "S", Value5 = "I", Value6 = "R") + scale_sir_colours(Value4 = "S", Value5 = "I", Value6 = "R") } if (require("ggplot2") && require("dplyr")) { @@ -213,14 +213,14 @@ if (require("ggplot2") && require("dplyr")) { # age_groups() is also a function in this AMR package: group_by(age_group = age_groups(age)) \%>\% select(age_group, CIP) \%>\% - ggplot_rsi(x = "age_group") + ggplot_sir(x = "age_group") } if (require("ggplot2") && require("dplyr")) { # a shorter version which also adjusts data label colours: example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP) \%>\% - ggplot_rsi(colours = FALSE) + ggplot_sir(colours = FALSE) } if (require("ggplot2") && require("dplyr")) { @@ -230,7 +230,7 @@ if (require("ggplot2") && require("dplyr")) { # select only UTI-specific drugs select(ward, AMX, NIT, FOS, TMP, CIP) \%>\% group_by(ward) \%>\% - ggplot_rsi( + ggplot_sir( x = "ward", facet = "antibiotic", nrow = 1, diff --git a/man/guess_ab_col.Rd b/man/guess_ab_col.Rd index c411d669f..4ce4e4b89 100755 --- a/man/guess_ab_col.Rd +++ b/man/guess_ab_col.Rd @@ -8,7 +8,7 @@ guess_ab_col( x = NULL, search_string = NULL, verbose = FALSE, - only_rsi_columns = FALSE + only_sir_columns = FALSE ) } \arguments{ @@ -18,7 +18,7 @@ guess_ab_col( \item{verbose}{a \link{logical} to indicate whether additional info should be printed} -\item{only_rsi_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{rsi} (see \code{\link[=as.rsi]{as.rsi()}}) on beforehand (defaults to \code{FALSE})} +\item{only_sir_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{sir} (see \code{\link[=as.sir]{as.sir()}}) on beforehand (defaults to \code{FALSE})} } \value{ A column name of \code{x}, or \code{NULL} when no result is found. diff --git a/man/key_antimicrobials.Rd b/man/key_antimicrobials.Rd index 200a26da7..2fe3c999c 100755 --- a/man/key_antimicrobials.Rd +++ b/man/key_antimicrobials.Rd @@ -17,11 +17,11 @@ key_antimicrobials( "oxacillin", "rifampin"), antifungal = c("anidulafungin", "caspofungin", "fluconazole", "miconazole", "nystatin", "voriconazole"), - only_rsi_columns = FALSE, + only_sir_columns = FALSE, ... ) -all_antimicrobials(x = NULL, only_rsi_columns = FALSE, ...) +all_antimicrobials(x = NULL, only_sir_columns = FALSE, ...) antimicrobials_equal( y, @@ -45,7 +45,7 @@ antimicrobials_equal( \item{antifungal}{names of antifungal drugs for \strong{fungi}, case-insensitive. Set to \code{NULL} to ignore. See \emph{Details} for the default antifungal drugs} -\item{only_rsi_columns}{a \link{logical} to indicate whether only columns must be included that were transformed to class \code{rsi} (see \code{\link[=as.rsi]{as.rsi()}}) on beforehand (defaults to \code{FALSE})} +\item{only_sir_columns}{a \link{logical} to indicate whether only columns must be included that were transformed to class \code{sir} (see \code{\link[=as.sir]{as.sir()}}) on beforehand (defaults to \code{FALSE})} \item{...}{ignored, only in place to allow future extensions} diff --git a/man/mdro.Rd b/man/mdro.Rd index e8434df28..ce8623104 100755 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -27,21 +27,21 @@ mdro( pct_required_classes = 0.5, combine_SI = TRUE, verbose = FALSE, - only_rsi_columns = FALSE, + only_sir_columns = FALSE, ... ) custom_mdro_guideline(..., as_factor = TRUE) -brmo(x = NULL, only_rsi_columns = FALSE, ...) +brmo(x = NULL, only_sir_columns = FALSE, ...) -mrgn(x = NULL, only_rsi_columns = FALSE, ...) +mrgn(x = NULL, only_sir_columns = FALSE, ...) -mdr_tb(x = NULL, only_rsi_columns = FALSE, ...) +mdr_tb(x = NULL, only_sir_columns = FALSE, ...) -mdr_cmi2012(x = NULL, only_rsi_columns = FALSE, ...) +mdr_cmi2012(x = NULL, only_sir_columns = FALSE, ...) -eucast_exceptional_phenotypes(x = NULL, only_rsi_columns = FALSE, ...) +eucast_exceptional_phenotypes(x = NULL, only_sir_columns = FALSE, ...) } \arguments{ \item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank for automatic determination.} @@ -58,7 +58,7 @@ eucast_exceptional_phenotypes(x = NULL, only_rsi_columns = FALSE, ...) \item{verbose}{a \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.} -\item{only_rsi_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{rsi} (see \code{\link[=as.rsi]{as.rsi()}}) on beforehand (defaults to \code{FALSE})} +\item{only_sir_columns}{a \link{logical} to indicate whether only antibiotic columns must be detected that were transformed to class \code{sir} (see \code{\link[=as.sir]{as.sir()}}) on beforehand (defaults to \code{FALSE})} \item{...}{in case of \code{\link[=custom_mdro_guideline]{custom_mdro_guideline()}}: a set of rules, see section \emph{Using Custom Guidelines} below. Otherwise: column name of an antibiotic, see section \emph{Antibiotics} below.} @@ -172,16 +172,19 @@ The following antibiotics are eligible for the functions \code{\link[=eucast_rul Amikacin (\code{AMK}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB06&showdescription=no}{S01AE08}), amoxicillin (\code{AMX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA04&showdescription=no}{J01MA02}), amoxicillin/clavulanic acid (\code{AMC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CR02&showdescription=no}{J01MA23}), ampicillin (\code{AMP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA01&showdescription=no}{J01MA04}), ampicillin/sulbactam (\code{SAM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CR01&showdescription=no}{J01MA08}), arbekacin (\code{ARB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB12&showdescription=no}{J01MA19}), aspoxicillin (\code{APX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA19&showdescription=no}{J01MA16}), azidocillin (\code{AZD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE04&showdescription=no}{J01MA15}), azithromycin (\code{AZM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA10&showdescription=no}{J01MA11}), azlocillin (\code{AZL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA09&showdescription=no}{J01MA25}), aztreonam (\code{ATM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DF01&showdescription=no}{J01MA12}), bacampicillin (\code{BAM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA06&showdescription=no}{J01MA24}), bekanamycin (\code{BEK}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB13&showdescription=no}{J01MA07}), benzathine benzylpenicillin (\code{BNB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE08&showdescription=no}{J01MA14}), benzathine phenoxymethylpenicillin (\code{BNP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE10&showdescription=no}{D10AF05}), benzylpenicillin (\code{PEN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE01&showdescription=no}{J01MA06}), besifloxacin (\code{BES}, \href{https://www.whocc.no/atc_ddd_index/?code=S01AE08&showdescription=no}{J01MA01}), biapenem (\code{BIA}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH05&showdescription=no}{J01MA18}), carbenicillin (\code{CRB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA03&showdescription=no}{J01MA03}), carindacillin (\code{CRN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA05&showdescription=no}{J01MA17}), cefacetrile (\code{CAC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB10&showdescription=no}{J01MA10}), cefaclor (\code{CEC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC04&showdescription=no}{J01MA21}), cefadroxil (\code{CFR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB05&showdescription=no}{J01MA09}), cefalexin (\code{LEX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB01&showdescription=no}{J01MA05}), cefaloridine (\code{RID}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB02&showdescription=no}{P01AA05}), cefalotin (\code{CEP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB03&showdescription=no}{J01MA22}), cefamandole (\code{MAN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC03&showdescription=no}{J01MA13}), cefapirin (\code{HAP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB08&showdescription=no}{J01CA01}), cefatrizine (\code{CTZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB07&showdescription=no}{J01CA04}), cefazedone (\code{CZD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB06&showdescription=no}{J01CA12}), cefazolin (\code{CZO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB04&showdescription=no}{J01CR05}), cefcapene (\code{CCP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD17&showdescription=no}{J01CA13}), cefdinir (\code{CDR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD15&showdescription=no}{J01AA02}), cefditoren (\code{DIT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD16&showdescription=no}{J01FA10}), cefepime (\code{FEP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DE01&showdescription=no}{J01FA09}), cefetamet (\code{CAT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD10&showdescription=no}{J01CR02}), cefixime (\code{CFM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD08&showdescription=no}{J01AA08}), cefmenoxime (\code{CMX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD05&showdescription=no}{J01FA06}), cefmetazole (\code{CMZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC09&showdescription=no}{J01CF04}), cefodizime (\code{DIZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD09&showdescription=no}{J01CF05}), cefonicid (\code{CID}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC06&showdescription=no}{J01CR01}), cefoperazone (\code{CFP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD12&showdescription=no}{J01CA19}), cefoperazone/sulbactam (\code{CSL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD62&showdescription=no}{J01CE04}), ceforanide (\code{CND}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC11&showdescription=no}{J01CA09}), cefotaxime (\code{CTX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD01&showdescription=no}{J01DF01}), cefotaxime/clavulanic acid (\code{CTC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD51&showdescription=no}{J01CA06}), cefotetan (\code{CTT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC05&showdescription=no}{J01CE08}), cefotiam (\code{CTF}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC07&showdescription=no}{J01CE10}), cefoxitin (\code{FOX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC01&showdescription=no}{J01CE01}), cefozopran (\code{ZOP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DE03&showdescription=no}{J01CA03}), cefpiramide (\code{CPM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD11&showdescription=no}{J01CA05}), cefpirome (\code{CPO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DE02&showdescription=no}{J01CE07}), cefpodoxime (\code{CPD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD13&showdescription=no}{J01CF02}), cefprozil (\code{CPR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC10&showdescription=no}{J01CF01}), cefroxadine (\code{CRD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB11&showdescription=no}{J01CA07}), cefsulodin (\code{CFS}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD03&showdescription=no}{J01CA18}), ceftaroline (\code{CPT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DI02&showdescription=no}{J01CA11}), ceftazidime (\code{CAZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD02&showdescription=no}{J01CA14}), ceftazidime/clavulanic acid (\code{CCV}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD52&showdescription=no}{J01CF03}), cefteram (\code{CEM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD18&showdescription=no}{J01CA10}), ceftezole (\code{CTL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB12&showdescription=no}{J01CF06}), ceftibuten (\code{CTB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD14&showdescription=no}{J01CE06}), ceftizoxime (\code{CZX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD07&showdescription=no}{J01CE05}), ceftobiprole medocaril (\code{CFM1}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DI01&showdescription=no}{J01CE02}), ceftolozane/tazobactam (\code{CZT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DI54&showdescription=no}{J01CA02}), ceftriaxone (\code{CRO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD04&showdescription=no}{J01CA08}), ceftriaxone/beta-lactamase inhibitor (\code{CEB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD63&showdescription=no}{J01CE09}), cefuroxime (\code{CXM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC02&showdescription=no}{J01CE03}), cephradine (\code{CED}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DB09&showdescription=no}{J01CG01}), chloramphenicol (\code{CHL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01BA01&showdescription=no}{J01CA16}), ciprofloxacin (\code{CIP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA02&showdescription=no}{J01CR04}), clarithromycin (\code{CLR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA09&showdescription=no}{J01CA15}), clindamycin (\code{CLI}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FF01&showdescription=no}{J01CG02}), clometocillin (\code{CLM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE07&showdescription=no}{J01CA17}), cloxacillin (\code{CLO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF02&showdescription=no}{J01CR03}), colistin (\code{COL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XB01&showdescription=no}{J01DB10}), cycloserine (\code{CYC}, \href{https://www.whocc.no/atc_ddd_index/?code=J04AB01&showdescription=no}{J01DC04}), dalbavancin (\code{DAL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XA04&showdescription=no}{J01DB05}), daptomycin (\code{DAP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XX09&showdescription=no}{J01DB01}), delafloxacin (\code{DFX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA23&showdescription=no}{J01DB02}), dibekacin (\code{DKB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB09&showdescription=no}{J01DB03}), dicloxacillin (\code{DIC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF01&showdescription=no}{J01DC03}), dirithromycin (\code{DIR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA13&showdescription=no}{J01DB08}), doripenem (\code{DOR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH04&showdescription=no}{J01DB07}), doxycycline (\code{DOX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01AA02&showdescription=no}{J01DB06}), enoxacin (\code{ENX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA04&showdescription=no}{J01DB04}), epicillin (\code{EPC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA07&showdescription=no}{J01DD17}), ertapenem (\code{ETP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH03&showdescription=no}{J01DD15}), erythromycin (\code{ERY}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA01&showdescription=no}{J01DD16}), fleroxacin (\code{FLE}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA08&showdescription=no}{J01DE01}), flucloxacillin (\code{FLC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF05&showdescription=no}{J01DD10}), flurithromycin (\code{FLR1}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA14&showdescription=no}{J01DD08}), fosfomycin (\code{FOS}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XX01&showdescription=no}{J01DD05}), framycetin (\code{FRM}, \href{https://www.whocc.no/atc_ddd_index/?code=D09AA01&showdescription=no}{J01DC09}), fusidic acid (\code{FUS}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XC01&showdescription=no}{J01DD09}), garenoxacin (\code{GRN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA19&showdescription=no}{J01DC06}), gatifloxacin (\code{GAT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA16&showdescription=no}{J01DD12}), gemifloxacin (\code{GEM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA15&showdescription=no}{J01DD62}), gentamicin (\code{GEN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB03&showdescription=no}{J01DC11}), grepafloxacin (\code{GRX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA11&showdescription=no}{J01DD01}), hetacillin (\code{HET}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA18&showdescription=no}{J01DD51}), imipenem (\code{IPM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH51&showdescription=no}{J01DC05}), imipenem/relebactam (\code{IMR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH56&showdescription=no}{J01DC07}), isepamicin (\code{ISE}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB11&showdescription=no}{J01DC01}), josamycin (\code{JOS}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA07&showdescription=no}{J01DE03}), kanamycin (\code{KAN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB04&showdescription=no}{J01DD11}), lascufloxacin (\code{LSC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA25&showdescription=no}{J01DE02}), latamoxef (\code{LTM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DD06&showdescription=no}{J01DD13}), levofloxacin (\code{LVX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA12&showdescription=no}{J01DC10}), levonadifloxacin (\code{LND}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA24&showdescription=no}{J01DB11}), lincomycin (\code{LIN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FF02&showdescription=no}{J01DD03}), linezolid (\code{LNZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XX08&showdescription=no}{J01DI02}), lomefloxacin (\code{LOM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA07&showdescription=no}{J01DD02}), loracarbef (\code{LOR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DC08&showdescription=no}{J01DD52}), mecillinam (\code{MEC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA11&showdescription=no}{J01DD18}), meropenem (\code{MEM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH02&showdescription=no}{J01DB12}), meropenem/vaborbactam (\code{MEV}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH52&showdescription=no}{J01DD14}), metampicillin (\code{MTM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA14&showdescription=no}{J01DD07}), meticillin (\code{MET}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF03&showdescription=no}{J01DI01}), mezlocillin (\code{MEZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA10&showdescription=no}{J01DI54}), micronomicin (\code{MCR}, \href{https://www.whocc.no/atc_ddd_index/?code=S01AA22&showdescription=no}{J01DD04}), midecamycin (\code{MID}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA03&showdescription=no}{J01DD63}), minocycline (\code{MNO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01AA08&showdescription=no}{J01DC02}), miocamycin (\code{MCM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA11&showdescription=no}{J01DB09}), moxifloxacin (\code{MFX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA14&showdescription=no}{J01DD06}), nadifloxacin (\code{NAD}, \href{https://www.whocc.no/atc_ddd_index/?code=D10AF05&showdescription=no}{J01DC08}), nafcillin (\code{NAF}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF06&showdescription=no}{J01DH05}), nalidixic acid (\code{NAL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MB02&showdescription=no}{J01DH04}), neomycin (\code{NEO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB05&showdescription=no}{J01DH03}), netilmicin (\code{NET}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB07&showdescription=no}{J01DH51}), nitrofurantoin (\code{NIT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XE01&showdescription=no}{J01DH56}), norfloxacin (\code{NOR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA06&showdescription=no}{J01DH02}), ofloxacin (\code{OFX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA01&showdescription=no}{J01DH52}), oleandomycin (\code{OLE}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA05&showdescription=no}{J01DH55}), oritavancin (\code{ORI}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XA05&showdescription=no}{J01DH06}), oxacillin (\code{OXA}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CF04&showdescription=no}{J01XA02}), panipenem (\code{PAN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH55&showdescription=no}{J01XA01}), pazufloxacin (\code{PAZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA18&showdescription=no}{J01XC01}), pefloxacin (\code{PEF}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA03&showdescription=no}{J01FA13}), penamecillin (\code{PNM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE06&showdescription=no}{J01FA01}), pheneticillin (\code{PHE}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE05&showdescription=no}{J01FA14}), phenoxymethylpenicillin (\code{PHN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE02&showdescription=no}{J01FA07}), piperacillin (\code{PIP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA12&showdescription=no}{J01FA03}), piperacillin/tazobactam (\code{TZP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CR05&showdescription=no}{J01FA11}), pivampicillin (\code{PVM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA02&showdescription=no}{J01FA05}), pivmecillinam (\code{PME}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA08&showdescription=no}{J01FA12}), plazomicin (\code{PLZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB14&showdescription=no}{J01FA16}), polymyxin B (\code{PLB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XB02&showdescription=no}{J01FA02}), pristinamycin (\code{PRI}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FG01&showdescription=no}{J01FA15}), procaine benzylpenicillin (\code{PRB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE09&showdescription=no}{J01FA08}), propicillin (\code{PRP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CE03&showdescription=no}{J01FF02}), prulifloxacin (\code{PRU}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA17&showdescription=no}{J01FG01}), quinupristin/dalfopristin (\code{QDA}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FG02&showdescription=no}{J01FG02}), ribostamycin (\code{RST}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB10&showdescription=no}{J04AB02}), rifampicin (\code{RIF}, \href{https://www.whocc.no/atc_ddd_index/?code=J04AB02&showdescription=no}{J01XX09}), rokitamycin (\code{ROK}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA12&showdescription=no}{J01XX08}), roxithromycin (\code{RXT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA06&showdescription=no}{J01AA07}), rufloxacin (\code{RFL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA10&showdescription=no}{J01XB01}), sisomicin (\code{SIS}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB08&showdescription=no}{J01XB02}), sitafloxacin (\code{SIT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA21&showdescription=no}{J01XE01}), solithromycin (\code{SOL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA16&showdescription=no}{J01AA12}), sparfloxacin (\code{SPX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA09&showdescription=no}{J01EA01}), spiramycin (\code{SPI}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA02&showdescription=no}{J01XX01}), streptoduocin (\code{STR}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GA02&showdescription=no}{J01BA01}), streptomycin (\code{STR1}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GA01&showdescription=no}{J01GB06}), sulbactam (\code{SUL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CG01&showdescription=no}{J01GB12}), sulbenicillin (\code{SBC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA16&showdescription=no}{J01GB13}), sulfadiazine (\code{SDI}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EC02&showdescription=no}{J01GB09}), sulfadiazine/trimethoprim (\code{SLT1}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE02&showdescription=no}{D09AA01}), sulfadimethoxine (\code{SUD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED01&showdescription=no}{J01GB03}), sulfadimidine (\code{SDM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB03&showdescription=no}{J01GB11}), sulfadimidine/trimethoprim (\code{SLT2}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE05&showdescription=no}{J01GB04}), sulfafurazole (\code{SLF}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB05&showdescription=no}{S01AA22}), sulfaisodimidine (\code{SLF1}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB01&showdescription=no}{J01GB05}), sulfalene (\code{SLF2}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED02&showdescription=no}{J01GB07}), sulfamazone (\code{SZO}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED09&showdescription=no}{J01GB14}), sulfamerazine (\code{SLF3}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED07&showdescription=no}{J01GB10}), sulfamerazine/trimethoprim (\code{SLT3}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE07&showdescription=no}{J01GB08}), sulfamethizole (\code{SLF4}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB02&showdescription=no}{J01GA02}), sulfamethoxazole (\code{SMX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EC01&showdescription=no}{J01GA01}), sulfamethoxypyridazine (\code{SLF5}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED05&showdescription=no}{J01GB01}), sulfametomidine (\code{SLF6}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED03&showdescription=no}{J01EE01}), sulfametoxydiazine (\code{SLF7}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED04&showdescription=no}{J01MB02}), sulfametrole/trimethoprim (\code{SLT4}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE03&showdescription=no}{J01FF01}), sulfamoxole (\code{SLF8}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EC03&showdescription=no}{J01XA04}), sulfamoxole/trimethoprim (\code{SLT5}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE04&showdescription=no}{J01XA05}), sulfanilamide (\code{SLF9}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB06&showdescription=no}{J01XA03}), sulfaperin (\code{SLF10}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED06&showdescription=no}{J04AB01}), sulfaphenazole (\code{SLF11}, \href{https://www.whocc.no/atc_ddd_index/?code=J01ED08&showdescription=no}{J01XX11}), sulfapyridine (\code{SLF12}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB04&showdescription=no}{J01EC02}), sulfathiazole (\code{SUT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB07&showdescription=no}{J01ED01}), sulfathiourea (\code{SLF13}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EB08&showdescription=no}{J01EB03}), sultamicillin (\code{SLT6}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CR04&showdescription=no}{J01EB05}), talampicillin (\code{TAL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA15&showdescription=no}{J01EB01}), tazobactam (\code{TAZ}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CG02&showdescription=no}{J01ED02}), tebipenem (\code{TBP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01DH06&showdescription=no}{J01ED09}), tedizolid (\code{TZD}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XX11&showdescription=no}{J01ED07}), teicoplanin (\code{TEC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XA02&showdescription=no}{J01EB02}), telavancin (\code{TLV}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XA03&showdescription=no}{J01EC01}), telithromycin (\code{TLT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA15&showdescription=no}{J01ED05}), temafloxacin (\code{TMX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA05&showdescription=no}{J01ED03}), temocillin (\code{TEM}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA17&showdescription=no}{J01ED04}), tetracycline (\code{TCY}, \href{https://www.whocc.no/atc_ddd_index/?code=J01AA07&showdescription=no}{J01EC03}), ticarcillin (\code{TIC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CA13&showdescription=no}{J01EB06}), ticarcillin/clavulanic acid (\code{TCC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01CR03&showdescription=no}{J01ED06}), tigecycline (\code{TGC}, \href{https://www.whocc.no/atc_ddd_index/?code=J01AA12&showdescription=no}{J01ED08}), tilbroquinol (\code{TBQ}, \href{https://www.whocc.no/atc_ddd_index/?code=P01AA05&showdescription=no}{J01EB04}), tobramycin (\code{TOB}, \href{https://www.whocc.no/atc_ddd_index/?code=J01GB01&showdescription=no}{J01EB07}), tosufloxacin (\code{TFX}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA22&showdescription=no}{J01EB08}), trimethoprim (\code{TMP}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EA01&showdescription=no}{J01EE02}), trimethoprim/sulfamethoxazole (\code{SXT}, \href{https://www.whocc.no/atc_ddd_index/?code=J01EE01&showdescription=no}{J01EE05}), troleandomycin (\code{TRL}, \href{https://www.whocc.no/atc_ddd_index/?code=J01FA08&showdescription=no}{J01EE07}), trovafloxacin (\code{TVA}, \href{https://www.whocc.no/atc_ddd_index/?code=J01MA13&showdescription=no}{J01EE03}), vancomycin (\code{VAN}, \href{https://www.whocc.no/atc_ddd_index/?code=J01XA01&showdescription=no}{J01EE04}) } -\section{Interpretation of R and S/I}{ +\section{Interpretation of SIR}{ -In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (\url{https://www.eucast.org/newsiandr/}). +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr/}): \itemize{ +\item \strong{S - Susceptible, standard dosing regimen}\cr +A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +\item \strong{I - Susceptible, increased exposure} \emph{\cr +A microorganism is categorised as "Susceptible, Increased exposure}" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. \item \strong{R = Resistant}\cr -A microorganism is categorised as \emph{Resistant} when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -\item \strong{S = Susceptible}\cr -A microorganism is categorised as \emph{Susceptible, standard dosing regimen}, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -\item \strong{I = Susceptible, Increased exposure}\cr -A microorganism is categorised as \emph{Susceptible, Increased exposure} when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +\itemize{ +\item \emph{Exposure} is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. +} } This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates. diff --git a/man/mean_amr_distance.Rd b/man/mean_amr_distance.Rd index 88e166a51..68059981a 100755 --- a/man/mean_amr_distance.Rd +++ b/man/mean_amr_distance.Rd @@ -2,21 +2,21 @@ % Please edit documentation in R/mean_amr_distance.R \name{mean_amr_distance} \alias{mean_amr_distance} -\alias{mean_amr_distance.rsi} +\alias{mean_amr_distance.sir} \alias{mean_amr_distance.data.frame} \alias{amr_distance_from_row} \title{Calculate the Mean AMR Distance} \usage{ mean_amr_distance(x, ...) -\method{mean_amr_distance}{rsi}(x, ..., combine_SI = TRUE) +\method{mean_amr_distance}{sir}(x, ..., combine_SI = TRUE) \method{mean_amr_distance}{data.frame}(x, ..., combine_SI = TRUE) amr_distance_from_row(amr_distance, row) } \arguments{ -\item{x}{a vector of class \link[=as.rsi]{rsi}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes} +\item{x}{a vector of class \link[=as.sir]{sir}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes} \item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}} @@ -34,7 +34,7 @@ The mean AMR distance is effectively \href{https://en.wikipedia.org/wiki/Standar MIC values (see \code{\link[=as.mic]{as.mic()}}) are transformed with \code{\link[=log2]{log2()}} first; their distance is thus calculated as \code{(log2(x) - mean(log2(x))) / sd(log2(x))}. -R/SI values (see \code{\link[=as.rsi]{as.rsi()}}) are transformed using \code{"S"} = 1, \code{"I"} = 2, and \code{"R"} = 3. If \code{combine_SI} is \code{TRUE} (default), the \code{"I"} will be considered to be 1. +SIR values (see \code{\link[=as.sir]{as.sir()}}) are transformed using \code{"S"} = 1, \code{"I"} = 2, and \code{"R"} = 3. If \code{combine_SI} is \code{TRUE} (default), the \code{"I"} will be considered to be 1. For data sets, the mean AMR distance will be calculated per column, after which the mean per row will be returned, see \emph{Examples}. @@ -46,9 +46,9 @@ Isolates with distances less than 0.01 difference from each other should be cons } \examples{ -rsi <- random_rsi(10) -rsi -mean_amr_distance(rsi) +sir <- random_sir(10) +sir +mean_amr_distance(sir) mic <- random_mic(10) mic @@ -62,7 +62,7 @@ mean_amr_distance(disk) y <- data.frame( id = LETTERS[1:10], - amox = random_rsi(10, ab = "amox", mo = "Escherichia coli"), + amox = random_sir(10, ab = "amox", mo = "Escherichia coli"), cipr = random_disk(10, ab = "cipr", mo = "Escherichia coli"), gent = random_mic(10, ab = "gent", mo = "Escherichia coli"), tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli") diff --git a/man/mo_matching_score.Rd b/man/mo_matching_score.Rd index 73fbcbd87..f659034c5 100755 --- a/man/mo_matching_score.Rd +++ b/man/mo_matching_score.Rd @@ -59,7 +59,7 @@ All matches are sorted descending on their matching score and for all user input \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/mo_property.Rd b/man/mo_property.Rd index fb4c0993c..ec46c967d 100755 --- a/man/mo_property.Rd +++ b/man/mo_property.Rd @@ -345,7 +345,7 @@ This function uses \code{\link[=as.mo]{as.mo()}} internally, which uses an advan \section{Reference Data Publicly Available}{ -All data sets in this \code{AMR} package (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. +All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}. } \examples{ diff --git a/man/pca.Rd b/man/pca.Rd index 4d7fb1247..f6b2c8ab7 100755 --- a/man/pca.Rd +++ b/man/pca.Rd @@ -72,7 +72,7 @@ if (require("dplyr")) { genus = mo_genus(mo) ) \%>\% # and genus as we do here; filter(n() >= 30) \%>\% # filter on only 30 results per group - summarise_if(is.rsi, resistance) # then get resistance of all drugs + summarise_if(is.sir, resistance) # then get resistance of all drugs # now conduct PCA for certain antimicrobial drugs pca_result <- resistance_data \%>\% diff --git a/man/plot.Rd b/man/plot.Rd index e0a1b06c1..3cf7bda30 100755 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -8,10 +8,10 @@ \alias{plot.disk} \alias{autoplot.disk} \alias{fortify.disk} -\alias{plot.rsi} -\alias{autoplot.rsi} -\alias{fortify.rsi} -\title{Plotting for Classes \code{rsi}, \code{mic} and \code{disk}} +\alias{plot.sir} +\alias{autoplot.sir} +\alias{fortify.sir} +\title{Plotting for Classes \code{sir}, \code{mic} and \code{disk}} \usage{ \method{plot}{mic}( x, @@ -21,7 +21,7 @@ main = deparse(substitute(x)), ylab = "Frequency", xlab = "Minimum Inhibitory Concentration (mg/L)", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ... @@ -35,7 +35,7 @@ title = deparse(substitute(object)), ylab = "Frequency", xlab = "Minimum Inhibitory Concentration (mg/L)", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ... @@ -51,7 +51,7 @@ mo = NULL, ab = NULL, guideline = "EUCAST", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ... @@ -65,7 +65,7 @@ ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", guideline = "EUCAST", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), expand = TRUE, ... @@ -73,7 +73,7 @@ \method{fortify}{disk}(object, ...) -\method{plot}{rsi}( +\method{plot}{sir}( x, ylab = "Percentage", xlab = "Antimicrobial Interpretation", @@ -82,20 +82,20 @@ ... ) -\method{autoplot}{rsi}( +\method{autoplot}{sir}( object, title = deparse(substitute(object)), xlab = "Antimicrobial Interpretation", ylab = "Frequency", - colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"), language = get_AMR_locale(), ... ) -\method{fortify}{rsi}(object, ...) +\method{fortify}{sir}(object, ...) } \arguments{ -\item{x, object}{values created with \code{\link[=as.mic]{as.mic()}}, \code{\link[=as.disk]{as.disk()}} or \code{\link[=as.rsi]{as.rsi()}} (or their \verb{random_*} variants, such as \code{\link[=random_mic]{random_mic()}})} +\item{x, object}{values created with \code{\link[=as.mic]{as.mic()}}, \code{\link[=as.disk]{as.disk()}} or \code{\link[=as.sir]{as.sir()}} (or their \verb{random_*} variants, such as \code{\link[=random_mic]{random_mic()}})} \item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}} @@ -107,7 +107,7 @@ \item{xlab, ylab}{axis title} -\item{colours_RSI}{colours to use for filling in the bars, must be a vector of three values (in the order R, S and I). The default colours are colour-blind friendly.} +\item{colours_SIR}{colours to use for filling in the bars, must be a vector of three values (in the order S, I and R). The default colours are colour-blind friendly.} \item{language}{language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant', defaults to system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}) and can be overwritten by setting the option \code{AMR_locale}, e.g. \code{options(AMR_locale = "de")}, see \link{translate}. Use \code{language = NULL} or \code{language = ""} to prevent translation.} @@ -121,7 +121,7 @@ The \code{autoplot()} functions return a \code{\link[ggplot2:ggplot]{ggplot}} mo The \code{fortify()} functions return a \link{data.frame} as an extension for usage in the \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}} function. } \description{ -Functions to plot classes \code{rsi}, \code{mic} and \code{disk}, with support for base \R and \code{ggplot2}. +Functions to plot classes \code{sir}, \code{mic} and \code{disk}, with support for base \R and \code{ggplot2}. } \details{ The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases. @@ -133,11 +133,11 @@ Simply using \code{"CLSI"} or \code{"EUCAST"} as input will automatically select \examples{ some_mic_values <- random_mic(size = 100) some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") -some_rsi_values <- random_rsi(50, prob_RSI = c(0.30, 0.55, 0.05)) +some_sir_values <- random_sir(50, prob_SIR = c(0.55, 0.05, 0.30)) plot(some_mic_values) plot(some_disk_values) -plot(some_rsi_values) +plot(some_sir_values) # when providing the microorganism and antibiotic, colours will show interpretations: plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") @@ -152,7 +152,7 @@ if (require("ggplot2")) { autoplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") } if (require("ggplot2")) { - autoplot(some_rsi_values) + autoplot(some_sir_values) } } } diff --git a/man/proportion.Rd b/man/proportion.Rd index f168b9a0f..419089c8f 100755 --- a/man/proportion.Rd +++ b/man/proportion.Rd @@ -1,18 +1,18 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/proportion.R, R/rsi_df.R +% Please edit documentation in R/proportion.R, R/sir_df.R \name{proportion} \alias{proportion} \alias{resistance} \alias{portion} \alias{susceptibility} -\alias{rsi_confidence_interval} +\alias{sir_confidence_interval} \alias{proportion_R} \alias{proportion_IR} \alias{proportion_I} \alias{proportion_SI} \alias{proportion_S} \alias{proportion_df} -\alias{rsi_df} +\alias{sir_df} \title{Calculate Microbial Resistance} \source{ \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition}, 2022, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}. @@ -22,7 +22,7 @@ resistance(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE) susceptibility(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE) -rsi_confidence_interval( +sir_confidence_interval( ..., ab_result = "R", minimum = 30, @@ -52,7 +52,7 @@ proportion_df( confidence_level = 0.95 ) -rsi_df( +sir_df( data, translate_ab = "name", language = get_AMR_locale(), @@ -63,7 +63,7 @@ rsi_df( ) } \arguments{ -\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.rsi]{as.rsi()}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See \emph{Examples}.} +\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.sir]{as.sir()}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See \emph{Examples}.} \item{minimum}{the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see \emph{Source}.} @@ -71,13 +71,13 @@ rsi_df( \item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antibiotics, see section \emph{Combination Therapy} below} -\item{ab_result}{antibiotic results to test against, must be one of more values of "R", "S", "I"} +\item{ab_result}{antibiotic results to test against, must be one or more values of "S", "I", or "R"} \item{confidence_level}{the confidence level for the returned confidence interval. For the calculation, the number of S or SI isolates, and R isolates are compared with the total number of available isolates with R, S, or I by using \code{\link[=binom.test]{binom.test()}}, i.e., the Clopper-Pearson method.} \item{side}{the side of the confidence interval to return. Defaults to \code{"both"} for a length 2 vector, but can also be (abbreviated as) \code{"min"}/\code{"left"}/\code{"lower"}/\code{"less"} or \code{"max"}/\code{"right"}/\code{"higher"}/\code{"greater"}.} -\item{data}{a \link{data.frame} containing columns with class \code{\link{rsi}} (see \code{\link[=as.rsi]{as.rsi()}})} +\item{data}{a \link{data.frame} containing columns with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})} \item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}} @@ -96,13 +96,13 @@ These functions can be used to calculate the (co-)resistance or susceptibility o \details{ The function \code{\link[=resistance]{resistance()}} is equal to the function \code{\link[=proportion_R]{proportion_R()}}. The function \code{\link[=susceptibility]{susceptibility()}} is equal to the function \code{\link[=proportion_SI]{proportion_SI()}}. -Use \code{\link[=rsi_confidence_interval]{rsi_confidence_interval()}} to calculate the confidence interval, which relies on \code{\link[=binom.test]{binom.test()}}, i.e., the Clopper-Pearson method. This function returns a vector of length 2 at default for antimicrobial \emph{resistance}. Change the \code{side} argument to "left"/"min" or "right"/"max" to return a single value, and change the \code{ab_result} argument to e.g. \code{c("S", "I")} to test for antimicrobial \emph{susceptibility}, see Examples. +Use \code{\link[=sir_confidence_interval]{sir_confidence_interval()}} to calculate the confidence interval, which relies on \code{\link[=binom.test]{binom.test()}}, i.e., the Clopper-Pearson method. This function returns a vector of length 2 at default for antimicrobial \emph{resistance}. Change the \code{side} argument to "left"/"min" or "right"/"max" to return a single value, and change the \code{ab_result} argument to e.g. \code{c("S", "I")} to test for antimicrobial \emph{susceptibility}, see Examples. \strong{Remember that you should filter your data to let it contain only first isolates!} This is needed to exclude duplicates and to reduce selection bias. Use \code{\link[=first_isolate]{first_isolate()}} to determine them in your data set. These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the \code{\link[=count]{count()}} functions to count isolates. The function \code{\link[=susceptibility]{susceptibility()}} is essentially equal to \code{count_susceptible() / count_all()}. \emph{Low counts can influence the outcome - the \code{proportion} functions may camouflage this, since they only return the proportion (albeit being dependent on the \code{minimum} argument).} -The function \code{\link[=proportion_df]{proportion_df()}} takes any variable from \code{data} that has an \code{\link{rsi}} class (created with \code{\link[=as.rsi]{as.rsi()}}) and calculates the proportions R, I and S. It also supports grouped variables. The function \code{\link[=rsi_df]{rsi_df()}} works exactly like \code{\link[=proportion_df]{proportion_df()}}, but adds the number of isolates. +The function \code{\link[=proportion_df]{proportion_df()}} takes any variable from \code{data} that has an \code{\link{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) and calculates the proportions S, I, and R. It also supports grouped variables. The function \code{\link[=sir_df]{sir_df()}} works exactly like \code{\link[=proportion_df]{proportion_df()}}, but adds the number of isolates. } \section{Combination Therapy}{ @@ -141,16 +141,19 @@ and that, in combination therapies, for \code{only_all_tested = FALSE} applies t Using \code{only_all_tested} has no impact when only using one antibiotic as input. } -\section{Interpretation of R and S/I}{ +\section{Interpretation of SIR}{ -In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (\url{https://www.eucast.org/newsiandr/}). +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr/}): \itemize{ +\item \strong{S - Susceptible, standard dosing regimen}\cr +A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +\item \strong{I - Susceptible, increased exposure} \emph{\cr +A microorganism is categorised as "Susceptible, Increased exposure}" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. \item \strong{R = Resistant}\cr -A microorganism is categorised as \emph{Resistant} when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -\item \strong{S = Susceptible}\cr -A microorganism is categorised as \emph{Susceptible, standard dosing regimen}, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -\item \strong{I = Susceptible, Increased exposure}\cr -A microorganism is categorised as \emph{Susceptible, Increased exposure} when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +\itemize{ +\item \emph{Exposure} is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. +} } This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates. @@ -163,14 +166,14 @@ This AMR package honours this insight. Use \code{\link[=susceptibility]{suscepti # base R ------------------------------------------------------------ # determines \%R resistance(example_isolates$AMX) -rsi_confidence_interval(example_isolates$AMX) -rsi_confidence_interval(example_isolates$AMX, +sir_confidence_interval(example_isolates$AMX) +sir_confidence_interval(example_isolates$AMX, confidence_level = 0.975 ) # determines \%S+I: susceptibility(example_isolates$AMX) -rsi_confidence_interval(example_isolates$AMX, +sir_confidence_interval(example_isolates$AMX, ab_result = c("S", "I") ) @@ -188,16 +191,16 @@ if (require("dplyr")) { group_by(ward) \%>\% summarise( r = resistance(CIP), - n = n_rsi(CIP) - ) # n_rsi works like n_distinct in dplyr, see ?n_rsi + n = n_sir(CIP) + ) # n_sir works like n_distinct in dplyr, see ?n_sir } if (require("dplyr")) { example_isolates \%>\% group_by(ward) \%>\% summarise( cipro_R = resistance(CIP), - ci_min = rsi_confidence_interval(CIP, side = "min"), - ci_max = rsi_confidence_interval(CIP, side = "max"), + ci_min = sir_confidence_interval(CIP, side = "min"), + ci_max = sir_confidence_interval(CIP, side = "max"), ) } if (require("dplyr")) { @@ -218,7 +221,7 @@ if (require("dplyr")) { R = resistance(CIP, as_percent = TRUE), SI = susceptibility(CIP, as_percent = TRUE), n1 = count_all(CIP), # the actual total; sum of all three - n2 = n_rsi(CIP), # same - analogous to n_distinct + n2 = n_sir(CIP), # same - analogous to n_distinct total = n() ) # NOT the number of tested isolates! @@ -261,17 +264,17 @@ if (require("dplyr")) { combination_n = count_all(CIP, GEN) ) - # Get proportions S/I/R immediately of all rsi columns + # Get proportions S/I/R immediately of all sir columns example_isolates \%>\% select(AMX, CIP) \%>\% proportion_df(translate = FALSE) # It also supports grouping variables - # (use rsi_df to also include the count) + # (use sir_df to also include the count) example_isolates \%>\% select(ward, AMX, CIP) \%>\% group_by(ward) \%>\% - rsi_df(translate = FALSE) + sir_df(translate = FALSE) } } } diff --git a/man/random.Rd b/man/random.Rd index d5325e9b3..87b7a82fa 100755 --- a/man/random.Rd +++ b/man/random.Rd @@ -4,14 +4,14 @@ \alias{random} \alias{random_mic} \alias{random_disk} -\alias{random_rsi} -\title{Random MIC Values/Disk Zones/RSI Generation} +\alias{random_sir} +\title{Random MIC Values/Disk Zones/SIR Generation} \usage{ random_mic(size = NULL, mo = NULL, ab = NULL, ...) random_disk(size = NULL, mo = NULL, ab = NULL, ...) -random_rsi(size = NULL, prob_RSI = c(0.33, 0.33, 0.33), ...) +random_sir(size = NULL, prob_SIR = c(0.33, 0.33, 0.33), ...) } \arguments{ \item{size}{desired size of the returned vector. If used in a \link{data.frame} call or \code{dplyr} verb, will get the current (group) size if left blank.} @@ -22,7 +22,7 @@ random_rsi(size = NULL, prob_RSI = c(0.33, 0.33, 0.33), ...) \item{...}{ignored, only in place to allow future extensions} -\item{prob_RSI}{a vector of length 3: the probabilities for "R" (1st value), "S" (2nd value) and "I" (3rd value)} +\item{prob_SIR}{a vector of length 3: the probabilities for "S" (1st value), "I" (2nd value) and "R" (3rd value)} } \value{ class \code{mic} for \code{\link[=random_mic]{random_mic()}} (see \code{\link[=as.mic]{as.mic()}}) and class \code{disk} for \code{\link[=random_disk]{random_disk()}} (see \code{\link[=as.disk]{as.disk()}}) @@ -33,12 +33,12 @@ These functions can be used for generating random MIC values and disk diffusion \details{ The base \R function \code{\link[=sample]{sample()}} is used for generating values. -Generated values are based on the EUCAST 2022 guideline as implemented in the \link{rsi_translation} data set. To create specific generated values per bug or drug, set the \code{mo} and/or \code{ab} argument. +Generated values are based on the EUCAST 2022 guideline as implemented in the \link{clinical_breakpoints} data set. To create specific generated values per bug or drug, set the \code{mo} and/or \code{ab} argument. } \examples{ random_mic(25) random_disk(25) -random_rsi(25) +random_sir(25) \donttest{ # make the random generation more realistic by setting a bug and/or drug: diff --git a/man/resistance_predict.Rd b/man/resistance_predict.Rd index e05e3d536..4f253e0bb 100755 --- a/man/resistance_predict.Rd +++ b/man/resistance_predict.Rd @@ -2,9 +2,9 @@ % Please edit documentation in R/resistance_predict.R \name{resistance_predict} \alias{resistance_predict} -\alias{rsi_predict} +\alias{sir_predict} \alias{plot.resistance_predict} -\alias{ggplot_rsi_predict} +\alias{ggplot_sir_predict} \alias{autoplot.resistance_predict} \title{Predict Antimicrobial Resistance} \usage{ @@ -23,7 +23,7 @@ resistance_predict( ... ) -rsi_predict( +sir_predict( x, col_ab, col_date = NULL, @@ -40,7 +40,7 @@ rsi_predict( \method{plot}{resistance_predict}(x, main = paste("Resistance Prediction of", x_name), ...) -ggplot_rsi_predict( +ggplot_sir_predict( x, main = paste("Resistance Prediction of", x_name), ribbon = TRUE, @@ -110,16 +110,19 @@ Valid options for the statistical model (argument \code{model}) are: \item \code{"lin"} or \code{"linear"}: a linear regression model } } -\section{Interpretation of R and S/I}{ +\section{Interpretation of SIR}{ -In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories R and S/I as shown below (\url{https://www.eucast.org/newsiandr/}). +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr/}): \itemize{ +\item \strong{S - Susceptible, standard dosing regimen}\cr +A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. +\item \strong{I - Susceptible, increased exposure} \emph{\cr +A microorganism is categorised as "Susceptible, Increased exposure}" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. \item \strong{R = Resistant}\cr -A microorganism is categorised as \emph{Resistant} when there is a high likelihood of therapeutic failure even when there is increased exposure. Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. -\item \strong{S = Susceptible}\cr -A microorganism is categorised as \emph{Susceptible, standard dosing regimen}, when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent. -\item \strong{I = Susceptible, Increased exposure}\cr -A microorganism is categorised as \emph{Susceptible, Increased exposure} when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection. +A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure. +\itemize{ +\item \emph{Exposure} is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. +} } This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates. @@ -134,7 +137,7 @@ x <- resistance_predict(example_isolates, plot(x) \donttest{ if (require("ggplot2")) { - ggplot_rsi_predict(x) + ggplot_sir_predict(x) } # using dplyr: diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd index a394d9c1d..25da5af9a 100755 --- a/vignettes/AMR.Rmd +++ b/vignettes/AMR.Rmd @@ -33,7 +33,7 @@ Conducting AMR data analysis unfortunately requires in-depth knowledge from diff * Good questions (always start with those!) * A thorough understanding of (clinical) epidemiology, to understand the clinical and epidemiological relevance and possible bias of results * A thorough understanding of (clinical) microbiology/infectious diseases, to understand which microorganisms are causal to which infections and the implications of pharmaceutical treatment, as well as understanding intrinsic and acquired microbial resistance -* Experience with data analysis with microbiological tests and their results, to understand the determination and limitations of MIC values and their interpretations to RSI values +* Experience with data analysis with microbiological tests and their results, to understand the determination and limitations of MIC values and their interpretations to SIR values * Availability of the biological taxonomy of microorganisms and probably normalisation factors for pharmaceuticals, such as defined daily doses (DDD) * Available (inter-)national guidelines, and profound methods to apply them @@ -122,7 +122,7 @@ bacteria <- c( ## Put everything together -Using the `sample()` function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results, using the `random_rsi()` function. +Using the `sample()` function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results, using the `random_sir()` function. ```{r merge data} sample_size <- 20000 @@ -142,10 +142,10 @@ data <- data.frame( size = sample_size, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10) ), - AMX = random_rsi(sample_size, prob_RSI = c(0.35, 0.60, 0.05)), - AMC = random_rsi(sample_size, prob_RSI = c(0.15, 0.75, 0.10)), - CIP = random_rsi(sample_size, prob_RSI = c(0.20, 0.80, 0.00)), - GEN = random_rsi(sample_size, prob_RSI = c(0.08, 0.92, 0.00)) + AMX = random_sir(sample_size, prob_sir = c(0.35, 0.60, 0.05)), + AMC = random_sir(sample_size, prob_sir = c(0.15, 0.75, 0.10)), + CIP = random_sir(sample_size, prob_sir = c(0.20, 0.80, 0.00)), + GEN = random_sir(sample_size, prob_sir = c(0.08, 0.92, 0.00)) ) ``` @@ -186,14 +186,14 @@ data <- data %>% mutate(bacteria = as.mo(bacteria)) ``` -We also want to transform the antibiotics, because in real life data we don't know if they are really clean. The `as.rsi()` function ensures reliability and reproducibility in these kind of variables. The `is.rsi.eligible()` can check which columns are probably columns with R/SI test results. Using `mutate()` and `across()`, we can apply the transformation to the formal `` class: +We also want to transform the antibiotics, because in real life data we don't know if they are really clean. The `as.sir()` function ensures reliability and reproducibility in these kind of variables. The `is_sir_eligible()` can check which columns are probably columns with SIR test results. Using `mutate()` and `across()`, we can apply the transformation to the formal `` class: ```{r transform abx} -is.rsi.eligible(data) -colnames(data)[is.rsi.eligible(data)] +is_sir_eligible(data) +colnames(data)[is_sir_eligible(data)] data <- data %>% - mutate(across(where(is.rsi.eligible), as.rsi)) + mutate(across(where(is_sir_eligible), as.sir)) ``` Finally, we will apply [EUCAST rules](https://www.eucast.org/expert_rules_and_intrinsic_resistance/) on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the `eucast_rules()` function can also apply additional rules, like forcing ampicillin = R when amoxicillin/clavulanic acid = R. @@ -360,14 +360,14 @@ data_1st %>% knitr::kable(align = "c", big.mark = ",") ``` -Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the `n_rsi()` can be used, which works exactly like `n_distinct()` from the `dplyr` package. It counts all isolates available for every group (i.e. values S, I or R): +Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the `n_sir()` can be used, which works exactly like `n_distinct()` from the `dplyr` package. It counts all isolates available for every group (i.e. values S, I or R): ```{r, eval = FALSE} data_1st %>% group_by(hospital) %>% summarise( amoxicillin = resistance(AMX), - available = n_rsi(AMX) + available = n_sir(AMX) ) ``` ```{r, echo = FALSE} @@ -375,7 +375,7 @@ data_1st %>% group_by(hospital) %>% summarise( amoxicillin = resistance(AMX), - available = n_rsi(AMX) + available = n_sir(AMX) ) %>% knitr::kable(align = "c", big.mark = ",") ``` @@ -469,11 +469,11 @@ ggplot(a_data_set) + geom_bar(aes(year)) ``` -The `AMR` package contains functions to extend this `ggplot2` package, for example `geom_rsi()`. It automatically transforms data with `count_df()` or `proportion_df()` and show results in stacked bars. Its simplest and shortest example: +The `AMR` package contains functions to extend this `ggplot2` package, for example `geom_sir()`. It automatically transforms data with `count_df()` or `proportion_df()` and show results in stacked bars. Its simplest and shortest example: ```{r plot 3} ggplot(data_1st) + - geom_rsi(translate_ab = FALSE) + geom_sir(translate_ab = FALSE) ``` Omit the `translate_ab = FALSE` to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin/clavulanic acid, ciprofloxacin, gentamicin). @@ -484,13 +484,13 @@ If we group on e.g. the `genus` column and add some additional functions from ou # group the data on `genus` ggplot(data_1st %>% group_by(genus)) + # create bars with genus on x axis - # it looks for variables with class `rsi`, - # of which we have 4 (earlier created with `as.rsi`) - geom_rsi(x = "genus") + + # it looks for variables with class `sir`, + # of which we have 4 (earlier created with `as.sir`) + geom_sir(x = "genus") + # split plots on antibiotic - facet_rsi(facet = "antibiotic") + - # set colours to the R/SI interpretations (colour-blind friendly) - scale_rsi_colours() + + facet_sir(facet = "antibiotic") + + # set colours to the SIR interpretations (colour-blind friendly) + scale_sir_colours() + # show percentages on y axis scale_y_percent(breaks = 0:4 * 25) + # turn 90 degrees, to make it bars instead of columns @@ -505,12 +505,12 @@ ggplot(data_1st %>% group_by(genus)) + theme(axis.text.y = element_text(face = "italic")) ``` -To simplify this, we also created the `ggplot_rsi()` function, which combines almost all above functions: +To simplify this, we also created the `ggplot_sir()` function, which combines almost all above functions: ```{r plot 5} data_1st %>% group_by(genus) %>% - ggplot_rsi( + ggplot_sir( x = "genus", facet = "antibiotic", breaks = 0:4 * 25, diff --git a/vignettes/MDR.Rmd b/vignettes/MDR.Rmd index 8fafd561c..b47fc086e 100644 --- a/vignettes/MDR.Rmd +++ b/vignettes/MDR.Rmd @@ -111,16 +111,16 @@ example_isolates %>% For another example, I will create a data set to determine multi-drug resistant TB: ```{r} -# random_rsi() is a helper function to generate +# random_sir() is a helper function to generate # a random vector with values S, I and R my_TB_data <- data.frame( - rifampicin = random_rsi(5000), - isoniazid = random_rsi(5000), - gatifloxacin = random_rsi(5000), - ethambutol = random_rsi(5000), - pyrazinamide = random_rsi(5000), - moxifloxacin = random_rsi(5000), - kanamycin = random_rsi(5000) + rifampicin = random_sir(5000), + isoniazid = random_sir(5000), + gatifloxacin = random_sir(5000), + ethambutol = random_sir(5000), + pyrazinamide = random_sir(5000), + moxifloxacin = random_sir(5000), + kanamycin = random_sir(5000) ) ``` @@ -128,13 +128,13 @@ Because all column names are automatically verified for valid drug names or code ```{r, eval = FALSE} my_TB_data <- data.frame( - RIF = random_rsi(5000), - INH = random_rsi(5000), - GAT = random_rsi(5000), - ETH = random_rsi(5000), - PZA = random_rsi(5000), - MFX = random_rsi(5000), - KAN = random_rsi(5000) + RIF = random_sir(5000), + INH = random_sir(5000), + GAT = random_sir(5000), + ETH = random_sir(5000), + PZA = random_sir(5000), + MFX = random_sir(5000), + KAN = random_sir(5000) ) ``` diff --git a/vignettes/PCA.Rmd b/vignettes/PCA.Rmd index 3f31a5d43..508baba54 100755 --- a/vignettes/PCA.Rmd +++ b/vignettes/PCA.Rmd @@ -44,7 +44,7 @@ resistance_data <- example_isolates %>% order = mo_order(mo), # group on anything, like order genus = mo_genus(mo) ) %>% # and genus as we do here - summarise_if(is.rsi, resistance) %>% # then get resistance of all drugs + summarise_if(is.sir, resistance) %>% # then get resistance of all drugs select( order, genus, AMC, CXM, CTX, CAZ, GEN, TOB, TMP, SXT diff --git a/vignettes/WHONET.Rmd b/vignettes/WHONET.Rmd index b4f38f6d3..2a8e48814 100644 --- a/vignettes/WHONET.Rmd +++ b/vignettes/WHONET.Rmd @@ -48,15 +48,15 @@ library(cleaner) # to create frequency tables We will have to transform some variables to simplify and automate the analysis: * Microorganisms should be transformed to our own microorganism codes (called an `mo`) using [our Catalogue of Life reference data set](https://msberends.github.io/AMR/reference/catalogue_of_life), which contains all ~70,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with `as.mo()`. This function also recognises almost all WHONET abbreviations of microorganisms. -* Antimicrobial results or interpretations have to be clean and valid. In other words, they should only contain values `"S"`, `"I"` or `"R"`. That is exactly where the `as.rsi()` function is for. +* Antimicrobial results or interpretations have to be clean and valid. In other words, they should only contain values `"S"`, `"I"` or `"R"`. That is exactly where the `as.sir()` function is for. ```{r} # transform variables data <- WHONET %>% # get microbial ID based on given organism mutate(mo = as.mo(Organism)) %>% - # transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class - mutate_at(vars(AMP_ND10:CIP_EE), as.rsi) + # transform everything from "AMP_ND10" to "CIP_EE" to the new `sir` class + mutate_at(vars(AMP_ND10:CIP_EE), as.sir) ``` No errors or warnings, so all values are transformed succesfully. @@ -77,13 +77,13 @@ data %>% freq(AMC_ND2) ### A first glimpse at results -An easy `ggplot` will already give a lot of information, using the included `ggplot_rsi()` function: +An easy `ggplot` will already give a lot of information, using the included `ggplot_sir()` function: ```{r, eval = FALSE} data %>% group_by(Country) %>% select(Country, AMP_ND2, AMC_ED20, CAZ_ED10, CIP_ED5) %>% - ggplot_rsi(translate_ab = "ab", facet = "Country", datalabels = FALSE) + ggplot_sir(translate_ab = "ab", facet = "Country", datalabels = FALSE) ``` ```{r, echo = FALSE} @@ -91,7 +91,7 @@ data %>% tryCatch(data %>% group_by(Country) %>% select(Country, AMP_ND2, AMC_ED20, CAZ_ED10, CIP_ED5) %>% - ggplot_rsi(translate_ab = "ab", facet = "Country", datalabels = FALSE) %>% + ggplot_sir(translate_ab = "ab", facet = "Country", datalabels = FALSE) %>% print(), error = function(e) base::invisible() ) diff --git a/vignettes/datasets.Rmd b/vignettes/datasets.Rmd index e7ee87ab0..8abb3d354 100644 --- a/vignettes/datasets.Rmd +++ b/vignettes/datasets.Rmd @@ -111,7 +111,7 @@ print_df <- function(x, rows = 6) { } ``` -All reference data (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) in this `AMR` package are reliable, up-to-date and freely available. We continually export our data sets to formats for use in R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. +All reference data (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) in this `AMR` package are reliable, up-to-date and freely available. We continually export our data sets to formats for use in R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. On this page, we explain how to download them and how the structure of the data sets look like. @@ -209,22 +209,22 @@ antivirals %>% print_df() ``` -## `rsi_translation`: Interpretation from MIC values / disk diameters to R/SI +## `clinical_breakpoints`: Interpretation from MIC values & disk diameters to SIR -`r structure_txt(rsi_translation)` +`r structure_txt(clinical_breakpoints)` -This data set is in R available as `rsi_translation`, after you load the `AMR` package. +This data set is in R available as `clinical_breakpoints`, after you load the `AMR` package. -`r download_txt("rsi_translation")` +`r download_txt("clinical_breakpoints")` ### Source -This data set contains interpretation rules for MIC values and disk diffusion diameters. Included guidelines are CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`) and EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`). +This data set contains interpretation rules for MIC values and disk diffusion diameters. Included guidelines are CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`) and EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`). ### Example content ```{r, echo = FALSE} -rsi_translation %>% +clinical_breakpoints %>% mutate(mo_name = mo_name(mo, language = NULL), .after = mo) %>% mutate(ab_name = ab_name(ab, language = NULL), .after = ab) %>% print_df() diff --git a/vignettes/resistance_predict.Rmd b/vignettes/resistance_predict.Rmd index 97d0cd75d..62244de5a 100755 --- a/vignettes/resistance_predict.Rmd +++ b/vignettes/resistance_predict.Rmd @@ -80,13 +80,13 @@ plot(predict_TZP) This is the fastest way to plot the result. It automatically adds the right axes, error bars, titles, number of available observations and type of model. -We also support the `ggplot2` package with our custom function `ggplot_rsi_predict()` to create more appealing plots: +We also support the `ggplot2` package with our custom function `ggplot_sir_predict()` to create more appealing plots: ```{r} -ggplot_rsi_predict(predict_TZP) +ggplot_sir_predict(predict_TZP) # choose for error bars instead of a ribbon -ggplot_rsi_predict(predict_TZP, ribbon = FALSE) +ggplot_sir_predict(predict_TZP, ribbon = FALSE) ``` ### Choosing the right model @@ -97,7 +97,7 @@ Resistance is not easily predicted; if we look at vancomycin resistance in Gram- example_isolates %>% filter(mo_gramstain(mo, language = NULL) == "Gram-positive") %>% resistance_predict(col_ab = "VAN", year_min = 2010, info = FALSE, model = "binomial") %>% - ggplot_rsi_predict() + ggplot_sir_predict() ``` Vancomycin resistance could be 100% in ten years, but might remain very low. @@ -118,7 +118,7 @@ For the vancomycin resistance in Gram-positive bacteria, a linear model might be example_isolates %>% filter(mo_gramstain(mo, language = NULL) == "Gram-positive") %>% resistance_predict(col_ab = "VAN", year_min = 2010, info = FALSE, model = "linear") %>% - ggplot_rsi_predict() + ggplot_sir_predict() ``` The model itself is also available from the object, as an `attribute`: diff --git a/vignettes/welcome_to_AMR.Rmd b/vignettes/welcome_to_AMR.Rmd index 3b9a9582d..c2d55a090 100644 --- a/vignettes/welcome_to_AMR.Rmd +++ b/vignettes/welcome_to_AMR.Rmd @@ -30,7 +30,7 @@ The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#c This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)). -After installing this package, R knows `r AMR:::format_included_data_number(AMR::microorganisms)` distinct microbial species and all `r AMR:::format_included_data_number(rbind(AMR::antibiotics[, "atc", drop = FALSE], AMR::antivirals[, "atc", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. +After installing this package, R knows `r AMR:::format_included_data_number(AMR::microorganisms)` distinct microbial species and all `r AMR:::format_included_data_number(rbind(AMR::antibiotics[, "atc", drop = FALSE], AMR::antivirals[, "atc", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. The `AMR` package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages. @@ -52,10 +52,10 @@ This package can be used for: * Applying EUCAST expert rules * Getting SNOMED codes of a microorganism, or getting properties of a microorganism based on a SNOMED code * Getting LOINC codes of an antibiotic, or getting properties of an antibiotic based on a LOINC code - * Machine reading the EUCAST and CLSI guidelines from 2011-2020 to translate MIC values and disk diffusion diameters to R/SI + * Machine reading the EUCAST and CLSI guidelines from 2011-2020 to translate MIC values and disk diffusion diameters to SIR * Principal component analysis for AMR -All reference data sets (about microorganisms, antibiotics, R/SI interpretation, EUCAST rules, etc.) in this `AMR` package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find [all download links on our website](https://msberends.github.io/AMR/articles/datasets.html), which is automatically updated with every code change. +All reference data sets (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) in this `AMR` package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find [all download links on our website](https://msberends.github.io/AMR/articles/datasets.html), which is automatically updated with every code change. This R package was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl), and is being [actively and durably maintained](./news) by two public healthcare organisations in the Netherlands.