` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
#' @export
NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE),
new_class = c("rsi", "ordered", "factor"))
diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz
index f98e02ae..7739bac9 100644
Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ
diff --git a/docs/404.html b/docs/404.html
index d0e3cfb3..38bd6720 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -43,7 +43,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index 12c4f12c..1ab18143 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html
index e9bbe351..ee823ef9 100644
--- a/docs/articles/datasets.html
+++ b/docs/articles/datasets.html
@@ -44,7 +44,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/docs/authors.html b/docs/authors.html
index 43af78f6..b47ce57e 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/docs/index.html b/docs/index.html
index 9ca96788..76d7b387 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -47,7 +47,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/docs/news/index.html b/docs/news/index.html
index 314cf777..44c34afc 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
@@ -157,12 +157,12 @@
-
+
-
Last updated: 9 May 2022
+
Last updated: 9 May 2022
-
Changed
+
Changed
- Removed
as.integer()
for MIC values, since MIC are not integer values and running table()
on MIC values consequently failed for not being able to retrieve the level position (as that’s how normally as.integer()
on factor
s work)
-
droplevels()
on MIC will now return a common factor
at default and will lose the <mic>
class. Use droplevels(..., as.mic = TRUE)
to keep the <mic>
class.
diff --git a/docs/reference/as.mic.html b/docs/reference/as.mic.html
index 0daf4317..7a523999 100644
--- a/docs/reference/as.mic.html
+++ b/docs/reference/as.mic.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1
+ 1.8.1.9004
@@ -30,7 +30,7 @@
-
+
How to
@@ -166,19 +166,27 @@
NA_mic_
-is.mic(x)
+
is.mic(x)
+
+
# S3 method for mic
+
droplevels(
+
x,
+ exclude
= if (any(is.na(levels(x)))) NULL else NA,
+ as.mic
= FALSE,
+
...
+
)
-
Arguments
- x
a character or numeric vector
- na.rm
a logical indicating whether missing values should be removed
+- exclude
+factor levels which should be excluded from the result even if present, see droplevels()
+- as.mic
+a logical to indicate whether the <mic>
class should be kept, defaults to FALSE
Value
@@ -186,7 +194,7 @@
Details
-
To interpret MIC values as RSI values, use as.rsi()
on MIC values. It supports guidelines from EUCAST and CLSI.
+
To interpret MIC values as RSI values, use 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 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:
x <- random_mic(10)
x
#> Class <mic>
@@ -216,7 +224,9 @@
#> 10 16 A
The following generic functions 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.
-
NA_mic_
is a missing value of the new <mic>
class.
+
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 factors, 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.
+
NA_mic_
is a missing value of the new <mic>
class, analogous to e.g. base R's NA_character_
.
Stable Lifecycle
@@ -277,7 +287,7 @@ The
lifecycle of this function is
stable
diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html
index c3e7efb6..62cb372d 100644
--- a/docs/reference/as.rsi.html
+++ b/docs/reference/as.rsi.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9002
+ 1.8.1.9004
@@ -225,7 +225,7 @@
ab
any (vector of) text that can be coerced to a valid antimicrobial code with as.ab()
guideline
-defaults to the latest included EUCAST guideline, see Details for all options
+defaults to the latest included EUCAST guideline, supports EUCAST (2011-2021) and CLSI (2010-2021), see Details
uti
(Urinary Tract Infection) A vector with logicals (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 logicals 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.
conserve_capped_values
@@ -289,7 +289,7 @@
The function is.rsi.eligible()
returns TRUE
when a columns contains at most 5% invalid antimicrobial interpretations (not S and/or I and/or R), and FALSE
otherwise. The threshold of 5% can be set with the threshold
argument. If the input is a data.frame, it iterates over all columns and returns a logical vector.
-NA_rsi_
is a missing value of the new <rsi>
class.
+NA_rsi_
is a missing value of the new <rsi>
class, analogous to e.g. base R's NA_character_
.
Interpretation of R and S/I
@@ -408,7 +408,7 @@ The
lifecycle of this function is
stableexample_isolates %>%
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 %>%
# mutate(across(where(is.rsi.eligible), as.rsi))
}
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 5e8e510e..ec796c07 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
@@ -200,7 +200,7 @@
Interpret MIC and Disk Values, or Clean Raw R/SI Data |
- as.mic() NA_mic_ is.mic()
+ as.mic() NA_mic_ is.mic() droplevels(<mic>)
|
Transform Input to Minimum Inhibitory Concentrations (MIC) |
diff --git a/docs/survey.html b/docs/survey.html
index f0faa2df..eef75c52 100644
--- a/docs/survey.html
+++ b/docs/survey.html
@@ -17,7 +17,7 @@
AMR (for R)
- 1.8.1.9003
+ 1.8.1.9004
diff --git a/inst/tinytest/test-mic.R b/inst/tinytest/test-mic.R
index a82a992d..714bf5dd 100755
--- a/inst/tinytest/test-mic.R
+++ b/inst/tinytest/test-mic.R
@@ -33,7 +33,9 @@ expect_true(is.mic(as.mic(8)))
expect_equal(as.double(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)
# all levels should be valid MICs
diff --git a/man/as.mic.Rd b/man/as.mic.Rd
index 71c7126d..185aa44e 100755
--- a/man/as.mic.Rd
+++ b/man/as.mic.Rd
@@ -6,21 +6,30 @@
\alias{mic}
\alias{NA_mic_}
\alias{is.mic}
+\alias{droplevels.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{
as.mic(x, na.rm = FALSE)
NA_mic_
is.mic(x)
+
+\method{droplevels}{mic}(
+ x,
+ exclude = if (any(is.na(levels(x)))) NULL else NA,
+ as.mic = FALSE,
+ ...
+)
}
\arguments{
\item{x}{a \link{character} or \link{numeric} vector}
\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{} class should be kept, defaults to \code{FALSE}}
}
\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.
}
\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)
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.
-\code{NA_mic_} is a missing value of the new \verb{} 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{} class.
+
+\code{NA_mic_} is a missing value of the new \verb{} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
}
\section{Stable Lifecycle}{
diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd
index d73402cf..c8dfcc04 100755
--- a/man/as.rsi.Rd
+++ b/man/as.rsi.Rd
@@ -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{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}.}
@@ -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.
}
-\code{NA_rsi_} is a missing value of the new \verb{} class.
+\code{NA_rsi_} is a missing value of the new \verb{} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
}
\section{Interpretation of R and S/I}{
@@ -247,7 +247,7 @@ if (require("dplyr")) {
example_isolates \%>\%
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 \%>\%
# mutate(across(where(is.rsi.eligible), as.rsi))
}
|