diff --git a/DESCRIPTION b/DESCRIPTION index 8ad67e4e..3298eaed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.3.0 -Date: 2020-07-31 +Version: 1.3.0.9000 +Date: 2020-08-10 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index f6607863..034004e4 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,19 @@ -# AMR 1.3.0 +# AMR 1.3.0.9000 +## Last updated: 10 August 2020 +### Changed +* Support for using `dplyr`'s `across()` in `as.rsi()` to interpret MIC values or disk zone diameters, that now also automatically determines the column with microorganism names or codes. + ```r + # until dplyr 1.0.0 + your_data %>% mutate_if(is.mic, as.rsi) + your_data %>% mutate_if(is.disk, as.rsi) + + # since dplyr 1.0.0 + your_data %>% mutate(across(where(is.mic), as.rsi)) + your_data %>% mutate(across(where(is.disk), as.rsi)) + ``` + +# AMR 1.3.0 ### New * Function `ab_from_text()` to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 0da2ab7e..eef1dfc3 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -202,11 +202,19 @@ stop_ifnot_installed <- function(package) { return(invisible()) } -import_fn <- function(name, pkg) { - stop_ifnot_installed(pkg) +import_fn <- function(name, pkg, error_on_fail = TRUE) { + if (isTRUE(error_on_fail)) { + stop_ifnot_installed(pkg) + } tryCatch( get(name, envir = asNamespace(pkg)), - error = function(e) stop_("an error occurred in import_fn() while using this function", call = FALSE)) + error = function(e) { + if (isTRUE(error_on_fail)) { + stop_("function ", name, "() not found in package '", pkg, "'. Please contact the maintainers of the AMR package at https://github.com/msberends/AMR/issues.", call = FALSE) + } else { + return(NULL) + } + }) } stop_ <- function(..., call = TRUE) { diff --git a/R/rsi.R b/R/rsi.R index 447fc94f..db5718aa 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -21,11 +21,11 @@ #' Class 'rsi' #' -#' 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`. Invalid antimicrobial interpretations will be translated as `NA` with a warning. +#' 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`. Values that cannot be interpreted will be returned as `NA` with a warning. #' @inheritSection lifecycle Stable lifecycle #' @rdname as.rsi #' @param x vector of values (for class [`mic`]: an MIC value in mg/L, for class [`disk`]: a disk diffusion radius in millimetres) -#' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()] +#' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()], will be determined automatically if the `dplyr` package is installed #' @param ab any (vector of) text that can be coerced to a valid antimicrobial 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 search for a 'specimen' and rows containing 'urin' in that column will be regarded isolates from a UTI. See *Examples*. #' @inheritParams first_isolate @@ -34,15 +34,44 @@ #' @param threshold maximum fraction of invalid antimicrobial interpretations of `x`, please see *Examples* #' @param ... parameters passed on to methods #' @details -#' When using [as.rsi()] on untransformed data, the data will be cleaned to only contain values S, I and R. When using the function on data with class [`mic`] (using [as.mic()]) or class [`disk`] (using [as.disk()]), the data will be interpreted based on the guideline set with the `guideline` parameter. +#' ## How it works #' -#' Supported guidelines to be used as input for the `guideline` parameter are: `r paste0('"', sort(unique(AMR::rsi_translation$guideline)), '"', collapse = ", ")`. Simply using `"CLSI"` or `"EUCAST"` for input will automatically select the latest version of that guideline. +#' The [as.rsi()] function works in four ways: #' -#' 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 will in this case return "S" or "I". +#' 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. +#' +#' 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` parameter. +#' * Using `dplyr`, R/SI interpretation can be done very easily with either: +#' ``` +#' your_data %>% mutate_if(is.mic, as.rsi) # until dplyr 1.0.0 +#' your_data %>% mutate(across(where(is.mic), as.rsi)) # since dplyr 1.0.0 +#' ``` +#' * 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` parameter. +#' * Using `dplyr`, R/SI interpretation can be done very easily with either: +#' ``` +#' your_data %>% mutate_if(is.disk, as.rsi) # until dplyr 1.0.0 +#' your_data %>% mutate(across(where(is.disk), as.rsi)) # since dplyr 1.0.0 +#' ``` +#' +#' 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(data)`. +#' +#' ## Supported guidelines +#' +#' For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the `guideline` parameter are: `r paste0('"', sort(unique(AMR::rsi_translation$guideline)), '"', collapse = ", ")`. +#' +#' Simply using `"CLSI"` or `"EUCAST"` as input will automatically select the latest version of that guideline. +#' +#' ## 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. +#' +#' ## Machine readable interpretation guidelines #' #' The repository of this package [contains a machine readable version](https://github.com/msberends/AMR/blob/master/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 agent 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. #' -#' After using [as.rsi()], you can use [eucast_rules()] 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. +#' ## Other #' #' 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` parameter. #' @section Interpretation of R and S/I: @@ -59,7 +88,7 @@ #' @return Ordered factor with new class [`rsi`] #' @aliases rsi #' @export -#' @seealso [as.mic()] +#' @seealso [as.mic()], [as.disk()], [as.mo()] #' @inheritSection AMR Read more on our website! #' @examples #' summary(example_isolates) # see all R/SI results at a glance @@ -79,12 +108,12 @@ #' #' # the dplyr way #' library(dplyr) +#' df %>% mutate_at(vars(AMP:TOB), as.rsi) +#' df %>% mutate(across(AMP:TOB), as.rsi) + #' df %>% #' mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli") #' -#' df %>% -#' mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism) -#' #' # to include information about urinary tract infections (UTI) #' data.frame(mo = "E. coli", #' NIT = c("<= 2", 32), @@ -248,17 +277,42 @@ as.rsi.default <- function(x, ...) { #' @rdname as.rsi #' @export as.rsi.mic <- function(x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, conserve_capped_values = FALSE, ...) { - stop_if(missing(mo), - 'No information was supplied about the microorganisms (missing parameter "mo"). See ?as.rsi.\n\n', + + # for dplyr's across() + cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE) + if (!is.null(cur_column_dplyr)) { + # try to get current column, which will only be available when in across() + ab <- tryCatch(cur_column_dplyr(), + error = function(e) ab) + } + + # for auto-determining mo + mo_var_found <- "" + if (is.null(mo)) { + peek_mask_dplyr <- import_fn("peek_mask", "dplyr", error_on_fail = FALSE) + if (!is.null(peek_mask_dplyr)) { + try({ + df <- as.data.frame(peek_mask_dplyr()$across_cols(), stringsAsFactors = FALSE) + mo <- suppressMessages(search_type_in_df(df, "mo")) + if (!is.null(mo)) { + mo_var_found <- paste0(" based on column `", font_bold(mo), "`") + mo <- df[, mo, drop = TRUE] + } + }, silent = TRUE) + } + } + if (is.null(mo)) { + stop_('No information was supplied about the microorganisms (missing parameter "mo"). See ?as.rsi.\n\n', "To transform certain columns with e.g. mutate_at(), use\n", "`data %>% mutate_at(vars(...), as.rsi, mo = .$x)`, where x is your column with microorganisms.\n\n", "To tranform all MIC variables in a data set, use `as.rsi(data)` or `data %>% as.rsi()`.", call = FALSE) + } ab_coerced <- suppressWarnings(as.ab(ab)) mo_coerced <- suppressWarnings(as.mo(mo)) @@ -276,7 +330,8 @@ as.rsi.mic <- function(x, message(font_blue(paste0("=> Interpreting MIC values of `", font_bold(ab), "` (", ifelse(ab_coerced != ab, paste0(ab_coerced, ", "), ""), - ab_name(ab_coerced, tolower = TRUE), ") using guideline ", font_bold(guideline_coerced), " ... ")), + ab_name(ab_coerced, tolower = TRUE), ")", mo_var_found, + " according to ", font_bold(guideline_coerced), " ... ")), appendLF = FALSE) result <- exec_as.rsi(method = "mic", x = x, @@ -291,16 +346,41 @@ as.rsi.mic <- function(x, #' @rdname as.rsi #' @export as.rsi.disk <- function(x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, ...) { - stop_if(missing(mo), - 'No information was supplied about the microorganisms (missing parameter "mo"). See ?as.rsi.\n\n', + + # for dplyr's across() + cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE) + if (!is.null(cur_column_dplyr)) { + # try to get current column, which will only be available when in across() + ab <- tryCatch(cur_column_dplyr(), + error = function(e) ab) + } + + # for auto-determining mo + mo_var_found <- "" + if (is.null(mo)) { + peek_mask_dplyr <- import_fn("peek_mask", "dplyr", error_on_fail = FALSE) + if (!is.null(peek_mask_dplyr)) { + try({ + df <- as.data.frame(peek_mask_dplyr()$across_cols(), stringsAsFactors = FALSE) + mo <- suppressMessages(search_type_in_df(df, "mo")) + if (!is.null(mo)) { + mo_var_found <- paste0(" based on column `", font_bold(mo), "`") + mo <- df[, mo, drop = TRUE] + } + }, silent = TRUE) + } + } + if (is.null(mo)) { + stop_('No information was supplied about the microorganisms (missing parameter "mo"). See ?as.rsi.\n\n', "To transform certain columns with e.g. mutate_at(), use\n", "`data %>% mutate_at(vars(...), as.rsi, mo = .$x)`, where x is your column with microorganisms.\n\n", "To tranform all disk diffusion zones in a data set, use `as.rsi(data)` or `data %>% as.rsi()`.", call = FALSE) + } ab_coerced <- suppressWarnings(as.ab(ab)) mo_coerced <- suppressWarnings(as.mo(mo)) @@ -573,12 +653,21 @@ summary.rsi <- function(object, ...) { S <- sum(x == "S", na.rm = TRUE) I <- sum(x == "I", na.rm = TRUE) R <- sum(x == "R", na.rm = TRUE) + pad <- function(x) { + if (x == "0%") { + x <- " 0.0%" + } + if (nchar(x) < 5) { + x <- paste0(rep(" ", 5 - nchar(x)), x) + } + x + } value <- c( "Class" = "rsi", - "%R" = paste0(percentage(R / n), " (n=", R, ")"), - "%SI" = paste0(percentage((S + I) / n), " (n=", S + I, ")"), - "- %S" = paste0(percentage(S / n), " (n=", S, ")"), - "- %I" = paste0(percentage(I / n), " (n=", I, ")") + "%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, ")"), + "- %I" = paste0(pad(percentage(I / n, digits = 1)), " (n=", I, ")") ) class(value) <- c("summaryDefault", "table") value diff --git a/R/zzz.R b/R/zzz.R index 1bfbe11b..1856d6c5 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -29,7 +29,15 @@ envir = asNamespace("AMR")) } -# maybe add survey later: "https://www.surveymonkey.com/r/AMR_for_R" +.onAttach <- function(...) { + if (!interactive() || stats::runif(1) > 0.25 || isTRUE(as.logical(Sys.getenv("AMR_silentstart", FALSE)))) { + return() + } + packageStartupMessage("Thank you for using the AMR package! ", + "If you have a minute, please anonymously fill in this short questionnaire to improve the package and its functionalities:", + "\nhttps://msberends.github.io/AMR/survey.html", + "\n[ permanently turn this message off with: Sys.setenv(AMR_silentstart = TRUE) ]") +} create_MO_lookup <- function() { MO_lookup <- AMR::microorganisms diff --git a/docs/404.html b/docs/404.html index c7406dcc..1fc44158 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index b4be27d3..ff5e9656 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ diff --git a/docs/articles/index.html b/docs/articles/index.html index a21603d9..cd41c307 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ diff --git a/docs/articles/welcome_to_AMR.html b/docs/articles/welcome_to_AMR.html index c1837ae5..b8f30472 100644 --- a/docs/articles/welcome_to_AMR.html +++ b/docs/articles/welcome_to_AMR.html @@ -39,7 +39,7 @@ @@ -186,7 +186,7 @@vignettes/welcome_to_AMR.Rmd
welcome_to_AMR.Rmd
July 2020
+Since you are one of our users, we would like to know how you use the package and what it brought you or your organisation. If you have a minute, please anonymously fill in this short questionnaire. Your valuable input will help to improve the package and its functionalities. You can answer the open questions in either English, Spanish, French, Dutch, or German. Thank you very much in advance!
PLEASE TAKE PART IN OUR SURVEY!
-Since you are one of our users, we would like to know how you use the package and what it brought you or your organisation. If you have a minute, please anonymously fill in this short questionnaire. Your valuable input will help to improve the package and its functionalities. You can answer the open questions in either English, Spanish, French, Dutch, or German. Thank you very much in advance!
Take me to the 5-min survey!
NEWS.md
+ Support for using dplyr
’s across()
in as.rsi()
to interpret MIC values or disk zone diameters, that now also automatically determines the column with microorganism names or codes.
# until dplyr 1.0.0 +your_data %>% mutate_if(is.mic, as.rsi) +your_data %>% mutate_if(is.disk, as.rsi) + + # since dplyr 1.0.0 + your_data %>% mutate(across(where(is.mic), as.rsi)) +your_data %>% mutate(across(where(is.disk), as.rsi))
Function ab_from_text()
to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses as.ab()
internally
Tidyverse selection helpers for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows selection helpers, like dplyr::select()
and tidyr::pivot_longer()
:
library(dplyr) +-library(dplyr) # Columns 'IPM' and 'MEM' are in the example_isolates data set example_isolates %>% @@ -255,9 +281,9 @@Added parameter
conserve_capped_values
toas.rsi()
for interpreting MIC values - it makes sure that values starting with “<” (but not “<=”) will always return “S” and values starting with “>” (but not “>=”) will always return “R”. The default behaviour ofas.rsi()
has not changed, so you need to specifically doas.rsi(..., conserve_capped_values = TRUE)
.+--Changed
+Changed
Big speed improvement for using any function on microorganism codes from earlier package versions (prior to
@@ -331,9 +357,9 @@AMR
v1.2.0), such asas.mo()
,mo_name()
,first_isolate()
,eucast_rules()
,mdro()
, etc.+--Changed
+Changed
- Taxonomy:
@@ -386,9 +412,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
- Plotting biplots for principal component analysis using the new
ggplot_pca()
function+-Changed
+Changed
- Improvements for the algorithm used by
as.mo()
(and consequently allmo_*
functions, that useas.mo()
internally):@@ -420,14 +446,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
AMR 1.0.1 2020-02-23
-+-Changed
+Changed
Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline
Interpretation from MIC values (and disk zones) to R/SI can now be used with
-mutate_at()
of thedplyr
package:yourdata %>% +yourdata %>% mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli") yourdata %>% @@ -454,7 +480,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for LOINC codes in the
-antibiotics
data set. Useab_loinc()
to retrieve LOINC codes, or use a LOINC code for input in anyab_*
function:ab_loinc("ampicillin") +ab_loinc("ampicillin") #> [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5" ab_name("21066-6") #> [1] "Ampicillin" @@ -463,7 +489,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Support for SNOMED CT codes in the
-microorganisms
data set. Usemo_snomed()
to retrieve SNOMED codes, or use a SNOMED code for input in anymo_*
function:mo_snomed("S. aureus") +mo_snomed("S. aureus") #> [1] 115329001 3092008 113961008 mo_name(115329001) #> [1] "Staphylococcus aureus" @@ -526,9 +552,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/@@ -540,7 +566,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:
-+if (mo_family(somebugs) == "Enterobacteriaceae") ...if (mo_family(somebugs) == "Enterobacteriaceae") ...then please adjust this to:
-+if (mo_order(somebugs) == "Enterobacterales") ...if (mo_order(somebugs) == "Enterobacterales") ...
Functions
-susceptibility()
andresistance()
as aliases ofproportion_SI()
andproportion_R()
, respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.library(dplyr) +library(dplyr) example_isolates %>% group_by(bug = mo_name(mo)) %>% summarise(amoxicillin = resistance(AMX), @@ -567,7 +593,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/More intelligent way of coping with some consonants like “l” and “r”
Added a score (a certainty percentage) to
-mo_uncertainties()
, that is calculated using the Levenshtein distance:as.mo(c("Stafylococcus aureus", +as.mo(c("Stafylococcus aureus", "staphylokok aureuz")) #> Warning: #> Results of two values were guessed with uncertainty. Use mo_uncertainties() to review them. @@ -624,12 +650,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Determination of first isolates now excludes all ‘unknown’ microorganisms at default, i.e. microbial code
-"UNKNOWN"
. They can be included with the new parameterinclude_unknown
:+first_isolate(..., include_unknown = TRUE)first_isolate(..., include_unknown = TRUE)For WHONET users, this means that all records/isolates with organism code
"con"
(contamination) will be excluded at default, sinceas.mo("con") = "UNKNOWN"
. The function always shows a note with the number of ‘unknown’ microorganisms that were included or excluded.For code consistency, classes
-ab
andmo
will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result inNA
:# how it works in base R: +# how it works in base R: x <- factor("A") x[1] <- "B" #> Warning message: @@ -652,7 +678,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Function
-bug_drug_combinations()
to quickly get adata.frame
with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed withmo_shortname()
at default:x <- bug_drug_combinations(example_isolates) +x <- bug_drug_combinations(example_isolates) #> NOTE: Using column `mo` as input for `col_mo`. x[1:4, ] #> mo ab S I R total @@ -673,11 +699,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ #> 4 Gram-negative AMX 227 0 405 632 #> NOTE: Use 'format()' on this result to get a publicable/printable format.You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R
-format()
function:+format(x, combine_IR = FALSE)format(x, combine_IR = FALSE)Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for
-portion_*
functions orcount_*
functions. This can be used to determine the empiric susceptibility of a combination therapy. A new parameteronly_all_tested
(which defaults toFALSE
) replaces the oldalso_single_tested
and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on theportion
andcount
help pages), where the %SI is being determined:# -------------------------------------------------------------------- +# -------------------------------------------------------------------- # only_all_tested = FALSE only_all_tested = TRUE # ----------------------- ----------------------- # Drug A Drug B include as include as include as include as @@ -697,7 +723,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/-
tibble
printing support for classesrsi
,mic
,disk
,ab
mo
. When usingtibble
s containing antimicrobial columns, valuesS
will print in green, valuesI
will print in yellow and valuesR
will print in red. Microbial IDs (classmo
) will emphasise on the genus and species, not on the kingdom.# (run this on your own console, as this page does not support colour printing) +-# (run this on your own console, as this page does not support colour printing) library(dplyr) example_isolates %>% select(mo:AMC) %>% @@ -705,9 +731,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/+-Changed
+Changed
- Many algorithm improvements for
as.mo()
(of which some led to additions to themicroorganisms
data set). Many thanks to all contributors that helped improving the algorithms.@@ -778,7 +804,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Function
-rsi_df()
to transform adata.frame
to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functionscount_df()
andportion_df()
to immediately show resistance percentages and number of available isolates:septic_patients %>% +septic_patients %>% select(AMX, CIP) %>% rsi_df() # antibiotic interpretation value isolates @@ -803,7 +829,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/- UPEC (Uropathogenic E. coli)
All these lead to the microbial ID of E. coli:
-as.mo("UPEC") +-as.mo("UPEC") # B_ESCHR_COL mo_name("UPEC") # "Escherichia coli" @@ -814,9 +840,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Function
mo_synonyms()
to get all previously accepted taxonomic names of a microorganism+--Changed
+Changed
- Column names of output
count_df()
andportion_df()
are now lowercase- Fixed bug in translation of microorganism names
@@ -863,9 +889,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/- Added guidelines of the WHO to determine multi-drug resistance (MDR) for TB (
mdr_tb()
) and added a new vignette about MDR. Read this tutorial here on our website.+-Changed
+Changed
- Fixed a critical bug in
first_isolate()
where missing species would lead to incorrect FALSEs. This bug was not present in AMR v0.5.0, but was in v0.6.0 and v0.6.1.- Fixed a bug in
@@ -906,7 +932,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/eucast_rules()
where antibiotics from WHONET software would not be recognisedwhen all values are unique it now shows a message instead of a warning
support for boxplots:
-septic_patients %>% +septic_patients %>% freq(age) %>% boxplot() # grouped boxplots: @@ -948,9 +974,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/AMR 0.6.1 2019-03-29
-+-Changed
+Changed
- Fixed a critical bug when using
@@ -999,7 +1025,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/eucast_rules()
withverbose = TRUE
New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:
-filter_aminoglycosides() +filter_aminoglycosides() filter_carbapenems() filter_cephalosporins() filter_1st_cephalosporins() @@ -1011,14 +1037,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ filter_macrolides() filter_tetracyclines()The
-antibiotics
data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in theantibiotics
data set. For example:septic_patients %>% filter_glycopeptides(result = "R") +septic_patients %>% filter_glycopeptides(result = "R") # Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R septic_patients %>% filter_glycopeptides(result = "R", scope = "all") # Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is RAll
-ab_*
functions are deprecated and replaced byatc_*
functions:ab_property -> atc_property() +ab_property -> atc_property() ab_name -> atc_name() ab_official -> atc_official() ab_trivial_nl -> atc_trivial_nl() @@ -1037,17 +1063,17 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/New function
age_groups()
to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.New function
-ggplot_rsi_predict()
as well as the base Rplot()
function can now be used for resistance prediction calculated withresistance_predict()
:x <- resistance_predict(septic_patients, col_ab = "amox") +x <- resistance_predict(septic_patients, col_ab = "amox") plot(x) ggplot_rsi_predict(x)Functions
-filter_first_isolate()
andfilter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.:septic_patients %>% filter_first_isolate(...) +septic_patients %>% filter_first_isolate(...) # or filter_first_isolate(septic_patients, ...)is equal to:
--septic_patients %>% +@@ -1056,9 +1082,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/septic_patients %>% mutate(only_firsts = first_isolate(septic_patients, ...)) %>% filter(only_firsts == TRUE) %>% select(-only_firsts)New vignettes about how to conduct AMR analysis, predict antimicrobial resistance, use the G-test and more. These are also available (and even easier readable) on our website: https://msberends.gitlab.io/AMR.
+-Changed
+Changed
- Function
eucast_rules()
:@@ -1078,7 +1104,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Now handles incorrect spelling, like
-i
instead ofy
andf
instead ofph
:# mo_fullname() uses as.mo() internally +# mo_fullname() uses as.mo() internally mo_fullname("Sthafilokockus aaureuz") #> [1] "Staphylococcus aureus" @@ -1088,7 +1114,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default
-allow_uncertain = TRUE
is equal to uncertainty level 2. Run?as.mo
for more info about these levels.# equal: +# equal: as.mo(..., allow_uncertain = TRUE) as.mo(..., allow_uncertain = 2) @@ -1101,7 +1127,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/All microbial IDs that found are now saved to a local file
~/.Rhistory_mo
. Use the new functionclean_mo_history()
to delete this file, which resets the algorithms.Incoercible results will now be considered ‘unknown’, MO code
-UNKNOWN
. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:mo_genus("qwerty", language = "es") +@@ -1149,7 +1175,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/mo_genus("qwerty", language = "es") # Warning: # one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it. #> [1] "(género desconocido)"
Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
-# Determine genus of microorganisms (mo) in `septic_patients` data set: +-# Determine genus of microorganisms (mo) in `septic_patients` data set: # OLD WAY septic_patients %>% mutate(genus = mo_genus(mo)) %>% @@ -1207,9 +1233,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/- Functions
mo_authors
andmo_year
to get specific values about the scientific reference of a taxonomic entry+-Changed
+Changed
Functions
MDRO
,BRMO
,MRGN
andEUCAST_exceptional_phenotypes
were renamed tomdro
,brmo
,mrgn
andeucast_exceptional_phenotypes
- @@ -1231,7 +1257,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
EUCAST_rules
was renamed toeucast_rules
, the old function still exists as a deprecated functionFewer than 3 characters as input for
as.mo
will return NAFunction
-as.mo
(and allmo_*
wrappers) now supports genus abbreviations with “species” attachedas.mo("E. species") # B_ESCHR +@@ -1246,13 +1272,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/as.mo("E. species") # B_ESCHR mo_fullname("E. spp.") # "Escherichia species" as.mo("S. spp") # B_STPHY mo_fullname("S. species") # "Staphylococcus species"
Support for grouping variables, test with:
-septic_patients %>% +septic_patients %>% group_by(hospital_id) %>% freq(gender)Support for (un)selecting columns:
-septic_patients %>% +@@ -1330,7 +1356,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/septic_patients %>% freq(hospital_id) %>% select(-count, -cum_count) # only get item, percent, cum_percentThey also come with support for German, Dutch, French, Italian, Spanish and Portuguese:
-mo_gramstain("E. coli") +mo_gramstain("E. coli") # [1] "Gram negative" mo_gramstain("E. coli", language = "de") # German # [1] "Gramnegativ" @@ -1339,7 +1365,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ mo_fullname("S. group A", language = "pt") # Portuguese # [1] "Streptococcus grupo A"Furthermore, former taxonomic names will give a note about the current taxonomic name:
-mo_gramstain("Esc blattae") +@@ -1352,14 +1378,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/mo_gramstain("Esc blattae") # Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010) # [1] "Gram negative"Function
is.rsi.eligible
to check for columns that have valid antimicrobial results, but do not have thersi
class yet. Transform the columns of your raw data with:data %>% mutate_if(is.rsi.eligible, as.rsi)
Functions
-as.mo
andis.mo
as replacements foras.bactid
andis.bactid
(since themicrooganisms
data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. Theas.mo
function determines microbial IDs using intelligent rules:as.mo("E. coli") +as.mo("E. coli") # [1] B_ESCHR_COL as.mo("MRSA") # [1] B_STPHY_AUR as.mo("S group A") # [1] B_STRPTC_GRAAnd with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:
-thousands_of_E_colis <- rep("E. coli", 25000) +-thousands_of_E_colis <- rep("E. coli", 25000) microbenchmark::microbenchmark(as.mo(thousands_of_E_colis), unit = "s") # Unit: seconds # min median max neval @@ -1384,14 +1410,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Renamed
septic_patients$sex
toseptic_patients$gender
+-Changed
+Changed
Added three antimicrobial agents to the
antibiotics
data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)Added 163 trade names to the
-antibiotics
data set, it now contains 298 different trade names in total, e.g.:ab_official("Bactroban") +ab_official("Bactroban") # [1] "Mupirocin" ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin" @@ -1406,7 +1432,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Added parameters
minimum
andas_percent
toportion_df
Support for quasiquotation in the functions series
-count_*
andportions_*
, andn_rsi
. This allows to check for more than 2 vectors or columns.septic_patients %>% select(amox, cipr) %>% count_IR() +septic_patients %>% select(amox, cipr) %>% count_IR() # which is the same as: septic_patients %>% count_IR(amox, cipr) @@ -1424,10 +1450,10 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Added longest en shortest character length in the frequency table (
freq
) header of classcharacter
Support for types (classes) list and matrix for
-freq
@@ -232,7 +232,7 @@my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2)) +For lists, subsetting is possible:
--my_list = list(age = septic_patients$age, gender = septic_patients$gender) +@@ -1518,9 +1544,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/my_list = list(age = septic_patients$age, gender = septic_patients$gender) my_list %>% freq(age) my_list %>% freq(gender)+diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html index 2da18763..dd5aa03d 100644 --- a/docs/reference/as.rsi.html +++ b/docs/reference/as.rsi.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@--Changed
+Changed
- Improvements for forecasting with
resistance_predict
and added more examples- More antibiotics added as parameters for EUCAST rules
@@ -1604,9 +1630,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/- New print format for
tibble
s anddata.table
s+diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index a11a7225..89538a06 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -82,7 +82,7 @@diff --git a/docs/reference/ab_property.html b/docs/reference/ab_property.html index 5c80b836..cef70dd1 100644 --- a/docs/reference/ab_property.html +++ b/docs/reference/ab_property.html @@ -82,7 +82,7 @@-Changed
+Changed
- Fixed
rsi
class for vectors that contain only invalid antimicrobial interpretations- Renamed dataset
ablist
toantibiotics
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index f6e59365..7dfb87c0 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -11,7 +11,7 @@ articles: benchmarks: benchmarks.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2020-07-31T09:39Z +last_built: 2020-08-10T09:44Z urls: reference: https://msberends.github.io/AMR/reference article: https://msberends.github.io/AMR/articles diff --git a/docs/reference/ab_from_text.html b/docs/reference/ab_from_text.html index f68c2870..65336ffa 100644 --- a/docs/reference/ab_from_text.html +++ b/docs/reference/ab_from_text.html @@ -82,7 +82,7 @@-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 levelsS < I < R
. Invalid antimicrobial interpretations will be translated asNA
with a warning.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 levelsS < I < R
. Values that cannot be interpreted will be returned asNA
with a warning.as.rsi(x, ...) @@ -244,7 +244,7 @@ # S3 method for mic as.rsi( x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, @@ -255,7 +255,7 @@ # S3 method for disk as.rsi( x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, @@ -289,7 +289,7 @@mo -+ any (vector of) text that can be coerced to a valid microorganism code with
as.mo()
any (vector of) text that can be coerced to a valid microorganism code with
as.mo()
, will be determined automatically if thedplyr
package is installedab @@ -318,12 +318,46 @@Ordered factor with new class
rsi
Details
-When using
-as.rsi()
on untransformed data, the data will be cleaned to only contain values S, I and R. When using the function on data with classmic
(usingas.mic()
) or classdisk
(usingas.disk()
), the data will be interpreted based on the guideline set with theguideline
parameter.Supported guidelines to be used as input for the
-guideline
parameter are: "CLSI 2010", "CLSI 2011", "CLSI 2012", "CLSI 2013", "CLSI 2014", "CLSI 2015", "CLSI 2016", "CLSI 2017", "CLSI 2018", "CLSI 2019", "EUCAST 2011", "EUCAST 2012", "EUCAST 2013", "EUCAST 2014", "EUCAST 2015", "EUCAST 2016", "EUCAST 2017", "EUCAST 2018", "EUCAST 2019", "EUCAST 2020". Simply using"CLSI"
or"EUCAST"
for input will automatically select the latest version of that guideline.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 will in this case return "S" or "I".How it works
+ + +The
as.rsi()
function works in four ways:+
+ + +- +
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 returnNA
with a warning that the input is unclear.- +
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 classmic
. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using themo
parameter.+
- +
Using
dplyr
, R/SI interpretation can be done very easily with either:your_data %>% mutate_if(is.mic, as.rsi) # until dplyr 1.0.0 +your_data %>% mutate(across(where(is.mic), as.rsi)) # since dplyr 1.0.0- +
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".- +
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 classdisk
. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using themo
parameter.- +
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(data)
.Supported guidelines
+ + +For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the
+guideline
parameter are: "CLSI 2010", "CLSI 2011", "CLSI 2012", "CLSI 2013", "CLSI 2014", "CLSI 2015", "CLSI 2016", "CLSI 2017", "CLSI 2018", "CLSI 2019", "EUCAST 2011", "EUCAST 2012", "EUCAST 2013", "EUCAST 2014", "EUCAST 2015", "EUCAST 2016", "EUCAST 2017", "EUCAST 2018", "EUCAST 2019", "EUCAST 2020".Simply using
+ +"CLSI"
or"EUCAST"
as input will automatically select the latest version of that guideline.After interpretation
+ + +After using
+ +as.rsi()
, you can use theeucast_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 of all guidelines. This is a CSV file consisting of 18,650 rows and 10 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 agent 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.
-After using
+ +as.rsi()
, you can useeucast_rules()
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.Other
+ +The function
+is.rsi.eligible()
returnsTRUE
when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), andFALSE
otherwise. The threshold of 5% can be set with thethreshold
parameter.Interpretation of R and S/I
@@ -352,7 +386,7 @@ The lifecycle of this function is stableOn our website https://msberends.github.io/AMR you can find a comprehensive tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey!See also
- +Examples
summary(example_isolates) # see all R/SI results at a glance @@ -372,12 +406,11 @@ The lifecycle of this function is stable# the dplyr way library(dplyr) +df %>% mutate_at(vars(AMP:TOB), as.rsi) +df %>% mutate(across(AMP:TOB), as.rsi) df %>% mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli") -df %>% - mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism) - # to include information about urinary tract infections (UTI) data.frame(mo = "E. coli", NIT = c("<= 2", 32), diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 7659109f..d9a2e3e6 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ diff --git a/docs/reference/ggplot_pca.html b/docs/reference/ggplot_pca.html index 65b1d481..b4e3c2bd 100644 --- a/docs/reference/ggplot_pca.html +++ b/docs/reference/ggplot_pca.html @@ -82,7 +82,7 @@ diff --git a/docs/reference/index.html b/docs/reference/index.html index 0e77a34c..6b904191 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index dcd0ebc7..c30b1f31 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -82,7 +82,7 @@ diff --git a/docs/survey.html b/docs/survey.html index ffa8ea1a..4bff0f97 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ diff --git a/index.md b/index.md index 9f27cb2d..6da490e1 100644 --- a/index.md +++ b/index.md @@ -3,6 +3,8 @@ > *July 2020*
> **PLEASE TAKE PART IN OUR SURVEY!** > Since you are one of our users, we would like to know how you use the package and what it brought you or your organisation. **If you have a minute, please [anonymously fill in this short questionnaire](./survey.html)**. Your valuable input will help to improve the package and its functionalities. You can answer the open questions in either English, Spanish, French, Dutch, or German. Thank you very much in advance! +>
+> Take me to the 5-min survey! ### What is `AMR` (for R)? diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd index ecb69c42..fa9827f9 100755 --- a/man/as.rsi.Rd +++ b/man/as.rsi.Rd @@ -18,7 +18,7 @@ is.rsi.eligible(x, threshold = 0.05) \method{as.rsi}{mic}( x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, @@ -28,7 +28,7 @@ is.rsi.eligible(x, threshold = 0.05) \method{as.rsi}{disk}( x, - mo, + mo = NULL, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, @@ -51,7 +51,7 @@ is.rsi.eligible(x, threshold = 0.05) \item{threshold}{maximum fraction of invalid antimicrobial interpretations of \code{x}, please see \emph{Examples}} -\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}} +\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}, will be determined automatically if the \code{dplyr} package is installed} \item{ab}{any (vector of) text that can be coerced to a valid antimicrobial code with \code{\link[=as.ab]{as.ab()}}} @@ -67,21 +67,53 @@ is.rsi.eligible(x, threshold = 0.05) Ordered factor with new class \code{\link{rsi}} } \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 factor with levels \verb{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning. +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 factor with levels \verb{S < I < R}. Values that cannot be interpreted will be returned as \code{NA} with a warning. } \details{ -When using \code{\link[=as.rsi]{as.rsi()}} on untransformed data, the data will be cleaned to only contain values S, I and R. When using the function on data with class \code{\link{mic}} (using \code{\link[=as.mic]{as.mic()}}) or class \code{\link{disk}} (using \code{\link[=as.disk]{as.disk()}}), the data will be interpreted based on the guideline set with the \code{guideline} parameter. +\subsection{How it works}{ -Supported guidelines to be used as input for the \code{guideline} parameter are: "CLSI 2010", "CLSI 2011", "CLSI 2012", "CLSI 2013", "CLSI 2014", "CLSI 2015", "CLSI 2016", "CLSI 2017", "CLSI 2018", "CLSI 2019", "EUCAST 2011", "EUCAST 2012", "EUCAST 2013", "EUCAST 2014", "EUCAST 2015", "EUCAST 2016", "EUCAST 2017", "EUCAST 2018", "EUCAST 2019", "EUCAST 2020". Simply using \code{"CLSI"} or \code{"EUCAST"} for input will automatically select the latest version of that guideline. +The \code{\link[=as.rsi]{as.rsi()}} 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{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} parameter. +\itemize{ +\item Using \code{dplyr}, R/SI interpretation can be done very easily with either:\preformatted{your_data \%>\% mutate_if(is.mic, as.rsi) # until dplyr 1.0.0 +your_data \%>\% mutate(across(where(is.mic), as.rsi)) # since dplyr 1.0.0 +} +\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} parameter. +\itemize{ +\item Using \code{dplyr}, R/SI interpretation can be done very easily with either:\preformatted{your_data \%>\% mutate_if(is.disk, as.rsi) # until dplyr 1.0.0 +your_data \%>\% mutate(across(where(is.disk), as.rsi)) # since dplyr 1.0.0 +} +} +\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(data)}. +} +} -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 will in this case return "S" or "I". +\subsection{Supported guidelines}{ + +For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the \code{guideline} parameter are: "CLSI 2010", "CLSI 2011", "CLSI 2012", "CLSI 2013", "CLSI 2014", "CLSI 2015", "CLSI 2016", "CLSI 2017", "CLSI 2018", "CLSI 2019", "EUCAST 2011", "EUCAST 2012", "EUCAST 2013", "EUCAST 2014", "EUCAST 2015", "EUCAST 2016", "EUCAST 2017", "EUCAST 2018", "EUCAST 2019", "EUCAST 2020". + +Simply using \code{"CLSI"} or \code{"EUCAST"} as input will automatically select the latest version of that guideline. +} + +\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. +} + +\subsection{Machine readable interpretation guidelines}{ The repository of this package \href{https://github.com/msberends/AMR/blob/master/data-raw/rsi_translation.txt}{contains a machine readable version} of all guidelines. This is a CSV file consisting of 18,650 rows and 10 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 agent 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. +} -After using \code{\link[=as.rsi]{as.rsi()}}, you can use \code{\link[=eucast_rules]{eucast_rules()}} 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{Other}{ 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} parameter. } +} \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 (\url{http://www.eucast.org/newsiandr/}). @@ -128,12 +160,11 @@ as.rsi(df) # the dplyr way library(dplyr) +df \%>\% mutate_at(vars(AMP:TOB), as.rsi) +df \%>\% mutate(across(AMP:TOB), as.rsi) df \%>\% mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli") -df \%>\% - mutate_at(vars(AMP:TOB), as.rsi, mo = .$microorganism) - # to include information about urinary tract infections (UTI) data.frame(mo = "E. coli", NIT = c("<= 2", 32), @@ -190,5 +221,5 @@ is.rsi.eligible(WHONET$`First name`, threshold = 0.99) # succeeds } } \seealso{ -\code{\link[=as.mic]{as.mic()}} +\code{\link[=as.mic]{as.mic()}}, \code{\link[=as.disk]{as.disk()}}, \code{\link[=as.mo]{as.mo()}} } diff --git a/pkgdown/extra.css b/pkgdown/extra.css index 5cc5b30c..10dadf1a 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -237,3 +237,16 @@ table a:not(.btn):hover, .table a:not(.btn):hover { color: black; font-weight: bold; } + +.btn.btn-info.btn-amr { + background: #128f76; + color: #ffffff; + border-color: #128f76; + line-height: 1; + width: 100%; + font-weight: bold; +} +.btn.btn-info.btn-amr:hover { + background: #128f7645; + color: #2c3e50; +} diff --git a/pkgdown/logos/countries.png b/pkgdown/logos/countries.png index a6e82d12..12d05988 100644 Binary files a/pkgdown/logos/countries.png and b/pkgdown/logos/countries.png differ diff --git a/pkgdown/logos/countries_large.png b/pkgdown/logos/countries_large.png index 0a5cd21f..3ddd6ed3 100644 Binary files a/pkgdown/logos/countries_large.png and b/pkgdown/logos/countries_large.png differ diff --git a/tests/testthat/test-rsi.R b/tests/testthat/test-rsi.R index 11ac1143..2dc37a0c 100644 --- a/tests/testthat/test-rsi.R +++ b/tests/testthat/test-rsi.R @@ -39,10 +39,10 @@ test_that("rsi works", { expect_equal(summary(as.rsi(c("S", "R"))), structure(c("Class" = "rsi", - "%R" = "50% (n=1)", - "%SI" = "50% (n=1)", - "- %S" = "50% (n=1)", - "- %I" = "0% (n=0)"), class = c("summaryDefault", "table"))) + "%R" = "50.0% (n=1)", + "%SI" = "50.0% (n=1)", + "- %S" = "50.0% (n=1)", + "- %I" = " 0.0% (n=0)"), class = c("summaryDefault", "table"))) expect_identical(as.logical(lapply(example_isolates, is.rsi.eligible)), rep(FALSE, length(example_isolates)))