mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 05:26:13 +01:00
(v1.8.1.9004) fix for table() on MICs
This commit is contained in:
parent
1c891cc90c
commit
d4e22069bc
@ -1,5 +1,5 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 1.8.1.9003
|
Version: 1.8.1.9004
|
||||||
Date: 2022-05-09
|
Date: 2022-05-09
|
||||||
Title: Antimicrobial Resistance Data Analysis
|
Title: Antimicrobial Resistance Data Analysis
|
||||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
|||||||
# `AMR` 1.8.1.9003
|
# `AMR` 1.8.1.9004
|
||||||
## <small>Last updated: 9 May 2022</small>
|
## <small>Last updated: 9 May 2022</small>
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
17
R/mic.R
17
R/mic.R
@ -47,7 +47,7 @@ valid_mic_levels <- c(c(t(vapply(FUN.VALUE = character(9), ops,
|
|||||||
#' @rdname as.mic
|
#' @rdname as.mic
|
||||||
#' @param x a [character] or [numeric] vector
|
#' @param x a [character] or [numeric] vector
|
||||||
#' @param na.rm a [logical] indicating whether missing values should be removed
|
#' @param na.rm a [logical] indicating whether missing values should be removed
|
||||||
#' @details To interpret MIC values as RSI values, use [as.rsi()] on MIC values. It supports guidelines from EUCAST and CLSI.
|
#' @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)))`).
|
||||||
#'
|
#'
|
||||||
#' 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:
|
#' 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:
|
||||||
#'
|
#'
|
||||||
@ -86,6 +86,10 @@ valid_mic_levels <- c(c(t(vapply(FUN.VALUE = character(9), ops,
|
|||||||
#' ```
|
#' ```
|
||||||
#'
|
#'
|
||||||
#' The following [generic functions][groupGeneric()] are implemented for the MIC class: `!`, `!=`, `%%`, `%/%`, `&`, `*`, `+`, `-`, `/`, `<`, `<=`, `==`, `>`, `>=`, `^`, `|`, [abs()], [acos()], [acosh()], [all()], [any()], [asin()], [asinh()], [atan()], [atanh()], [ceiling()], [cos()], [cosh()], [cospi()], [cummax()], [cummin()], [cumprod()], [cumsum()], [digamma()], [exp()], [expm1()], [floor()], [gamma()], [lgamma()], [log()], [log1p()], [log2()], [log10()], [max()], [mean()], [min()], [prod()], [range()], [round()], [sign()], [signif()], [sin()], [sinh()], [sinpi()], [sqrt()], [sum()], [tan()], [tanh()], [tanpi()], [trigamma()] and [trunc()]. Some functions of the `stats` package are also implemented: [median()], [quantile()], [mad()], [IQR()], [fivenum()]. Also, [boxplot.stats()] is supported. Since [sd()] and [var()] are non-generic functions, these could not be extended. Use [mad()] as an alternative, or use e.g. `sd(as.numeric(x))` where `x` is your vector of MIC values.
|
#' The following [generic functions][groupGeneric()] are implemented for the MIC class: `!`, `!=`, `%%`, `%/%`, `&`, `*`, `+`, `-`, `/`, `<`, `<=`, `==`, `>`, `>=`, `^`, `|`, [abs()], [acos()], [acosh()], [all()], [any()], [asin()], [asinh()], [atan()], [atanh()], [ceiling()], [cos()], [cosh()], [cospi()], [cummax()], [cummin()], [cumprod()], [cumsum()], [digamma()], [exp()], [expm1()], [floor()], [gamma()], [lgamma()], [log()], [log1p()], [log2()], [log10()], [max()], [mean()], [min()], [prod()], [range()], [round()], [sign()], [signif()], [sin()], [sinh()], [sinpi()], [sqrt()], [sum()], [tan()], [tanh()], [tanpi()], [trigamma()] and [trunc()]. Some functions of the `stats` package are also implemented: [median()], [quantile()], [mad()], [IQR()], [fivenum()]. Also, [boxplot.stats()] is supported. Since [sd()] and [var()] are non-generic functions, these could not be extended. Use [mad()] as an alternative, or use e.g. `sd(as.numeric(x))` where `x` is your vector of MIC values.
|
||||||
|
#'
|
||||||
|
#' Using [as.double()] or [as.numeric()] on MIC values will remove the operators and return a numeric vector. Do **not** use [as.integer()] on MIC values as by the \R convention on [factor]s, it will return the index of the factor levels (which is often useless for regular users).
|
||||||
|
#'
|
||||||
|
#' Use [droplevels()] to drop unused levels. At default, it will return a plain factor. Use `droplevels(..., as.mic = TRUE)` to maintain the `<mic>` class.
|
||||||
#' @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.
|
#' @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
|
#' @aliases mic
|
||||||
#' @export
|
#' @export
|
||||||
@ -196,7 +200,8 @@ all_valid_mics <- function(x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#' @rdname as.mic
|
#' @rdname as.mic
|
||||||
#' @details `NA_mic_` is a missing value of the new `<mic>` class.
|
#' @details `NA_mic_` is a missing value of the new `<mic>` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
|
||||||
|
#' @format NULL
|
||||||
#' @export
|
#' @export
|
||||||
NA_mic_ <- set_clean_class(factor(NA, levels = valid_mic_levels, ordered = TRUE),
|
NA_mic_ <- set_clean_class(factor(NA, levels = valid_mic_levels, ordered = TRUE),
|
||||||
new_class = c("mic", "ordered", "factor"))
|
new_class = c("mic", "ordered", "factor"))
|
||||||
@ -221,9 +226,11 @@ as.numeric.mic <- function(x, ...) {
|
|||||||
as.numeric(gsub("[<=>]+", "", as.character(x), perl = TRUE))
|
as.numeric(gsub("[<=>]+", "", as.character(x), perl = TRUE))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' @rdname as.mic
|
||||||
#' @method droplevels mic
|
#' @method droplevels mic
|
||||||
|
#' @param exclude factor levels which should be excluded from the result even if present, see [droplevels()][base::droplevels()]
|
||||||
|
#' @param as.mic a [logical] to indicate whether the `<mic>` class should be kept, defaults to `FALSE`
|
||||||
#' @export
|
#' @export
|
||||||
#' @noRd
|
|
||||||
droplevels.mic <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA, as.mic = FALSE, ...) {
|
droplevels.mic <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA, as.mic = FALSE, ...) {
|
||||||
x <- droplevels.factor(x, exclude = exclude, ...)
|
x <- droplevels.factor(x, exclude = exclude, ...)
|
||||||
if (as.mic == TRUE) {
|
if (as.mic == TRUE) {
|
||||||
@ -253,7 +260,9 @@ type_sum.mic <- function(x, ...) {
|
|||||||
#' @export
|
#' @export
|
||||||
#' @noRd
|
#' @noRd
|
||||||
print.mic <- function(x, ...) {
|
print.mic <- function(x, ...) {
|
||||||
cat("Class <mic>\n")
|
cat("Class <mic>",
|
||||||
|
ifelse(length(levels(x)) < length(valid_mic_levels), font_red(" with dropped levels"), ""),
|
||||||
|
"\n", sep = "")
|
||||||
print(as.character(x), quote = FALSE)
|
print(as.character(x), quote = FALSE)
|
||||||
att <- attributes(x)
|
att <- attributes(x)
|
||||||
if ("na.action" %in% names(att)) {
|
if ("na.action" %in% names(att)) {
|
||||||
|
6
R/rsi.R
6
R/rsi.R
@ -33,7 +33,7 @@
|
|||||||
#' @param ab any (vector of) text that can be coerced to a valid antimicrobial code with [as.ab()]
|
#' @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 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.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*.
|
||||||
#' @inheritParams first_isolate
|
#' @inheritParams first_isolate
|
||||||
#' @param guideline defaults to the latest included EUCAST guideline, see *Details* for all options
|
#' @param guideline defaults to the latest included EUCAST 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 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 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 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 [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.
|
||||||
@ -179,7 +179,7 @@
|
|||||||
#' example_isolates %>%
|
#' example_isolates %>%
|
||||||
#' mutate_if(is.rsi.eligible, as.rsi)
|
#' mutate_if(is.rsi.eligible, as.rsi)
|
||||||
#'
|
#'
|
||||||
#' # note: from dplyr 1.0.0 on, this will be:
|
#' # since dplyr 1.0.0, this can also be:
|
||||||
#' # example_isolates %>%
|
#' # example_isolates %>%
|
||||||
#' # mutate(across(where(is.rsi.eligible), as.rsi))
|
#' # mutate(across(where(is.rsi.eligible), as.rsi))
|
||||||
#' }
|
#' }
|
||||||
@ -189,7 +189,7 @@ as.rsi <- function(x, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#' @rdname as.rsi
|
#' @rdname as.rsi
|
||||||
#' @details `NA_rsi_` is a missing value of the new `<rsi>` class.
|
#' @details `NA_rsi_` is a missing value of the new `<rsi>` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
|
||||||
#' @export
|
#' @export
|
||||||
NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE),
|
NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE),
|
||||||
new_class = c("rsi", "ordered", "factor"))
|
new_class = c("rsi", "ordered", "factor"))
|
||||||
|
Binary file not shown.
@ -43,7 +43,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
|
<a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -157,12 +157,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section level2">
|
<div class="section level2">
|
||||||
<h2 class="page-header" data-toc-text="1.8.1.9003" id="amr-1819003">
|
<h2 class="page-header" data-toc-text="1.8.1.9004" id="amr-1819004">
|
||||||
<code>AMR</code> 1.8.1.9003<a class="anchor" aria-label="anchor" href="#amr-1819003"></a></h2>
|
<code>AMR</code> 1.8.1.9004<a class="anchor" aria-label="anchor" href="#amr-1819004"></a></h2>
|
||||||
<div class="section level3">
|
<div class="section level3">
|
||||||
<h3 id="last-updated-may-1-8-1-9003"><small>Last updated: 9 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9003"></a></h3>
|
<h3 id="last-updated-may-1-8-1-9004"><small>Last updated: 9 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9004"></a></h3>
|
||||||
<div class="section level4">
|
<div class="section level4">
|
||||||
<h4 id="changed-1-8-1-9003">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9003"></a></h4>
|
<h4 id="changed-1-8-1-9004">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9004"></a></h4>
|
||||||
<ul><li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values consequently failed for not being able to retrieve the level position (as that’s how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li>
|
<ul><li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values consequently failed for not being able to retrieve the level position (as that’s how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li>
|
||||||
<li>
|
<li>
|
||||||
<code><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels()</a></code> on MIC will now return a common <code>factor</code> at default and will lose the <code><mic></code> class. Use <code>droplevels(..., as.mic = TRUE)</code> to keep the <code><mic></code> class.</li>
|
<code><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels()</a></code> on MIC will now return a common <code>factor</code> at default and will lose the <code><mic></code> class. Use <code>droplevels(..., as.mic = TRUE)</code> to keep the <code><mic></code> class.</li>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -225,7 +225,7 @@
|
|||||||
<dt>ab</dt>
|
<dt>ab</dt>
|
||||||
<dd><p>any (vector of) text that can be coerced to a valid antimicrobial code with <code><a href="as.ab.html">as.ab()</a></code></p></dd>
|
<dd><p>any (vector of) text that can be coerced to a valid antimicrobial code with <code><a href="as.ab.html">as.ab()</a></code></p></dd>
|
||||||
<dt>guideline</dt>
|
<dt>guideline</dt>
|
||||||
<dd><p>defaults to the latest included EUCAST guideline, see <em>Details</em> for all options</p></dd>
|
<dd><p>defaults to the latest included EUCAST guideline, supports EUCAST (2011-2021) and CLSI (2010-2021), see <em>Details</em></p></dd>
|
||||||
<dt>uti</dt>
|
<dt>uti</dt>
|
||||||
<dd><p>(Urinary Tract Infection) A vector with <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a>s (<code>TRUE</code> or <code>FALSE</code>) to specify whether a UTI specific interpretation from the guideline should be chosen. For using <code>as.rsi()</code> on a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, this can also be a column containing <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a>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 <em>Examples</em>.</p></dd>
|
<dd><p>(Urinary Tract Infection) A vector with <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a>s (<code>TRUE</code> or <code>FALSE</code>) to specify whether a UTI specific interpretation from the guideline should be chosen. For using <code>as.rsi()</code> on a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, this can also be a column containing <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a>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 <em>Examples</em>.</p></dd>
|
||||||
<dt>conserve_capped_values</dt>
|
<dt>conserve_capped_values</dt>
|
||||||
@ -289,7 +289,7 @@
|
|||||||
<p>The function <code>is.rsi.eligible()</code> returns <code>TRUE</code> when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and <code>FALSE</code> otherwise. The threshold of 5% can be set with the <code>threshold</code> argument. If the input is a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, it iterates over all columns and returns a <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a> vector.</p>
|
<p>The function <code>is.rsi.eligible()</code> returns <code>TRUE</code> when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and <code>FALSE</code> otherwise. The threshold of 5% can be set with the <code>threshold</code> argument. If the input is a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, it iterates over all columns and returns a <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a> vector.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><code>NA_rsi_</code> is a missing value of the new <code><rsi></code> class.</p>
|
<p><code>NA_rsi_</code> is a missing value of the new <code><rsi></code> class, analogous to e.g. base <span style="R">R</span>'s <code><a href="https://rdrr.io/r/base/NA.html" class="external-link">NA_character_</a></code>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="interpretation-of-r-and-s-i">
|
<div id="interpretation-of-r-and-s-i">
|
||||||
<h2>Interpretation of R and S/I</h2>
|
<h2>Interpretation of R and S/I</h2>
|
||||||
@ -408,7 +408,7 @@ The <a href="lifecycle.html">lifecycle</a> of this function is <strong>stable</s
|
|||||||
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span>
|
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span>
|
||||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html" class="external-link">mutate_if</a></span><span class="op">(</span><span class="va">is.rsi.eligible</span>, <span class="va">as.rsi</span><span class="op">)</span>
|
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html" class="external-link">mutate_if</a></span><span class="op">(</span><span class="va">is.rsi.eligible</span>, <span class="va">as.rsi</span><span class="op">)</span>
|
||||||
|
|
||||||
<span class="co"># note: from dplyr 1.0.0 on, this will be: </span>
|
<span class="co"># since dplyr 1.0.0, this can also be: </span>
|
||||||
<span class="co"># example_isolates %>%</span>
|
<span class="co"># example_isolates %>%</span>
|
||||||
<span class="co"># mutate(across(where(is.rsi.eligible), as.rsi))</span>
|
<span class="co"># mutate(across(where(is.rsi.eligible), as.rsi))</span>
|
||||||
<span class="op">}</span>
|
<span class="op">}</span>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -200,7 +200,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><p>Interpret MIC and Disk Values, or Clean Raw R/SI Data</p></td>
|
<td><p>Interpret MIC and Disk Values, or Clean Raw R/SI Data</p></td>
|
||||||
</tr><tr><td>
|
</tr><tr><td>
|
||||||
<p><code><a href="as.mic.html">as.mic()</a></code> <code><a href="as.mic.html">NA_mic_</a></code> <code><a href="as.mic.html">is.mic()</a></code> </p>
|
<p><code><a href="as.mic.html">as.mic()</a></code> <code><a href="as.mic.html">NA_mic_</a></code> <code><a href="as.mic.html">is.mic()</a></code> <code><a href="as.mic.html">droplevels(<i><mic></i>)</a></code> </p>
|
||||||
</td>
|
</td>
|
||||||
<td><p>Transform Input to Minimum Inhibitory Concentrations (MIC)</p></td>
|
<td><p>Transform Input to Minimum Inhibitory Concentrations (MIC)</p></td>
|
||||||
</tr><tr><td>
|
</tr><tr><td>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -33,7 +33,9 @@ expect_true(is.mic(as.mic(8)))
|
|||||||
|
|
||||||
expect_equal(as.double(as.mic(">=32")), 32)
|
expect_equal(as.double(as.mic(">=32")), 32)
|
||||||
expect_equal(as.numeric(as.mic(">=32")), 32)
|
expect_equal(as.numeric(as.mic(">=32")), 32)
|
||||||
expect_equal(as.integer(as.mic(">=32")), 32)
|
expect_equal(as.integer(as.mic(">=32")), # should be factor level, not the MIC
|
||||||
|
as.integer(factor(as.character(">=32"),
|
||||||
|
levels = levels(as.mic(">=32")))))
|
||||||
expect_equal(suppressWarnings(as.logical(as.mic("INVALID VALUE"))), NA)
|
expect_equal(suppressWarnings(as.logical(as.mic("INVALID VALUE"))), NA)
|
||||||
|
|
||||||
# all levels should be valid MICs
|
# all levels should be valid MICs
|
||||||
|
@ -6,21 +6,30 @@
|
|||||||
\alias{mic}
|
\alias{mic}
|
||||||
\alias{NA_mic_}
|
\alias{NA_mic_}
|
||||||
\alias{is.mic}
|
\alias{is.mic}
|
||||||
|
\alias{droplevels.mic}
|
||||||
\title{Transform Input to Minimum Inhibitory Concentrations (MIC)}
|
\title{Transform Input to Minimum Inhibitory Concentrations (MIC)}
|
||||||
\format{
|
|
||||||
An object of class \code{mic} (inherits from \code{ordered}, \code{factor}) of length 1.
|
|
||||||
}
|
|
||||||
\usage{
|
\usage{
|
||||||
as.mic(x, na.rm = FALSE)
|
as.mic(x, na.rm = FALSE)
|
||||||
|
|
||||||
NA_mic_
|
NA_mic_
|
||||||
|
|
||||||
is.mic(x)
|
is.mic(x)
|
||||||
|
|
||||||
|
\method{droplevels}{mic}(
|
||||||
|
x,
|
||||||
|
exclude = if (any(is.na(levels(x)))) NULL else NA,
|
||||||
|
as.mic = FALSE,
|
||||||
|
...
|
||||||
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{x}{a \link{character} or \link{numeric} vector}
|
\item{x}{a \link{character} or \link{numeric} vector}
|
||||||
|
|
||||||
\item{na.rm}{a \link{logical} indicating whether missing values should be removed}
|
\item{na.rm}{a \link{logical} indicating whether missing values should be removed}
|
||||||
|
|
||||||
|
\item{exclude}{factor levels which should be excluded from the result even if present, see \link[base:droplevels]{droplevels()}}
|
||||||
|
|
||||||
|
\item{as.mic}{a \link{logical} to indicate whether the \verb{<mic>} class should be kept, defaults to \code{FALSE}}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
Ordered \link{factor} with additional class \code{\link{mic}}, that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a \link{numeric} value.
|
Ordered \link{factor} with additional class \code{\link{mic}}, that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a \link{numeric} value.
|
||||||
@ -29,7 +38,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.
|
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{
|
\details{
|
||||||
To interpret MIC values as RSI values, use \code{\link[=as.rsi]{as.rsi()}} on MIC values. It supports guidelines from EUCAST and CLSI.
|
To interpret MIC values as RSI values, use \code{\link[=as.rsi]{as.rsi()}} on MIC values. It supports guidelines from EUCAST (2011-2021) and CLSI (2010-2021).
|
||||||
|
|
||||||
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:\preformatted{x <- random_mic(10)
|
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:\preformatted{x <- random_mic(10)
|
||||||
x
|
x
|
||||||
@ -63,7 +72,11 @@ subset(df, x > 4) # or with dplyr: df \%>\% filter(x > 4)
|
|||||||
|
|
||||||
The following \link[=groupGeneric]{generic functions} are implemented for the MIC class: \code{!}, \code{!=}, \code{\%\%}, \code{\%/\%}, \code{&}, \code{*}, \code{+}, \code{-}, \code{/}, \code{<}, \code{<=}, \code{==}, \code{>}, \code{>=}, \code{^}, \code{|}, \code{\link[=abs]{abs()}}, \code{\link[=acos]{acos()}}, \code{\link[=acosh]{acosh()}}, \code{\link[=all]{all()}}, \code{\link[=any]{any()}}, \code{\link[=asin]{asin()}}, \code{\link[=asinh]{asinh()}}, \code{\link[=atan]{atan()}}, \code{\link[=atanh]{atanh()}}, \code{\link[=ceiling]{ceiling()}}, \code{\link[=cos]{cos()}}, \code{\link[=cosh]{cosh()}}, \code{\link[=cospi]{cospi()}}, \code{\link[=cummax]{cummax()}}, \code{\link[=cummin]{cummin()}}, \code{\link[=cumprod]{cumprod()}}, \code{\link[=cumsum]{cumsum()}}, \code{\link[=digamma]{digamma()}}, \code{\link[=exp]{exp()}}, \code{\link[=expm1]{expm1()}}, \code{\link[=floor]{floor()}}, \code{\link[=gamma]{gamma()}}, \code{\link[=lgamma]{lgamma()}}, \code{\link[=log]{log()}}, \code{\link[=log1p]{log1p()}}, \code{\link[=log2]{log2()}}, \code{\link[=log10]{log10()}}, \code{\link[=max]{max()}}, \code{\link[=mean]{mean()}}, \code{\link[=min]{min()}}, \code{\link[=prod]{prod()}}, \code{\link[=range]{range()}}, \code{\link[=round]{round()}}, \code{\link[=sign]{sign()}}, \code{\link[=signif]{signif()}}, \code{\link[=sin]{sin()}}, \code{\link[=sinh]{sinh()}}, \code{\link[=sinpi]{sinpi()}}, \code{\link[=sqrt]{sqrt()}}, \code{\link[=sum]{sum()}}, \code{\link[=tan]{tan()}}, \code{\link[=tanh]{tanh()}}, \code{\link[=tanpi]{tanpi()}}, \code{\link[=trigamma]{trigamma()}} and \code{\link[=trunc]{trunc()}}. Some functions of the \code{stats} package are also implemented: \code{\link[=median]{median()}}, \code{\link[=quantile]{quantile()}}, \code{\link[=mad]{mad()}}, \code{\link[=IQR]{IQR()}}, \code{\link[=fivenum]{fivenum()}}. Also, \code{\link[=boxplot.stats]{boxplot.stats()}} is supported. Since \code{\link[=sd]{sd()}} and \code{\link[=var]{var()}} are non-generic functions, these could not be extended. Use \code{\link[=mad]{mad()}} as an alternative, or use e.g. \code{sd(as.numeric(x))} where \code{x} is your vector of MIC values.
|
The following \link[=groupGeneric]{generic functions} are implemented for the MIC class: \code{!}, \code{!=}, \code{\%\%}, \code{\%/\%}, \code{&}, \code{*}, \code{+}, \code{-}, \code{/}, \code{<}, \code{<=}, \code{==}, \code{>}, \code{>=}, \code{^}, \code{|}, \code{\link[=abs]{abs()}}, \code{\link[=acos]{acos()}}, \code{\link[=acosh]{acosh()}}, \code{\link[=all]{all()}}, \code{\link[=any]{any()}}, \code{\link[=asin]{asin()}}, \code{\link[=asinh]{asinh()}}, \code{\link[=atan]{atan()}}, \code{\link[=atanh]{atanh()}}, \code{\link[=ceiling]{ceiling()}}, \code{\link[=cos]{cos()}}, \code{\link[=cosh]{cosh()}}, \code{\link[=cospi]{cospi()}}, \code{\link[=cummax]{cummax()}}, \code{\link[=cummin]{cummin()}}, \code{\link[=cumprod]{cumprod()}}, \code{\link[=cumsum]{cumsum()}}, \code{\link[=digamma]{digamma()}}, \code{\link[=exp]{exp()}}, \code{\link[=expm1]{expm1()}}, \code{\link[=floor]{floor()}}, \code{\link[=gamma]{gamma()}}, \code{\link[=lgamma]{lgamma()}}, \code{\link[=log]{log()}}, \code{\link[=log1p]{log1p()}}, \code{\link[=log2]{log2()}}, \code{\link[=log10]{log10()}}, \code{\link[=max]{max()}}, \code{\link[=mean]{mean()}}, \code{\link[=min]{min()}}, \code{\link[=prod]{prod()}}, \code{\link[=range]{range()}}, \code{\link[=round]{round()}}, \code{\link[=sign]{sign()}}, \code{\link[=signif]{signif()}}, \code{\link[=sin]{sin()}}, \code{\link[=sinh]{sinh()}}, \code{\link[=sinpi]{sinpi()}}, \code{\link[=sqrt]{sqrt()}}, \code{\link[=sum]{sum()}}, \code{\link[=tan]{tan()}}, \code{\link[=tanh]{tanh()}}, \code{\link[=tanpi]{tanpi()}}, \code{\link[=trigamma]{trigamma()}} and \code{\link[=trunc]{trunc()}}. Some functions of the \code{stats} package are also implemented: \code{\link[=median]{median()}}, \code{\link[=quantile]{quantile()}}, \code{\link[=mad]{mad()}}, \code{\link[=IQR]{IQR()}}, \code{\link[=fivenum]{fivenum()}}. Also, \code{\link[=boxplot.stats]{boxplot.stats()}} is supported. Since \code{\link[=sd]{sd()}} and \code{\link[=var]{var()}} are non-generic functions, these could not be extended. Use \code{\link[=mad]{mad()}} as an alternative, or use e.g. \code{sd(as.numeric(x))} where \code{x} is your vector of MIC values.
|
||||||
|
|
||||||
\code{NA_mic_} is a missing value of the new \verb{<mic>} class.
|
Using \code{\link[=as.double]{as.double()}} or \code{\link[=as.numeric]{as.numeric()}} on MIC values will remove the operators and return a numeric vector. Do \strong{not} use \code{\link[=as.integer]{as.integer()}} on MIC values as by the \R convention on \link{factor}s, it will return the index of the factor levels (which is often useless for regular users).
|
||||||
|
|
||||||
|
Use \code{\link[=droplevels]{droplevels()}} to drop unused levels. At default, it will return a plain factor. Use \code{droplevels(..., as.mic = TRUE)} to maintain the \verb{<mic>} class.
|
||||||
|
|
||||||
|
\code{NA_mic_} is a missing value of the new \verb{<mic>} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
|
||||||
}
|
}
|
||||||
\section{Stable Lifecycle}{
|
\section{Stable Lifecycle}{
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ is.rsi.eligible(x, threshold = 0.05)
|
|||||||
|
|
||||||
\item{ab}{any (vector of) text that can be coerced to a valid antimicrobial code with \code{\link[=as.ab]{as.ab()}}}
|
\item{ab}{any (vector of) text that can be coerced to a valid antimicrobial code with \code{\link[=as.ab]{as.ab()}}}
|
||||||
|
|
||||||
\item{guideline}{defaults to the latest included EUCAST guideline, see \emph{Details} for all options}
|
\item{guideline}{defaults to the latest included EUCAST guideline, supports EUCAST (2011-2021) and CLSI (2010-2021), 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.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}.}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ The function \code{\link[=is.rsi]{is.rsi()}} detects if the input contains class
|
|||||||
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.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.
|
||||||
}
|
}
|
||||||
|
|
||||||
\code{NA_rsi_} is a missing value of the new \verb{<rsi>} class.
|
\code{NA_rsi_} is a missing value of the new \verb{<rsi>} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
|
||||||
}
|
}
|
||||||
\section{Interpretation of R and S/I}{
|
\section{Interpretation of R and S/I}{
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ if (require("dplyr")) {
|
|||||||
example_isolates \%>\%
|
example_isolates \%>\%
|
||||||
mutate_if(is.rsi.eligible, as.rsi)
|
mutate_if(is.rsi.eligible, as.rsi)
|
||||||
|
|
||||||
# note: from dplyr 1.0.0 on, this will be:
|
# since dplyr 1.0.0, this can also be:
|
||||||
# example_isolates \%>\%
|
# example_isolates \%>\%
|
||||||
# mutate(across(where(is.rsi.eligible), as.rsi))
|
# mutate(across(where(is.rsi.eligible), as.rsi))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user