mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 03:40:48 +01:00
(v3.0.1.9137) Add the guideline argument to count_df(), proportion_df(), sir_df(), ggplot_sir(), geom_sir(), and labels_sir_count(), so that with CLSI the 'I' category is merged with R, and describe in the documentation of get_AMR_locale() that LANG takes precedence over LANGUAGE
This commit is contained in:
1 parent
46f5de1d36
commit
dbd95ffa46
17 files changed
+118
-40
No files matched your search
@@ -267,7 +267,8 @@ n_sir <- count_all
|
||||
count_df <- function(data,
|
||||
translate_ab = "name",
|
||||
language = get_AMR_locale(),
|
||||
combine_SI = TRUE) {
|
||||
combine_SI = TRUE,
|
||||
guideline = getOption("AMR_guideline", "EUCAST")) {
|
||||
tryCatch(
|
||||
sir_calc_df(
|
||||
type = "count",
|
||||
@@ -275,7 +276,8 @@ count_df <- function(data,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
combine_SI = combine_SI,
|
||||
confidence_level = 0.95 # doesn't matter, will be removed
|
||||
confidence_level = 0.95, # doesn't matter, will be removed
|
||||
guideline = guideline
|
||||
),
|
||||
error = function(e) stop_(gsub("in sir_calc_df(): ", "", conditionMessage(e), fixed = TRUE), call = -5)
|
||||
)
|
||||
|
||||
+6
-2
@@ -174,6 +174,7 @@ ggplot_sir <- function(data,
|
||||
combine_SI = TRUE,
|
||||
minimum = 30,
|
||||
language = get_AMR_locale(),
|
||||
guideline = getOption("AMR_guideline", "EUCAST"),
|
||||
nrow = NULL,
|
||||
colours = c(
|
||||
S = "#3CAEA3",
|
||||
@@ -242,7 +243,7 @@ ggplot_sir <- function(data,
|
||||
geom_sir(
|
||||
position = position, x = x, fill = fill, translate_ab = translate_ab,
|
||||
minimum = minimum, language = language,
|
||||
combine_SI = combine_SI, ...
|
||||
combine_SI = combine_SI, guideline = guideline, ...
|
||||
) +
|
||||
theme_sir()
|
||||
|
||||
@@ -263,6 +264,7 @@ ggplot_sir <- function(data,
|
||||
minimum = minimum,
|
||||
language = language,
|
||||
combine_SI = combine_SI,
|
||||
guideline = guideline,
|
||||
datalabels.size = datalabels.size,
|
||||
datalabels.colour = datalabels.colour
|
||||
)
|
||||
@@ -292,6 +294,7 @@ geom_sir <- function(position = NULL,
|
||||
minimum = 30,
|
||||
language = get_AMR_locale(),
|
||||
combine_SI = TRUE,
|
||||
guideline = getOption("AMR_guideline", "EUCAST"),
|
||||
...) {
|
||||
x <- x[1]
|
||||
stop_ifnot_installed("ggplot2")
|
||||
@@ -334,7 +337,8 @@ geom_sir <- function(position = NULL,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
minimum = minimum,
|
||||
combine_SI = combine_SI
|
||||
combine_SI = combine_SI,
|
||||
guideline = guideline
|
||||
)
|
||||
},
|
||||
mapping = utils::modifyList(ggplot2::aes(), list(x = str2lang(x), y = str2lang(y), fill = str2lang(fill))),
|
||||
|
||||
+3
-1
@@ -1554,6 +1554,7 @@ labels_sir_count <- function(position = NULL,
|
||||
minimum = 30,
|
||||
language = get_AMR_locale(),
|
||||
combine_SI = TRUE,
|
||||
guideline = getOption("AMR_guideline", "EUCAST"),
|
||||
datalabels.size = 3,
|
||||
datalabels.colour = "grey15") {
|
||||
stop_ifnot_installed("ggplot2")
|
||||
@@ -1587,7 +1588,8 @@ labels_sir_count <- function(position = NULL,
|
||||
translate_ab = translate_ab,
|
||||
combine_SI = combine_SI,
|
||||
minimum = minimum,
|
||||
language = language
|
||||
language = language,
|
||||
guideline = guideline
|
||||
)
|
||||
transformed$gr <- transformed[, x_name, drop = TRUE]
|
||||
transformed %pm>%
|
||||
|
||||
+6
-4
@@ -42,9 +42,9 @@
|
||||
#' * EUCAST: [susceptibility()] \eqn{= \%S + \%I}, [resistance()] \eqn{= \%R}
|
||||
#' * CLSI: [susceptibility()] \eqn{= \%S + \%SDD}, [resistance()] \eqn{= \%I + \%R}
|
||||
#'
|
||||
#' You can also use e.g. [proportion_R()] or [proportion_S()] instead, to be explicit.
|
||||
#' You can also use e.g. [proportion_R()] or [proportion_S()] instead, to be explicit. For [proportion_df()], [count_df()], and [sir_df()], the guideline determines how 'I' is merged when `combine_SI = TRUE`.
|
||||
#' @inheritParams ab_property
|
||||
#' @param combine_SI A [logical] to indicate whether all values of S, SDD, and I must be merged into one, so the output only consists of S+SDD+I vs. R (susceptible vs. resistant) - the default is `TRUE`.
|
||||
#' @param combine_SI A [logical] to indicate whether the 'I' category must be merged with another category, so the output only consists of susceptible vs. resistant - the default is `TRUE`. Following the `guideline` argument, the output then consists of `"SI"` (S+SDD+I) vs. `"R"` with EUCAST, and of `"S"` (S+SDD) vs. `"IR"` (I+R) with CLSI.
|
||||
#' @param ab_result Antibiotic results to test against, must be one or more values of "S", "SDD", "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. The default is `"both"` for a length 2 vector, but can also be (abbreviated as) `"min"`/`"left"`/`"lower"`/`"less"` or `"max"`/`"right"`/`"higher"`/`"greater"`.
|
||||
@@ -431,7 +431,8 @@ proportion_df <- function(data,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
combine_SI = TRUE,
|
||||
confidence_level = 0.95) {
|
||||
confidence_level = 0.95,
|
||||
guideline = getOption("AMR_guideline", "EUCAST")) {
|
||||
tryCatch(
|
||||
sir_calc_df(
|
||||
type = "proportion",
|
||||
@@ -441,7 +442,8 @@ proportion_df <- function(data,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
combine_SI = combine_SI,
|
||||
confidence_level = confidence_level
|
||||
confidence_level = confidence_level,
|
||||
guideline = guideline
|
||||
),
|
||||
error = function(e) stop_(gsub("in sir_calc_df(): ", "", conditionMessage(e), fixed = TRUE), call = -5)
|
||||
)
|
||||
|
||||
+17
-5
@@ -220,7 +220,8 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
combine_SI = TRUE,
|
||||
confidence_level = 0.95) {
|
||||
confidence_level = 0.95,
|
||||
guideline = getOption("AMR_guideline", "EUCAST")) {
|
||||
meet_criteria(type, is_in = c("proportion", "count", "both"), has_length = 1)
|
||||
meet_criteria(data, allow_class = "data.frame")
|
||||
data <- ascertain_sir_classes(data, "data")
|
||||
@@ -230,6 +231,15 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
||||
meet_criteria(as_percent, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(combine_SI, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(confidence_level, allow_class = "numeric", has_length = 1)
|
||||
meet_criteria(guideline, allow_class = "character", has_length = 1)
|
||||
if (guideline %like% "EUCAST") {
|
||||
guideline <- "EUCAST"
|
||||
} else if (guideline %like% "CLSI") {
|
||||
guideline <- "CLSI"
|
||||
}
|
||||
meet_criteria(guideline, allow_class = "character", is_in = c("EUCAST", "CLSI"), has_length = 1)
|
||||
# with EUCAST, 'I' is merged with S into 'SI', with CLSI, 'I' is merged with R into 'IR'
|
||||
combined_levels <- if (identical(guideline, "CLSI")) c("S", "IR") else c("SI", "R")
|
||||
|
||||
translate_ab <- get_translate_ab(translate_ab)
|
||||
|
||||
@@ -252,10 +262,12 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
||||
data[, i] <- as.character(as.sir(data[, i, drop = TRUE]))
|
||||
data[which(data[, i, drop = TRUE] %in% c("S", "SDD", "WT")), i] <- "S"
|
||||
data[which(data[, i, drop = TRUE] %in% c("R", "NWT", "NS")), i] <- "R"
|
||||
if (isTRUE(combine_SI)) {
|
||||
if (isTRUE(combine_SI) && identical(guideline, "CLSI")) {
|
||||
data[which(data[, i, drop = TRUE] %in% c("I", "R")), i] <- "IR"
|
||||
} else if (isTRUE(combine_SI)) {
|
||||
data[which(data[, i, drop = TRUE] %in% c("I", "S")), i] <- "SI"
|
||||
}
|
||||
data[which(!data[, i, drop = TRUE] %in% c("S", "SI", "I", "R")), i] <- NA_character_
|
||||
data[which(!data[, i, drop = TRUE] %in% c("S", "SI", "I", "IR", "R")), i] <- NA_character_
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +289,7 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
||||
for (i in seq_len(ncol(.data))) {
|
||||
values <- .data[, i, drop = TRUE]
|
||||
if (isTRUE(combine_SI)) {
|
||||
values <- factor(values, levels = c("SI", "R", "NI"), ordered = TRUE)
|
||||
values <- factor(values, levels = c(combined_levels, "NI"), ordered = TRUE)
|
||||
} else {
|
||||
values <- factor(values, levels = c("S", "SDD", "I", "R", "NI"), ordered = TRUE)
|
||||
}
|
||||
@@ -352,7 +364,7 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
||||
|
||||
# apply factors for right sorting in interpretation
|
||||
if (isTRUE(combine_SI)) {
|
||||
out$interpretation <- factor(out$interpretation, levels = c("SI", "R"), ordered = TRUE)
|
||||
out$interpretation <- factor(out$interpretation, levels = combined_levels, ordered = TRUE)
|
||||
} else {
|
||||
# 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
|
||||
|
||||
+4
-2
@@ -35,7 +35,8 @@ sir_df <- function(data,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
combine_SI = TRUE,
|
||||
confidence_level = 0.95) {
|
||||
confidence_level = 0.95,
|
||||
guideline = getOption("AMR_guideline", "EUCAST")) {
|
||||
tryCatch(
|
||||
sir_calc_df(
|
||||
type = "both",
|
||||
@@ -45,7 +46,8 @@ sir_df <- function(data,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
combine_SI = combine_SI,
|
||||
confidence_level = confidence_level
|
||||
confidence_level = confidence_level,
|
||||
guideline = guideline
|
||||
),
|
||||
error = function(e) stop_(gsub("in sir_calc_df(): ", "", conditionMessage(e), fixed = TRUE), call = -5)
|
||||
)
|
||||
|
||||
+7
-5
@@ -49,14 +49,16 @@
|
||||
#' Please read about adding or updating a language in [our Wiki](https://github.com/msberends/AMR/wiki/).
|
||||
#'
|
||||
#' ### Changing the Default Language
|
||||
#' The system language will be used at default (as returned by `Sys.getenv("LANG")` or, if `LANG` is not set, [`Sys.getlocale("LC_COLLATE")`][Sys.getlocale()]), if that language is supported. But the language to be used can be overwritten in two ways and will be checked in this order:
|
||||
#' The system language will be used at default, if that language is supported. The language to be used is determined in this order:
|
||||
#'
|
||||
#' 1. Setting the package option [`AMR_locale`][AMR-options], either by using e.g. `set_AMR_locale("German")` or by running e.g. `options(AMR_locale = "German")`.
|
||||
#' 1. The package option [`AMR_locale`][AMR-options], set by using e.g. `set_AMR_locale("German")` or by running e.g. `options(AMR_locale = "German")`.
|
||||
#'
|
||||
#' Note that setting an \R option only works in the same session. Save the command `options(AMR_locale = "(your language)")` to your `.Rprofile` file to apply it for every session. Run `utils::file.edit("~/.Rprofile")` to edit your `.Rprofile` file.
|
||||
#' 2. Setting the system variable `LANGUAGE` or `LANG`, e.g. by adding `LANGUAGE="de_DE.utf8"` to your `.Renviron` file in your home directory.
|
||||
#' 2. The system variable `LANG`, as returned by `Sys.getenv("LANG")`, e.g. set by adding `LANG="de_DE.utf8"` to your `.Renviron` file in your home directory.
|
||||
#' 3. The system variable `LANGUAGE`, but only if `LANG` is not set. Note that `LANG` is set on most Linux and macOS systems, in which case `LANGUAGE` has no effect.
|
||||
#' 4. The system locale, as returned by [`Sys.getlocale("LC_COLLATE")`][Sys.getlocale()], if neither `LANG` nor `LANGUAGE` is set.
|
||||
#'
|
||||
#' Thus, if the package option [`AMR_locale`][AMR-options] is set, the system variables `LANGUAGE` and `LANG` will be ignored.
|
||||
#' Thus, if the package option [`AMR_locale`][AMR-options] is set, the system variables `LANG` and `LANGUAGE` will be ignored.
|
||||
#' @rdname translate
|
||||
#' @name translate
|
||||
#' @export
|
||||
@@ -90,7 +92,7 @@ get_AMR_locale <- function() {
|
||||
return(validate_language(getOption("AMR_locale"), extra_txt = "set with `options(AMR_locale = ...)`"))
|
||||
}
|
||||
lang <- ""
|
||||
# now check the LANGUAGE system variable - return it if set
|
||||
# now check the system variables, of which LANG takes precedence over LANGUAGE
|
||||
if (!identical("", Sys.getenv("LANGUAGE"))) {
|
||||
lang <- Sys.getenv("LANGUAGE")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user