diff --git a/DESCRIPTION b/DESCRIPTION index 593eaf2e3..97344a2c7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.5.0.9031 -Date: 2021-03-05 +Version: 1.5.0.9032 +Date: 2021-03-07 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index 9f3e549a0..e5e814978 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,10 @@ # Generated by roxygen2: do not edit by hand +S3method("!",mic) S3method("!=",mic) S3method("%%",mic) S3method("%/%",mic) +S3method("&",mic) S3method("*",mic) S3method("+",mic) S3method("-",mic) @@ -35,6 +37,10 @@ S3method("[[<-",mic) S3method("[[<-",mo) S3method("[[<-",rsi) S3method("^",mic) +S3method("|",mic) +S3method(abs,mic) +S3method(acos,mic) +S3method(acosh,mic) S3method(all,mic) S3method(all.equal,isolate_identifier) S3method(any,mic) @@ -47,6 +53,10 @@ S3method(as.rsi,data.frame) S3method(as.rsi,default) S3method(as.rsi,disk) S3method(as.rsi,mic) +S3method(asin,mic) +S3method(asinh,mic) +S3method(atan,mic) +S3method(atanh,mic) S3method(barplot,disk) S3method(barplot,mic) S3method(barplot,rsi) @@ -57,14 +67,30 @@ S3method(c,mic) S3method(c,mo) S3method(c,rsi) S3method(ceiling,mic) +S3method(cos,mic) +S3method(cosh,mic) +S3method(cospi,mic) +S3method(cummax,mic) +S3method(cummin,mic) +S3method(cumprod,mic) +S3method(cumsum,mic) +S3method(digamma,mic) S3method(droplevels,mic) S3method(droplevels,rsi) +S3method(exp,mic) +S3method(expm1,mic) S3method(floor,mic) S3method(format,bug_drug_combinations) +S3method(gamma,mic) S3method(hist,mic) S3method(kurtosis,data.frame) S3method(kurtosis,default) S3method(kurtosis,matrix) +S3method(lgamma,mic) +S3method(log,mic) +S3method(log10,mic) +S3method(log1p,mic) +S3method(log2,mic) S3method(max,mic) S3method(mean,mic) S3method(median,mic) @@ -85,18 +111,31 @@ S3method(print,mo_renamed) S3method(print,mo_uncertainties) S3method(print,pca) S3method(print,rsi) +S3method(prod,mic) S3method(quantile,mic) S3method(range,mic) S3method(rep,mo) +S3method(round,mic) +S3method(sign,mic) +S3method(signif,mic) +S3method(sin,mic) +S3method(sinh,mic) +S3method(sinpi,mic) S3method(skewness,data.frame) S3method(skewness,default) S3method(skewness,matrix) S3method(sort,mic) +S3method(sqrt,mic) S3method(sum,mic) S3method(summary,mic) S3method(summary,mo) S3method(summary,pca) S3method(summary,rsi) +S3method(tan,mic) +S3method(tanh,mic) +S3method(tanpi,mic) +S3method(trigamma,mic) +S3method(trunc,mic) S3method(unique,ab) S3method(unique,disk) S3method(unique,isolate_identifier) diff --git a/NEWS.md b/NEWS.md index d80d9ab4c..84ccebb7a 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.5.0.9031 -## Last updated: 5 March 2021 +# AMR 1.5.0.9032 +## Last updated: 7 March 2021 ### New * Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package. diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 6e3a00e1b..3f87e2a6e 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -961,15 +961,8 @@ formatted_filesize <- function(...) { } create_pillar_column <- function(x, ...) { - new_pillar_shaft_simple <- import_fn("new_pillar_shaft_simple", "pillar", error_on_fail = FALSE) - if (!is.null(new_pillar_shaft_simple)) { - new_pillar_shaft_simple(x, ...) - } else { - # does not exist in package 'pillar' anymore - structure(list(x), - class = "pillar_shaft_simple", - ...) - } + new_pillar_shaft_simple <- import_fn("new_pillar_shaft_simple", "pillar") + new_pillar_shaft_simple(x, ...) } # copied from vctrs::s3_register by their permission: diff --git a/R/ab_from_text.R b/R/ab_from_text.R index 59decc1a0..4422cad11 100644 --- a/R/ab_from_text.R +++ b/R/ab_from_text.R @@ -26,7 +26,7 @@ #' Retrieve Antimicrobial Drug Names and Doses from Clinical Text #' #' Use this function on e.g. clinical texts from health care records. It returns a [list] with all antimicrobial drugs, doses and forms of administration found in the texts. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param text text to analyse #' @param type type of property to search for, either `"drug"`, `"dose"` or `"administration"`, see *Examples* #' @param collapse character to pass on to `paste(, collapse = ...)` to only return one character per element of `text`, see *Examples* diff --git a/R/ggplot_pca.R b/R/ggplot_pca.R index b93bb3237..f20ac6ac9 100755 --- a/R/ggplot_pca.R +++ b/R/ggplot_pca.R @@ -26,7 +26,7 @@ #' PCA Biplot with `ggplot2` #' #' Produces a `ggplot2` variant of a so-called [biplot](https://en.wikipedia.org/wiki/Biplot) for PCA (principal component analysis), but is more flexible and more appealing than the base \R [biplot()] function. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param x an object returned by [pca()], [prcomp()] or [princomp()] #' @inheritParams stats::biplot.prcomp #' @param labels an optional vector of labels for the observations. If set, the labels will be placed below their respective points. When using the [pca()] function as input for `x`, this will be determined automatically based on the attribute `non_numeric_cols`, see [pca()]. diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 92aef2aa1..3e2ae5813 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -26,7 +26,7 @@ #' AMR Plots with `ggplot2` #' #' Use these functions to create bar plots for AMR data analysis. All functions rely on [ggplot2][ggplot2::ggplot()] functions. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param data a [data.frame] with column(s) of class [`rsi`] (see [as.rsi()]) #' @param position position adjustment of bars, either `"fill"`, `"stack"` or `"dodge"` #' @param x variable to show on x axis, either `"antibiotic"` (default) or `"interpretation"` or a grouping variable diff --git a/R/mic.R b/R/mic.R index 661775886..a59f71f5f 100755 --- a/R/mic.R +++ b/R/mic.R @@ -25,13 +25,51 @@ #' Transform Input to Minimum Inhibitory Concentrations (MIC) #' -#' 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. #' @inheritSection lifecycle Stable Lifecycle #' @rdname as.mic -#' @param x vector +#' @param x character or numeric vector #' @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. -#' @return Ordered [factor] with additional class [`mic`] +#' +#' 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 +#' #> [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 +#' #> [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][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()], [log10()], [log1p()], [log2()], [max()], [mean()], [median()], [min()], [prod()], [quantile()], [range()], [round()], [sign()], [signif()], [sin()], [sinh()], [sinpi()], [sqrt()], [sum()], [tan()], [tanh()], [tanpi()], [trigamma()] and [trunc()]. +#' @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 #' @export #' @seealso [as.rsi()] @@ -197,6 +235,7 @@ pillar_shaft.mic <- function(x, ...) { out <- pasted out[is.na(x)] <- font_na(NA) out <- gsub("(<|=|>)", font_silver("\\1"), out) + out <- gsub("([.]?0+)$", font_white("\\1"), out) create_pillar_column(out, align = "right", width = max(nchar(pasted))) } @@ -211,22 +250,17 @@ type_sum.mic <- function(x, ...) { print.mic <- function(x, ...) { cat("Class \n") print(as.character(x), quote = FALSE) + att <- attributes(x) + if ("na.action" %in% names(att)) { + cat(font_silver(paste0("(NA ", class(att$na.action), ": ", paste0(att$na.action, collapse = ", "), ")\n"))) + } } #' @method summary mic #' @export #' @noRd summary.mic <- function(object, ...) { - x <- object - n_total <- length(x) - x <- x[!is.na(x)] - n <- length(x) - value <- c("Class" = "mic", - "" = n_total - n, - "Min." = as.character(sort(x)[1]), - "Max." = as.character(sort(x)[n])) - class(value) <- c("summaryDefault", "table") - value + summary(as.double(object), ...) } #' @method [ mic @@ -281,85 +315,52 @@ unique.mic <- function(x, incomparables = FALSE, ...) { y } -#' @method range mic +#' @method sort mic #' @export #' @noRd -range.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] +sort.mic <- function(x, decreasing = FALSE, ...) { + if (decreasing == TRUE) { + ord <- order(-as.double(x)) + } else { + ord <- order(as.double(x)) } - out <- c(as.character(rng[1]), as.character(rng[length(rng)])) - as.double(as.mic(out)) + x[ord] } -#' @method min mic +#' @method hist mic #' @export #' @noRd -min.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] - } - as.double(as.mic(as.character(rng[1]))) +hist.mic <- function(x, ...) { + warning_("Use `plot()` or `ggplot()` for plotting MIC values", call = FALSE) + hist(log2(x)) } -#' @method max mic -#' @export -#' @noRd -max.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] - } - as.double(as.mic(as.character(rng[length(rng)]))) +# will be exported using s3_register() in R/zzz.R +get_skimmers.mic <- function(column) { + skimr::sfl( + skim_type = "mic", + min = ~min(., na.rm = TRUE), + max = ~max(., na.rm = TRUE), + median = ~median(., na.rm = TRUE), + n_unique = ~pm_n_distinct(., na.rm = TRUE), + hist_log2 = ~skimr::inline_hist(log2(stats::na.omit(.))) + ) } -#' @method sum mic -#' @export -#' @noRd -sum.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] - } - sum(as.double(rng)) -} - -#' @method all mic -#' @export -#' @noRd -all.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] - } - all(as.double(rng)) -} - -#' @method any mic -#' @export -#' @noRd -any.mic <- function(..., na.rm = FALSE) { - rng <- sort(c(...)) - if (na.rm == TRUE) { - rng <- rng[!is.na(rng)] - } - any(as.double(rng)) -} +# Miscellaneous mathematical functions ------------------------------------ #' @method mean mic #' @export #' @noRd -mean.mic <- function(x, na.rm = FALSE, ...) { - mean(as.double(x), na.rm = na.rm, ...) +mean.mic <- function(x, trim = 0, na.rm = FALSE, ...) { + mean(as.double(x), trim = trim, na.rm = na.rm, ...) } #' @method median mic #' @export #' @noRd median.mic <- function(x, na.rm = FALSE, ...) { - median(as.double(x), na.rm = na.rm, ...) + stats::median(as.double(x), na.rm = na.rm, ...) } #' @method quantile mic @@ -367,22 +368,236 @@ median.mic <- function(x, na.rm = FALSE, ...) { #' @noRd quantile.mic <- function(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, ...) { - quantile(as.double(x), props = props, na.rm = na.rm, names = names, type = type, ...) + stats::quantile(as.double(x), props = props, na.rm = na.rm, names = names, type = type, ...) } +# Math (see ?groupGeneric) ---------------------------------------------- + +#' @method abs mic +#' @export +#' @noRd +abs.mic <- function(x) { + abs(as.double(x)) +} +#' @method sign mic +#' @export +#' @noRd +sign.mic <- function(x) { + sign(as.double(x)) +} +#' @method sqrt mic +#' @export +#' @noRd +sqrt.mic <- function(x) { + sqrt(as.double(x)) +} #' @method floor mic #' @export #' @noRd floor.mic <- function(x) { floor(as.double(x)) } - #' @method ceiling mic #' @export #' @noRd ceiling.mic <- function(x) { ceiling(as.double(x)) } +#' @method trunc mic +#' @export +#' @noRd +trunc.mic <- function(x, ...) { + trunc(as.double(x), ...) +} +#' @method round mic +#' @export +#' @noRd +round.mic <- function(x, digits = 0) { + round(as.double(x), digits = digits) +} +#' @method signif mic +#' @export +#' @noRd +signif.mic <- function(x, digits = 6) { + signif(as.double(x), digits = digits) +} +#' @method exp mic +#' @export +#' @noRd +exp.mic <- function(x) { + exp(as.double(x)) +} +#' @method log mic +#' @export +#' @noRd +log.mic <- function(x, base = exp(1)) { + log(as.double(x), base = base) +} +#' @method log10 mic +#' @export +#' @noRd +log10.mic <- function(x) { + log10(as.double(x)) +} +#' @method log2 mic +#' @export +#' @noRd +log2.mic <- function(x) { + log2(as.double(x)) +} +#' @method expm1 mic +#' @export +#' @noRd +expm1.mic <- function(x) { + expm1(as.double(x)) +} +#' @method log1p mic +#' @export +#' @noRd +log1p.mic <- function(x) { + log1p(as.double(x)) +} +#' @method cos mic +#' @export +#' @noRd +cos.mic <- function(x) { + cos(as.double(x)) +} +#' @method sin mic +#' @export +#' @noRd +sin.mic <- function(x) { + sin(as.double(x)) +} +#' @method tan mic +#' @export +#' @noRd +tan.mic <- function(x) { + tan(as.double(x)) +} +#' @method cospi mic +#' @export +#' @noRd +cospi.mic <- function(x) { + cospi(as.double(x)) +} +#' @method sinpi mic +#' @export +#' @noRd +sinpi.mic <- function(x) { + sinpi(as.double(x)) +} +#' @method tanpi mic +#' @export +#' @noRd +tanpi.mic <- function(x) { + tanpi(as.double(x)) +} +#' @method acos mic +#' @export +#' @noRd +acos.mic <- function(x) { + acos(as.double(x)) +} +#' @method asin mic +#' @export +#' @noRd +asin.mic <- function(x) { + asin(as.double(x)) +} +#' @method atan mic +#' @export +#' @noRd +atan.mic <- function(x) { + atan(as.double(x)) +} +#' @method cosh mic +#' @export +#' @noRd +cosh.mic <- function(x) { + cosh(as.double(x)) +} +#' @method sinh mic +#' @export +#' @noRd +sinh.mic <- function(x) { + sinh(as.double(x)) +} +#' @method tanh mic +#' @export +#' @noRd +tanh.mic <- function(x) { + tanh(as.double(x)) +} +#' @method acosh mic +#' @export +#' @noRd +acosh.mic <- function(x) { + acosh(as.double(x)) +} +#' @method asinh mic +#' @export +#' @noRd +asinh.mic <- function(x) { + asinh(as.double(x)) +} +#' @method atanh mic +#' @export +#' @noRd +atanh.mic <- function(x) { + atanh(as.double(x)) +} +#' @method lgamma mic +#' @export +#' @noRd +lgamma.mic <- function(x) { + lgamma(as.double(x)) +} +#' @method gamma mic +#' @export +#' @noRd +gamma.mic <- function(x) { + gamma(as.double(x)) +} +#' @method digamma mic +#' @export +#' @noRd +digamma.mic <- function(x) { + digamma(as.double(x)) +} +#' @method trigamma mic +#' @export +#' @noRd +trigamma.mic <- function(x) { + trigamma(as.double(x)) +} +#' @method cumsum mic +#' @export +#' @noRd +cumsum.mic <- function(x) { + cumsum(as.double(x)) +} +#' @method cumprod mic +#' @export +#' @noRd +cumprod.mic <- function(x) { + cumprod(as.double(x)) +} +#' @method cummax mic +#' @export +#' @noRd +cummax.mic <- function(x) { + cummax(as.double(x)) +} +#' @method cummin mic +#' @export +#' @noRd +cummin.mic <- function(x) { + cummin(as.double(x)) +} + +# Ops (see ?groupGeneric) ----------------------------------------------- + #' @method + mic #' @export @@ -433,6 +648,27 @@ ceiling.mic <- function(x) { as.double(e1) %/% as.double(e2) } +#' @method & mic +#' @export +#' @noRd +`&.mic` <- function(e1, e2) { + as.double(e1) & as.double(e2) +} + +#' @method | mic +#' @export +#' @noRd +`|.mic` <- function(e1, e2) { + as.double(e1) | as.double(e2) +} + +#' @method ! mic +#' @export +#' @noRd +`!.mic` <- function(x) { + !as.double(x) +} + #' @method == mic #' @export #' @noRd @@ -475,36 +711,47 @@ ceiling.mic <- function(x) { as.double(e1) > as.double(e2) } -#' @method sort mic +# Summary (see ?groupGeneric) ------------------------------------------- + +#' @method all mic #' @export #' @noRd -sort.mic <- function(x, decreasing = FALSE, ...) { - if (decreasing == TRUE) { - ord <- order(-as.double(x)) - } else { - ord <- order(as.double(x)) - } - x[ord] +all.mic <- function(..., na.rm = FALSE) { + all(as.double(c(...)), na.rm = na.rm) } - - - -#' @method hist mic +#' @method any mic #' @export #' @noRd -hist.mic <- function(x, ...) { - warning_("Use `plot()` or `ggplot()` for plotting MIC values", call = FALSE) - hist(as.double(x), ...) +any.mic <- function(..., na.rm = FALSE) { + any(as.double(c(...)), na.rm = na.rm) } - -# will be exported using s3_register() in R/zzz.R -get_skimmers.mic <- function(column) { - skimr::sfl( - skim_type = "mic", - min = ~as.character(sort(stats::na.omit(.))[1]), - max = ~as.character(sort(stats::na.omit(.))[length(stats::na.omit(.))]), - median = ~as.character(stats::na.omit(.)[as.double(stats::na.omit(.)) == median(as.double(stats::na.omit(.)))])[1], - n_unique = ~pm_n_distinct(., na.rm = TRUE), - hist_log2 = ~skimr::inline_hist(log2(as.double(stats::na.omit(.)))) - ) +#' @method sum mic +#' @export +#' @noRd +sum.mic <- function(..., na.rm = FALSE) { + sum(as.double(c(...)), na.rm = na.rm) +} +#' @method prod mic +#' @export +#' @noRd +prod.mic <- function(..., na.rm = FALSE) { + prod(as.double(c(...)), na.rm = na.rm) +} +#' @method min mic +#' @export +#' @noRd +min.mic <- function(..., na.rm = FALSE) { + min(as.double(c(...)), na.rm = na.rm) +} +#' @method max mic +#' @export +#' @noRd +max.mic <- function(..., na.rm = FALSE) { + max(as.double(c(...)), na.rm = na.rm) +} +#' @method range mic +#' @export +#' @noRd +range.mic <- function(..., na.rm = FALSE) { + range(as.double(c(...)), na.rm = na.rm) } diff --git a/R/pca.R b/R/pca.R index 5a06a1326..9d592cb15 100755 --- a/R/pca.R +++ b/R/pca.R @@ -26,7 +26,7 @@ #' Principal Component Analysis (for AMR) #' #' Performs a principal component analysis (PCA) based on a data set with automatic determination for afterwards plotting the groups and labels, and automatic filtering on only suitable (i.e. non-empty and numeric) variables. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param x a [data.frame] containing numeric columns #' @param ... columns of `x` to be selected for PCA, can be unquoted since it supports quasiquotation. #' @inheritParams stats::prcomp diff --git a/R/plot.R b/R/plot.R index 1fbaf3da4..23b4028fc 100644 --- a/R/plot.R +++ b/R/plot.R @@ -108,7 +108,6 @@ plot.mic <- function(x, fn = as.mic, language = language, ...) - barplot(x, col = cols_sub$cols, main = main, @@ -116,7 +115,7 @@ plot.mic <- function(x, ylab = ylab, xlab = xlab, axes = FALSE) - axis(2, seq(0, max(as.double(x)))) + axis(2, seq(0, max(x))) if (!is.null(cols_sub$sub)) { mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub) } @@ -124,15 +123,15 @@ plot.mic <- function(x, if (any(colours_RSI %in% cols_sub$cols)) { legend_txt <- character(0) legend_col <- character(0) - if (colours_RSI[2] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[2] & cols_sub$count > 0)) { legend_txt <- "Susceptible" legend_col <- colours_RSI[2] } - if (colours_RSI[3] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[3] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) legend_col <- c(legend_col, colours_RSI[3]) } - if (colours_RSI[1] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[1] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, "Resistant") legend_col <- c(legend_col, colours_RSI[1]) } @@ -317,15 +316,15 @@ plot.disk <- function(x, if (any(colours_RSI %in% cols_sub$cols)) { legend_txt <- character(0) legend_col <- character(0) - if (colours_RSI[1] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[1] & cols_sub$count > 0)) { legend_txt <- "Resistant" legend_col <- colours_RSI[1] } - if (colours_RSI[3] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[3] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, plot_name_of_I(cols_sub$guideline)) legend_col <- c(legend_col, colours_RSI[3]) } - if (colours_RSI[2] %in% cols_sub$cols) { + if (any(cols_sub$cols == colours_RSI[2] & cols_sub$count > 0)) { legend_txt <- c(legend_txt, "Susceptible") legend_col <- c(legend_col, colours_RSI[2]) } @@ -459,8 +458,8 @@ plot_prepare_table <- function(x, expand) { if (is.mic(x)) { if (expand == TRUE) { # expand range for MIC by adding factors of 2 from lowest to highest so all MICs in between also print - extra_range <- max(as.double(x)) / 2 - while (min(extra_range) / 2 > min(as.double(x))) { + extra_range <- max(x) / 2 + while (min(extra_range) / 2 > min(x)) { extra_range <- c(min(extra_range) / 2, extra_range) } nms <- extra_range @@ -525,7 +524,7 @@ plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_RSI, f cols <- "#BEBEBE" sub <- NULL } - list(cols = cols, sub = sub, guideline = guideline) + list(cols = cols, count = as.double(x), sub = sub, guideline = guideline) } diff --git a/R/random.R b/R/random.R index b4db99a49..96686f437 100644 --- a/R/random.R +++ b/R/random.R @@ -26,7 +26,7 @@ #' Random MIC Values/Disk Zones/RSI Generation #' #' These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice. By providing a microorganism and antimicrobial agent, the generated results will reflect reality as much as possible. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param size desired size of the returned vector #' @param mo any character that can be coerced to a valid microorganism code with [as.mo()] #' @param ab any character that can be coerced to a valid antimicrobial agent code with [as.ab()] @@ -119,7 +119,15 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) { valid_mics <- suppressWarnings(as.mic(set_range_max / (2 ^ c(-3:3)))) set_range <- valid_mics[!is.na(valid_mics)] } - return(as.mic(sample(set_range, size = size, replace = TRUE))) + out <- as.mic(sample(set_range, size = size, replace = TRUE)) + # 50% chance that lowest will get <= and highest will get >= + if (runif(1) > 0.5) { + out[out == min(out)] <- paste0("<=", out[out == min(out)]) + } + if (runif(1) > 0.5) { + out[out == max(out)] <- paste0(">=", out[out == max(out)]) + } + return(out) } else if (type == "DISK") { set_range <- seq(from = as.integer(min(df$breakpoint_R) / 1.25), to = as.integer(max(df$breakpoint_S) * 1.25), diff --git a/R/resistance_predict.R b/R/resistance_predict.R index 6dabf08f9..37850b26c 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -26,7 +26,7 @@ #' Predict antimicrobial resistance #' #' Create a prediction model to predict antimicrobial resistance for the next years on statistical solid ground. Standard errors (SE) will be returned as columns `se_min` and `se_max`. See *Examples* for a real live example. -#' @inheritSection lifecycle Maturing Lifecycle +#' @inheritSection lifecycle Stable Lifecycle #' @param col_ab column name of `x` containing antimicrobial interpretations (`"R"`, `"I"` and `"S"`) #' @param col_date column name of the date, will be used to calculate years if this column doesn't consist of years already, defaults to the first column of with a date class #' @param year_min lowest year to use in the prediction model, dafaults to the lowest year in `col_date` diff --git a/R/sysdata.rda b/R/sysdata.rda index ef5972b93..34b3bf963 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 58082bf81..5d2418ea7 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/data-raw/translations.tsv b/data-raw/translations.tsv index 7c717c3bd..5867097bc 100644 --- a/data-raw/translations.tsv +++ b/data-raw/translations.tsv @@ -33,7 +33,7 @@ no .*growth TRUE FALSE FALSE keine? .*wachstum geen .*groei no .*crecimientonon no|not TRUE FALSE FALSE keine? geen|niet no|sin sem non sem Susceptible TRUE FALSE FALSE Empfindlich Gevoelig Susceptible Intermediate TRUE FALSE FALSE Mittlere Intermediair Intermedio -Incr. exposure TRUE FALSE FALSE Empfindlich, erh Belastung Gevoelig, 'incr. exposure' Susceptible, 'incr. exposure' +Incr. exposure TRUE FALSE FALSE Empfindlich, erh Belastung 'Incr. exposure' 'Incr. exposure' Resistant TRUE FALSE FALSE Resistent Resistent Resistente antibiotic TRUE TRUE FALSE Antibiotikum antibioticum antibiótico Antibiotic TRUE TRUE FALSE Antibiotikum Antibioticum Antibiótico diff --git a/docs/404.html b/docs/404.html index aaec42545..384d81918 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 90b478fb2..a9760c799 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/articles/index.html b/docs/articles/index.html index 1c81f590e..ec18f4851 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/authors.html b/docs/authors.html index 2d5ef9480..9d72424d2 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/index.html b/docs/index.html index 17aa1cb3e..c383c5428 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/news/index.html b/docs/news/index.html index 96a8ff0ae..0ac411985 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 @@ -236,13 +236,13 @@ Source: NEWS.md -
-

-AMR 1.5.0.9031 Unreleased +
+

+AMR 1.5.0.9032 Unreleased

-
+

-Last updated: 5 March 2021 +Last updated: 7 March 2021

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c9cb9d8b7..eb26337dd 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: datasets: datasets.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2021-03-05T14:27Z +last_built: 2021-03-07T12:50Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/AMR.html b/docs/reference/AMR.html index 72404ce16..a3a499ee9 100644 --- a/docs/reference/AMR.html +++ b/docs/reference/AMR.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032

diff --git a/docs/reference/ab_from_text.html b/docs/reference/ab_from_text.html index ec9af198b..7acd3e4cd 100644 --- a/docs/reference/ab_from_text.html +++ b/docs/reference/ab_from_text.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9032
@@ -301,12 +301,13 @@

With using collapse, this function will return a character:
df %>% mutate(abx = ab_from_text(clinical_text, collapse = "|"))

-

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/as.mic.html b/docs/reference/as.mic.html index 6d4310c59..d365c7786 100644 --- a/docs/reference/as.mic.html +++ b/docs/reference/as.mic.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032
@@ -239,7 +239,7 @@
-

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() and trunc().

Stable Lifecycle

diff --git a/docs/reference/ggplot_pca.html b/docs/reference/ggplot_pca.html index a181e9924..c36a23185 100644 --- a/docs/reference/ggplot_pca.html +++ b/docs/reference/ggplot_pca.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9013 + 1.5.0.9032

@@ -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() or scale_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 5c0a82993..1bde674db 100644
--- a/docs/reference/ggplot_rsi.html
+++ b/docs/reference/ggplot_rsi.html
@@ -82,7 +82,7 @@
       
       
         AMR (for R)
-        1.5.0.9031
+        1.5.0.9032
       
     
 
@@ -415,12 +415,13 @@
 

labels_rsi_count() print datalabels on the bars with percentage and amount of isolates using ggplot2::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 20f7dab1f..21854e2d6 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/docs/reference/pca.html b/docs/reference/pca.html index 06ac67fcc..67b206778 100644 --- a/docs/reference/pca.html +++ b/docs/reference/pca.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9016 + 1.5.0.9032 @@ -311,12 +311,13 @@

The pca() function takes a data.frame as input and performs the actual PCA with the R function prcomp().

The result of the pca() function is a prcomp object, with an additional attribute 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 ggplot_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 2ae80980c..5c21b3c6f 100644 --- a/docs/reference/random.html +++ b/docs/reference/random.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 @@ -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/or ab 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 cac77c594..fc2c38522 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9019 + 1.5.0.9032 @@ -364,12 +364,13 @@
  • "lin" or "linear": a linear regression model

  • -

    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.

    Interpretation of R and S/I

    diff --git a/docs/survey.html b/docs/survey.html index 1b8f50b14..8ac19a600 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9031 + 1.5.0.9032 diff --git a/man/ab_from_text.Rd b/man/ab_from_text.Rd index 044feec80..387f02988 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 93c912602..a4ae80902 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 55ed68b91..dde88f829 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 2d4f768f3..7c05e8c7f 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 84988c472..f7f441e0b 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 63a09483d..93b0c3090 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 d90029a64..19cc4a8d8 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 a30fefbfa..0befef74b 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)) +})