NEWS.md
- With using collapse
, this function will return a character:
df %>% mutate(abx = ab_from_text(clinical_text, collapse = "|"))
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
This transforms a vector to a new class mic
, which is an ordered factor with valid minimum inhibitory concentrations (MIC) as levels. Invalid MIC values will be translated as NA
with a warning.
This ransforms vectors to a new class 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.
as.mic(x, na.rm = FALSE) @@ -251,7 +251,7 @@x -+ vector
character or numeric vector
na.rm @@ -261,10 +261,41 @@Value
-Ordered factor with additional class
+mic
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.Details
To interpret MIC values as RSI values, use
+as.rsi()
on MIC values. It supports guidelines from EUCAST and CLSI.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> +#> [1] 16 1 8 8 64 >=128 0.0625 32 32 16 + +is.factor(x) +#> [1] TRUE + +x[1] * 2 +#> [1] 32 + +median(x) +#> [1] 26 ++ +This makes it possible to maintain operators that often come with MIC values, such ">=" and "<=", even when filtering using numeric values in data analysis, e.g.:
x[x > 4] +#> Class <mic> +#> [1] 16 8 8 64 >=128 32 32 16 + +df <- data.frame(x, hospital = "A") +subset(df, x > 4) # or with dplyr: df %>% filter(x > 4) +#> x hospital +#> 1 16 A +#> 5 64 A +#> 6 >=128 A +#> 8 32 A +#> 9 32 A +#> 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()
,log10()
,log1p()
,log2()
,max()
,mean()
,median()
,min()
,prod()
,quantile()
,range()
,round()
,sign()
,signif()
,sin()
,sinh()
,sinpi()
,sqrt()
,sum()
,tan()
,tanh()
,tanpi()
,trigamma()
andtrunc()
.Stable Lifecycle
diff --git a/docs/reference/ggplot_pca.html b/docs/reference/ggplot_pca.html index a181e992..c36a2318 100644 --- a/docs/reference/ggplot_pca.html +++ b/docs/reference/ggplot_pca.html @@ -82,7 +82,7 @@ @@ -384,12 +384,13 @@Details
The colours for labels and points can be changed by adding another scale layer for colour, like
-scale_colour_viridis_d()
orscale_colour_brewer()
.Maturing Lifecycle
+Stable Lifecycle
-+
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
Examples
# `example_isolates` is a data set available in the AMR package. diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index 5c0a8299..1bde674d 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -82,7 +82,7 @@ @@ -415,12 +415,13 @@
labels_rsi_count()
print datalabels on the bars with percentage and amount of isolates usingggplot2::geom_text()
.-
ggplot_rsi()
is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (%>%
). See Examples.Maturing Lifecycle
+Stable Lifecycle
-+
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
Read more on Our Website!
diff --git a/docs/reference/index.html b/docs/reference/index.html index 20f7dab1..21854e2d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ diff --git a/docs/reference/pca.html b/docs/reference/pca.html index 06ac67fc..67b20677 100644 --- a/docs/reference/pca.html +++ b/docs/reference/pca.html @@ -82,7 +82,7 @@ @@ -311,12 +311,13 @@The
pca()
function takes a data.frame as input and performs the actual PCA with the R functionprcomp()
.The result of the
-pca()
function is a prcomp object, with an additional attributenon_numeric_cols
which is a vector with the column names of all columns that do not contain numeric values. These are probably the groups and labels, and will be used byggplot_pca()
.Maturing Lifecycle
+Stable Lifecycle
-+
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
Read more on Our Website!
diff --git a/docs/reference/random.html b/docs/reference/random.html index 2ae80980..5c21b3c6 100644 --- a/docs/reference/random.html +++ b/docs/reference/random.html @@ -82,7 +82,7 @@ @@ -280,12 +280,13 @@The base R function
sample()
is used for generating values.Generated values are based on the latest EUCAST guideline implemented in the rsi_translation data set. To create specific generated values per bug or drug, set the
-mo
and/orab
argument.Maturing Lifecycle
+Stable Lifecycle
-+
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
Read more on Our Website!
diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index cac77c59..fc2c3852 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -82,7 +82,7 @@ @@ -364,12 +364,13 @@-
"lin"
or"linear"
: a linear regression modelMaturing Lifecycle
+Stable Lifecycle
-+
-The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
Interpretation of R and S/I
diff --git a/docs/survey.html b/docs/survey.html index 1b8f50b1..8ac19a60 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ diff --git a/man/ab_from_text.Rd b/man/ab_from_text.Rd index 044feec8..387f0298 100644 --- a/man/ab_from_text.Rd +++ b/man/ab_from_text.Rd @@ -54,10 +54,12 @@ With using \code{collapse}, this function will return a \link{character}:\cr \code{df \%>\% mutate(abx = ab_from_text(clinical_text, collapse = "|"))} } } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Read more on Our Website!}{ diff --git a/man/as.mic.Rd b/man/as.mic.Rd index 93c91260..a4ae8090 100755 --- a/man/as.mic.Rd +++ b/man/as.mic.Rd @@ -11,18 +11,50 @@ as.mic(x, na.rm = FALSE) is.mic(x) } \arguments{ -\item{x}{vector} +\item{x}{character or numeric vector} \item{na.rm}{a logical indicating whether missing values should be removed} } \value{ -Ordered \link{factor} with additional class \code{\link{mic}} +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 numeric value. } \description{ -This transforms a vector to a new class \code{\link{mic}}, which is an ordered \link{factor} with valid minimum inhibitory concentrations (MIC) as levels. Invalid MIC values will be translated as \code{NA} with a warning. +This ransforms 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. + +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:\preformatted{x <- random_mic(10) +x +#> Class+#> [1] 16 1 8 8 64 >=128 0.0625 32 32 16 + +is.factor(x) +#> [1] TRUE + +x[1] * 2 +#> [1] 32 + +median(x) +#> [1] 26 +} + +This makes it possible to maintain operators that often come with MIC values, such ">=" and "<=", even when filtering using numeric values in data analysis, e.g.:\preformatted{x[x > 4] +#> Class +#> [1] 16 8 8 64 >=128 32 32 16 + +df <- data.frame(x, hospital = "A") +subset(df, x > 4) # or with dplyr: df \%>\% filter(x > 4) +#> x hospital +#> 1 16 A +#> 5 64 A +#> 6 >=128 A +#> 8 32 A +#> 9 32 A +#> 10 16 A +} + +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[=log10]{log10()}}, \code{\link[=log1p]{log1p()}}, \code{\link[=log2]{log2()}}, \code{\link[=max]{max()}}, \code{\link[=mean]{mean()}}, \code{\link[=median]{median()}}, \code{\link[=min]{min()}}, \code{\link[=prod]{prod()}}, \code{\link[=quantile]{quantile()}}, \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()}}. } \section{Stable Lifecycle}{ diff --git a/man/ggplot_pca.Rd b/man/ggplot_pca.Rd index 55ed68b9..dde88f82 100644 --- a/man/ggplot_pca.Rd +++ b/man/ggplot_pca.Rd @@ -108,10 +108,12 @@ Produces a \code{ggplot2} variant of a so-called \href{https://en.wikipedia.org/ \details{ The colours for labels and points can be changed by adding another scale layer for colour, like \code{scale_colour_viridis_d()} or \code{scale_colour_brewer()}. } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \examples{ diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index 2d4f768f..7c05e8c7 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -140,10 +140,12 @@ At default, the names of antibiotics will be shown on the plots using \code{\lin \code{\link[=ggplot_rsi]{ggplot_rsi()}} is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (\verb{\%>\%}). See \emph{Examples}. } } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Read more on Our Website!}{ diff --git a/man/pca.Rd b/man/pca.Rd index 84988c47..f7f441e0 100644 --- a/man/pca.Rd +++ b/man/pca.Rd @@ -59,10 +59,12 @@ The \code{\link[=pca]{pca()}} function takes a \link{data.frame} as input and pe The result of the \code{\link[=pca]{pca()}} function is a \link{prcomp} object, with an additional attribute \code{non_numeric_cols} which is a vector with the column names of all columns that do not contain numeric values. These are probably the groups and labels, and will be used by \code{\link[=ggplot_pca]{ggplot_pca()}}. } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Read more on Our Website!}{ diff --git a/man/random.Rd b/man/random.Rd index 63a09483..93b0c309 100644 --- a/man/random.Rd +++ b/man/random.Rd @@ -35,10 +35,12 @@ The base R function \code{\link[=sample]{sample()}} is used for generating value Generated values are based on the latest EUCAST guideline implemented in the \link{rsi_translation} data set. To create specific generated values per bug or drug, set the \code{mo} and/or \code{ab} argument. } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Read more on Our Website!}{ diff --git a/man/resistance_predict.Rd b/man/resistance_predict.Rd index d90029a6..19cc4a8d 100644 --- a/man/resistance_predict.Rd +++ b/man/resistance_predict.Rd @@ -100,10 +100,12 @@ Valid options for the statistical model (argument \code{model}) are: \item \code{"lin"} or \code{"linear"}: a linear regression model } } -\section{Maturing Lifecycle}{ +\section{Stable Lifecycle}{ -\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Interpretation of R and S/I}{ diff --git a/tests/testthat/test-mic.R b/tests/testthat/test-mic.R index a30fefbf..0befef74 100755 --- a/tests/testthat/test-mic.R +++ b/tests/testthat/test-mic.R @@ -31,12 +31,12 @@ test_that("mic works", { expect_true(as.mic("1") > as.mic("<=0.0625")) expect_true(as.mic("1") < as.mic(">=32")) 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(suppressWarnings(as.logical(as.mic("INVALID VALUE"))), NA) - + # all levels should be valid MICs x <- as.mic(c(2, 4)) expect_s3_class(x[1], "mic") @@ -60,12 +60,83 @@ test_that("mic works", { } expect_output(print(as.mic(c(1, 2, 4, 8)))) - expect_equal(summary(as.mic(c(2, 8))), - structure(c("Class" = "mic", - " " = "0", - "Min." = "2", - "Max." = "8"), class = c("summaryDefault", "table"))) + expect_s3_class(summary(as.mic(c(2, 8))), c("summaryDefault", "table")) library(dplyr, warn.conflicts = FALSE) expect_output(print(tibble(m = as.mic(2:4)))) }) + +test_that("mathematical functions on mic work", { + skip_on_cran() + x <- random_mic(50) + x_double <- as.double(gsub("[<=>]+", "", as.character(x))) + suppressWarnings(expect_identical(mean(x), mean(x_double))) + suppressWarnings(expect_identical(median(x), median(x_double))) + suppressWarnings(expect_identical(quantile(x), quantile(x_double))) + suppressWarnings(expect_identical(abs(x), abs(x_double))) + suppressWarnings(expect_identical(sign(x), sign(x_double))) + suppressWarnings(expect_identical(sqrt(x), sqrt(x_double))) + suppressWarnings(expect_identical(floor(x), floor(x_double))) + suppressWarnings(expect_identical(ceiling(x), ceiling(x_double))) + suppressWarnings(expect_identical(trunc(x), trunc(x_double))) + suppressWarnings(expect_identical(round(x), round(x_double))) + suppressWarnings(expect_identical(signif(x), signif(x_double))) + suppressWarnings(expect_identical(exp(x), exp(x_double))) + suppressWarnings(expect_identical(log(x), log(x_double))) + suppressWarnings(expect_identical(log10(x), log10(x_double))) + suppressWarnings(expect_identical(log2(x), log2(x_double))) + suppressWarnings(expect_identical(expm1(x), expm1(x_double))) + suppressWarnings(expect_identical(log1p(x), log1p(x_double))) + suppressWarnings(expect_identical(cos(x), cos(x_double))) + suppressWarnings(expect_identical(sin(x), sin(x_double))) + suppressWarnings(expect_identical(tan(x), tan(x_double))) + suppressWarnings(expect_identical(cospi(x), cospi(x_double))) + suppressWarnings(expect_identical(sinpi(x), sinpi(x_double))) + suppressWarnings(expect_identical(tanpi(x), tanpi(x_double))) + suppressWarnings(expect_identical(acos(x), acos(x_double))) + suppressWarnings(expect_identical(asin(x), asin(x_double))) + suppressWarnings(expect_identical(atan(x), atan(x_double))) + suppressWarnings(expect_identical(cosh(x), cosh(x_double))) + suppressWarnings(expect_identical(sinh(x), sinh(x_double))) + suppressWarnings(expect_identical(tanh(x), tanh(x_double))) + suppressWarnings(expect_identical(acosh(x), acosh(x_double))) + suppressWarnings(expect_identical(asinh(x), asinh(x_double))) + suppressWarnings(expect_identical(atanh(x), atanh(x_double))) + suppressWarnings(expect_identical(lgamma(x), lgamma(x_double))) + suppressWarnings(expect_identical(gamma(x), gamma(x_double))) + suppressWarnings(expect_identical(digamma(x), digamma(x_double))) + suppressWarnings(expect_identical(trigamma(x), trigamma(x_double))) + suppressWarnings(expect_identical(cumsum(x), cumsum(x_double))) + suppressWarnings(expect_identical(cumprod(x), cumprod(x_double))) + suppressWarnings(expect_identical(cummax(x), cummax(x_double))) + suppressWarnings(expect_identical(cummin(x), cummin(x_double))) + suppressWarnings(expect_identical(!x, !(x_double))) + + suppressWarnings(expect_identical(all(x), all(x_double))) + suppressWarnings(expect_identical(any(x), any(x_double))) + suppressWarnings(expect_identical(sum(x), sum(x_double))) + suppressWarnings(expect_identical(prod(x), prod(x_double))) + suppressWarnings(expect_identical(min(x), min(x_double))) + suppressWarnings(expect_identical(max(x), max(x_double))) + suppressWarnings(expect_identical(range(x), range(x_double))) + + el1 <- random_mic(50) + el1_double <- as.double(gsub("[<=>]+", "", as.character(el1))) + el2 <- random_mic(50) + el2_double <- as.double(gsub("[<=>]+", "", as.character(el2))) + suppressWarnings(expect_identical(el1 + el2, el1_double + el2_double)) + suppressWarnings(expect_identical(el1 - el2, el1_double - el2_double)) + suppressWarnings(expect_identical(el1 * el2, el1_double * el2_double)) + suppressWarnings(expect_identical(el1 / el2, el1_double / el2_double)) + suppressWarnings(expect_identical(el1 ^ el2, el1_double ^ el2_double)) + suppressWarnings(expect_identical(el1 %% el2, el1_double %% el2_double)) + suppressWarnings(expect_identical(el1 %/% el2, el1_double %/% el2_double)) + suppressWarnings(expect_identical(el1 & el2, el1_double & el2_double)) + suppressWarnings(expect_identical(el1 | el2, el1_double | el2_double)) + suppressWarnings(expect_identical(el1 == el2, el1_double == el2_double)) + suppressWarnings(expect_identical(el1 != el2, el1_double != el2_double)) + suppressWarnings(expect_identical(el1 < el2, el1_double < el2_double)) + suppressWarnings(expect_identical(el1 <= el2, el1_double <= el2_double)) + suppressWarnings(expect_identical(el1 >= el2, el1_double >= el2_double)) + suppressWarnings(expect_identical(el1 > el2, el1_double > el2_double)) +})