diff --git a/.Rbuildignore b/.Rbuildignore index 004dd495..3c2145c5 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -25,7 +25,6 @@ ^vignettes/AMR.Rmd$ ^vignettes/benchmarks.Rmd$ ^vignettes/EUCAST.Rmd$ -^vignettes/MDR.Rmd$ ^vignettes/PCA.Rmd$ ^vignettes/resistance_predict.Rmd$ ^vignettes/SPSS.Rmd$ diff --git a/DESCRIPTION b/DESCRIPTION index 29954dc8..cfe64475 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.5.0.9009 -Date: 2021-01-22 +Version: 1.5.0.9010 +Date: 2021-01-24 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index c31e390f..54a68cb2 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.5.0.9009 -## Last updated: 22 January 2021 +# AMR 1.5.0.9010 +## Last updated: 24 January 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. @@ -34,6 +34,7 @@ * WHONET code `"PNV"` will now correctly be interpreted as `PHN`, the antibiotic code for phenoxymethylpenicillin ('peni V') * Fix for verbose output of `mdro(..., verbose = TRUE)` for German guideline (3MGRN and 4MGRN) and Dutch guideline (BRMO, only *P. aeruginosa*) * `is.rsi.eligible()` now returns `FALSE` immediately if the input does not contain any of the values "R", "S" or "I". This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns. +* Functions `get_episode()` and `is_new_episode()` now support less than a day as value for argument `episode_days` (e.g., to include one patient/test per hour) ### Other * Big documentation updates diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index fc5dbbb0..b8961bb6 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -458,9 +458,9 @@ vector_or <- function(v, quotes = TRUE, reverse = FALSE) { format_class <- function(class, plural) { class.bak <- class - class[class %in% c("numeric", "double")] <- "number" + class[class == "numeric"] <- "number" class[class == "integer"] <- "whole number" - if (any(c("numeric", "double") %in% class.bak, na.rm = TRUE) & "integer" %in% class.bak) { + if (all(c("numeric", "integer") %in% class.bak, na.rm = TRUE)) { class[class %in% c("number", "whole number")] <- "(whole) number" } class[class == "character"] <- "text string" @@ -496,6 +496,8 @@ meet_criteria <- function(object, has_length = NULL, looks_like = NULL, is_in = NULL, + is_positive = NULL, + is_finite = NULL, contains_column_class = NULL, allow_NULL = FALSE, allow_NA = FALSE, @@ -504,6 +506,16 @@ meet_criteria <- function(object, obj_name <- deparse(substitute(object)) call_depth <- -2 - abs(.call_depth) + + # if object is missing, or another error: + tryCatch(invisible(object), + error = function(e) pkg_env$meet_criteria_error_txt <- e$message) + if (!is.null(pkg_env$meet_criteria_error_txt)) { + error_txt <- pkg_env$meet_criteria_error_txt + pkg_env$meet_criteria_error_txt <- NULL + stop(error_txt, call. = FALSE) + } + pkg_env$meet_criteria_error_txt <- NULL if (is.null(object)) { stop_if(allow_NULL == FALSE, "argument `", obj_name, "` must not be NULL", call = call_depth) @@ -552,6 +564,24 @@ meet_criteria <- function(object, vector_or(is_in, quotes = !isTRUE(any(c("double", "numeric", "integer") %in% allow_class))), call = call_depth) } + if (!is.null(is_positive)) { + stop_if(is.numeric(object) && !all(object > 0, na.rm = TRUE), "argument `", obj_name, + "` must ", + ifelse(!is.null(has_length) && length(has_length) == 1 && has_length == 1, + "be a positive number", + "all be positive numbers"), + " (higher than zero)", + call = call_depth) + } + if (!is.null(is_finite)) { + stop_if(is.numeric(object) && !all(is.finite(object[!is.na(object)]), na.rm = TRUE), "argument `", obj_name, + "` must ", + ifelse(!is.null(has_length) && length(has_length) == 1 && has_length == 1, + "be a finite number", + "all be finite numbers"), + " (i.e., not be infinite)", + call = call_depth) + } if (!is.null(contains_column_class)) { stop_ifnot(any(vapply(FUN.VALUE = logical(1), object, diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index ddbcfc21..5cbf3cef 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -38,7 +38,7 @@ #' @inheritSection AMR Reference Data Publicly Available #' @inheritSection AMR Read more on Our Website! #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' #' # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): diff --git a/R/age.R b/R/age.R index 430fc70a..7af36687 100755 --- a/R/age.R +++ b/R/age.R @@ -149,8 +149,8 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) { #' } #' } age_groups <- function(x, split_at = c(12, 25, 55, 75), na.rm = FALSE) { - meet_criteria(x, allow_class = c("numeric", "integer")) - meet_criteria(split_at, allow_class = c("numeric", "integer", "character")) + meet_criteria(x, allow_class = c("numeric", "integer"), is_positive = TRUE, is_finite = TRUE) + meet_criteria(split_at, allow_class = c("numeric", "integer", "character"), is_positive = TRUE, is_finite = TRUE) meet_criteria(na.rm, allow_class = "logical", has_length = 1) if (any(x < 0, na.rm = TRUE)) { diff --git a/R/availability.R b/R/availability.R index 0a537438..730a99b6 100644 --- a/R/availability.R +++ b/R/availability.R @@ -44,7 +44,7 @@ #' } availability <- function(tbl, width = NULL) { meet_criteria(tbl, allow_class = "data.frame") - meet_criteria(width, allow_class = "numeric", allow_NULL = TRUE) + meet_criteria(width, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE) x <- vapply(FUN.VALUE = double(1), tbl, function(x) { 1 - sum(is.na(x)) / length(x) diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index fbae0192..c9981683 100644 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -129,7 +129,7 @@ format.bug_drug_combinations <- function(x, meet_criteria(x, allow_class = "data.frame") meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(combine_SI, allow_class = "logical", has_length = 1) meet_criteria(combine_IR, allow_class = "logical", has_length = 1) meet_criteria(add_ab_group, allow_class = "logical", has_length = 1) diff --git a/R/disk.R b/R/disk.R index e470c1dc..1108f111 100644 --- a/R/disk.R +++ b/R/disk.R @@ -61,7 +61,7 @@ as.disk <- function(x, na.rm = FALSE) { meet_criteria(na.rm, allow_class = "logical", has_length = 1) if (!is.disk(x)) { - x <- x %pm>% unlist() + x <- unlist(x) if (na.rm == TRUE) { x <- x[!is.na(x)] } diff --git a/R/episode.R b/R/episode.R index 8630a2ce..0ffcad34 100644 --- a/R/episode.R +++ b/R/episode.R @@ -28,8 +28,8 @@ #' These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument `episode_days`. This can be used to determine clinical episodes for any epidemiological analysis. The [get_episode()] function returns the index number of the episode per group, while the [is_new_episode()] function returns values `TRUE`/`FALSE` to indicate whether an item in a vector is the start of a new episode. #' @inheritSection lifecycle Stable Lifecycle #' @param x vector of dates (class `Date` or `POSIXt`) -#' @param episode_days length of the required episode in days, see *Details* -#' @param ... arguments passed on to [as.Date()] +#' @param episode_days required episode length in days, can also be less than a day, see *Details* +#' @param ... arguments passed on to [as.POSIXct()] #' @details #' Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least `episode_days` days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least `episode_days` days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored. #' @@ -44,15 +44,20 @@ #' @export #' @inheritSection AMR Read more on Our Website! #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' -#' get_episode(example_isolates$date, episode_days = 60) -#' is_new_episode(example_isolates$date, episode_days = 60) +#' get_episode(example_isolates$date, episode_days = 60) # indices +#' is_new_episode(example_isolates$date, episode_days = 60) # TRUE/FALSE #' #' # filter on results from the third 60-day episode only, using base R #' example_isolates[which(get_episode(example_isolates$date, 60) == 3), ] #' +#' # the functions also work for less than a day, e.g. to include one per hour: +#' get_episode(c(Sys.time(), +#' Sys.time() + 60 * 60), +#' episode_days = 1/24) +#' #' \donttest{ #' if (require("dplyr")) { #' # is_new_episode() can also be used in dplyr verbs to determine patient @@ -100,7 +105,9 @@ #' } get_episode <- function(x, episode_days, ...) { meet_criteria(x, allow_class = c("Date", "POSIXt")) - meet_criteria(episode_days, allow_class = c("numeric", "double", "integer"), has_length = 1) + meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + stop_if(inherits(x, "Date") & episode_days < 1, + "argument `episode_days` must be at least 1 (day) when `x` is not a date-time object") exec_episode(type = "sequential", x = x, @@ -112,7 +119,9 @@ get_episode <- function(x, episode_days, ...) { #' @export is_new_episode <- function(x, episode_days, ...) { meet_criteria(x, allow_class = c("Date", "POSIXt")) - meet_criteria(episode_days, allow_class = c("numeric", "double", "integer"), has_length = 1) + meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + stop_if(inherits(x, "Date") & episode_days < 1, + "argument `episode_days` must be at least 1 (day) when `x` is not a date-time object") exec_episode(type = "logical", x = x, @@ -121,7 +130,10 @@ is_new_episode <- function(x, episode_days, ...) { } exec_episode <- function(type, x, episode_days, ...) { - x <- as.double(as.Date(x, ...)) # as.Date() for POSIX classes + x <- as.double(as.POSIXct(x, ...)) # as.POSIXct() for Date classes + # since x is now in seconds, get seconds from episode_days as well + episode_seconds <- episode_days * 60 * 60 * 24 + if (length(x) == 1) { if (type == "logical") { return(TRUE) @@ -129,7 +141,7 @@ exec_episode <- function(type, x, episode_days, ...) { return(1) } } else if (length(x) == 2) { - if (max(x) - min(x) >= episode_days) { + if (max(x) - min(x) >= episode_seconds) { if (type == "logical") { return(c(TRUE, TRUE)) } else if (type == "sequential") { @@ -146,13 +158,13 @@ exec_episode <- function(type, x, episode_days, ...) { # I asked on StackOverflow: # https://stackoverflow.com/questions/42122245/filter-one-row-every-year - exec <- function(x, episode_days) { + exec <- function(x, episode_seconds) { indices <- integer() start <- x[1] ind <- 1 indices[1] <- 1 for (i in 2:length(x)) { - if (isTRUE((x[i] - start) >= episode_days)) { + if (isTRUE((x[i] - start) >= episode_seconds)) { ind <- ind + 1 if (type == "logical") { indices[ind] <- i @@ -175,7 +187,7 @@ exec_episode <- function(type, x, episode_days, ...) { df <- data.frame(x = x, y = seq_len(length(x))) %pm>% pm_arrange(x) - df$new <- exec(df$x, episode_days) + df$new <- exec(df$x, episode_seconds) df %pm>% pm_arrange(y) %pm>% pm_pull(new) diff --git a/R/first_isolate.R b/R/first_isolate.R index e376d297..78b6ad1e 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -46,7 +46,7 @@ #' @param include_unknown logical to determine whether 'unknown' microorganisms should be included too, i.e. microbial code `"UNKNOWN"`, which defaults to `FALSE`. For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default. Isolates with a microbial ID of `NA` will always be excluded as first isolate. #' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], or arguments passed on to [key_antibiotics()] when using [filter_first_weighted_isolate()] #' @details -#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*. +#' These functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*. #' #' The [first_isolate()] function is a wrapper around the [is_new_episode()] function, but more efficient for data sets containing microorganism codes or names. #' @@ -96,7 +96,7 @@ #' **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition**, 2014, *Clinical and Laboratory Standards Institute (CLSI)*. . #' @inheritSection AMR Read more on Our Website! #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' #' # basic filtering on first isolates @@ -172,20 +172,20 @@ first_isolate <- function(x, col_keyantibiotics <- NULL } meet_criteria(col_keyantibiotics, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) - meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(testcodes_exclude, allow_class = "character", allow_NULL = TRUE) meet_criteria(icu_exclude, allow_class = "logical", has_length = 1) meet_criteria(specimen_group, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(type, allow_class = "character", has_length = 1) meet_criteria(ignore_I, allow_class = "logical", has_length = 1) - meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(info, allow_class = "logical", has_length = 1) meet_criteria(include_unknown, allow_class = "logical", has_length = 1) dots <- unlist(list(...)) if (length(dots) != 0) { # backwards compatibility with old arguments - dots.names <- dots %pm>% names() + dots.names <- names(dots) if ("filter_specimen" %in% dots.names) { specimen_group <- dots[which(dots.names == "filter_specimen")] } diff --git a/R/ggplot_pca.R b/R/ggplot_pca.R index 8180c5db..7671cc1a 100755 --- a/R/ggplot_pca.R +++ b/R/ggplot_pca.R @@ -61,7 +61,7 @@ #' @rdname ggplot_pca #' @export #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' #' # See ?pca for more info about Principal Component Analysis (PCA). @@ -109,26 +109,26 @@ ggplot_pca <- function(x, stop_ifnot_installed("ggplot2") meet_criteria(x, allow_class = c("prcomp", "princomp", "PCA", "lda")) - meet_criteria(choices, allow_class = c("numeric", "integer"), has_length = 2) + meet_criteria(choices, allow_class = c("numeric", "integer"), has_length = 2, is_positive = TRUE, is_finite = TRUE) meet_criteria(scale, allow_class = c("numeric", "integer", "logical"), has_length = 1) meet_criteria(pc.biplot, allow_class = "logical", has_length = 1) meet_criteria(labels, allow_class = "character", allow_NULL = TRUE) - meet_criteria(labels_textsize, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(labels_text_placement, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(labels_textsize, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(labels_text_placement, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(groups, allow_class = "character", allow_NULL = TRUE) meet_criteria(ellipse, allow_class = "logical", has_length = 1) - meet_criteria(ellipse_prob, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(ellipse_size, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(ellipse_alpha, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(points_size, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(points_alpha, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(ellipse_prob, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(ellipse_size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(ellipse_alpha, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(points_size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(points_alpha, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(arrows, allow_class = "logical", has_length = 1) meet_criteria(arrows_colour, allow_class = "character", has_length = 1) - meet_criteria(arrows_size, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(arrows_textsize, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(arrows_size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(arrows_textsize, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(arrows_textangled, allow_class = "logical", has_length = 1) - meet_criteria(arrows_alpha, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(base_textsize, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(arrows_alpha, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(base_textsize, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) calculations <- pca_calculations(pca_model = x, groups = groups, diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 049157b9..ced70105 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -180,12 +180,12 @@ ggplot_rsi <- function(data, meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE) meet_criteria(combine_SI, allow_class = "logical", has_length = 1) meet_criteria(combine_IR, allow_class = "logical", has_length = 1) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE) - meet_criteria(nrow, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE) + meet_criteria(nrow, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE) meet_criteria(colours, allow_class = c("character", "logical")) meet_criteria(datalabels, allow_class = "logical", has_length = 1) - meet_criteria(datalabels.size, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(datalabels.size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(datalabels.colour, allow_class = "character", has_length = 1) meet_criteria(title, allow_class = "character", has_length = 1, allow_NULL = TRUE) meet_criteria(subtitle, allow_class = "character", has_length = 1, allow_NULL = TRUE) @@ -279,7 +279,7 @@ geom_rsi <- function(position = NULL, meet_criteria(x, allow_class = "character", has_length = 1) meet_criteria(fill, allow_class = "character", has_length = 1) meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE) meet_criteria(combine_SI, allow_class = "logical", has_length = 1) meet_criteria(combine_IR, allow_class = "logical", has_length = 1) @@ -327,7 +327,7 @@ facet_rsi <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { facet <- facet[1] stop_ifnot_installed("ggplot2") meet_criteria(facet, allow_class = "character", has_length = 1) - meet_criteria(nrow, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE) + meet_criteria(nrow, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE) # we work with aes_string later on facet_deparse <- deparse(substitute(facet)) @@ -414,11 +414,11 @@ labels_rsi_count <- function(position = NULL, meet_criteria(position, allow_class = "character", has_length = 1, is_in = c("fill", "stack", "dodge"), allow_NULL = TRUE) meet_criteria(x, allow_class = "character", has_length = 1) meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE) meet_criteria(combine_SI, allow_class = "logical", has_length = 1) meet_criteria(combine_IR, allow_class = "logical", has_length = 1) - meet_criteria(datalabels.size, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(datalabels.size, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(datalabels.colour, allow_class = "character", has_length = 1) if (is.null(position)) { diff --git a/R/key_antibiotics.R b/R/key_antibiotics.R index 518416e5..1d884bba 100755 --- a/R/key_antibiotics.R +++ b/R/key_antibiotics.R @@ -27,7 +27,7 @@ #' #' These function can be used to determine first isolates (see [first_isolate()]). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates can then be called first 'weighted' isolates. #' @inheritSection lifecycle Stable Lifecycle -#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. +#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank to determine automatically #' @param y,z character vectors to compare #' @inheritParams first_isolate #' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of **broad-spectrum** antibiotics, case-insensitive. See details for which antibiotics will be used at default (which are guessed with [guess_ab_col()]). @@ -36,7 +36,7 @@ #' @param warnings give a warning about missing antibiotic columns (they will be ignored) #' @param ... other arguments passed on to functions #' @details -#' The [key_antibiotics()] function is context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*. +#' The [key_antibiotics()] function is context-aware. This means that then the `x` argument can be left blank, see *Examples*. #' #' The function [key_antibiotics()] returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using [key_antibiotics_equal()], to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (`"."`) by [key_antibiotics()] and ignored by [key_antibiotics_equal()]. #' @@ -77,7 +77,7 @@ #' @seealso [first_isolate()] #' @inheritSection AMR Read more on Our Website! #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' #' # output of the `key_antibiotics()` function could be like this: @@ -158,7 +158,7 @@ key_antibiotics <- function(x, dots <- unlist(list(...)) if (length(dots) != 0) { # backwards compatibility with old arguments - dots.names <- dots %pm>% names() + dots.names <- names(dots) if ("info" %in% dots.names) { warnings <- dots[which(dots.names == "info")] } @@ -291,7 +291,7 @@ key_antibiotics_equal <- function(y, meet_criteria(z, allow_class = "character") meet_criteria(type, allow_class = "character", has_length = c(1, 2)) meet_criteria(ignore_I, allow_class = "logical", has_length = 1) - meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(info, allow_class = "logical", has_length = 1) stop_ifnot(length(y) == length(z), "length of `y` and `z` must be equal") diff --git a/R/mdro.R b/R/mdro.R index 28770e7e..7b3b1dbb 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -37,7 +37,7 @@ #' @param verbose a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not. #' @inheritSection eucast_rules Antibiotics #' @details -#' These functions are context-aware when used inside `dplyr` verbs, such as `filter()`, `mutate()` and `summarise()`. This means that then the `x` argument can be left blank, see *Examples*. +#' These functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*. #' #' For the `pct_required_classes` argument, values above 1 will be divided by 100. This is to support both fractions (`0.75` or `3/4`) and percentages (`75`). #' @@ -108,7 +108,7 @@ #' #> 43 891 1066 #' ``` #' -#' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()], +#' The rules set (the `custom` object in this case) could be exported to a shared file location using [saveRDS()] if you collaborate with multiple users. The custom rules set could then be imported using [readRDS()]. #' @inheritSection as.rsi Interpretation of R and S/I #' @return #' - CMI 2012 paper - function [mdr_cmi2012()] or [mdro()]:\cr diff --git a/R/mic.R b/R/mic.R index 9460455d..e418869e 100755 --- a/R/mic.R +++ b/R/mic.R @@ -62,7 +62,7 @@ as.mic <- function(x, na.rm = FALSE) { if (is.mic(x)) { x } else { - x <- x %pm>% unlist() + x <- unlist(x) if (na.rm == TRUE) { x <- x[!is.na(x)] } diff --git a/R/mo.R b/R/mo.R index 42f4b5cd..ad4a7faf 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1546,7 +1546,7 @@ exec_as.mo <- function(x, message_(word_wrap("- Try to use as many valid taxonomic names as possible for your input.", extra_indent = 2), as_note = FALSE) - message_(word_wrap("- Save the output and use it as input for future calculations, e.g. create a new variable to your data using `as.mo()`. All functions in this package that rely on microorganism codes will automatically use that new column where possible. All `mo_*()` functions also do not require you to set their `x` argument as long as you have the dplyr package installed and you have a column of class .", + message_(word_wrap("- Save the output and use it as input for future calculations, e.g. create a new variable to your data using `as.mo()`. All functions in this package that rely on microorganism codes will automatically use that new column where possible. All `mo_*()` functions also do not require you to set their `x` argument as long as you have a column of class .", extra_indent = 2), as_note = FALSE) message_(word_wrap("- Use `set_mo_source()` to continually transform your organisation codes to microorganisms codes used by this package, see `?mo_source`.", diff --git a/R/mo_source.R b/R/mo_source.R index efa42b34..ff4a74e8 100644 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -200,8 +200,8 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s "', for which your permission is needed.")), "\n\n", word_wrap("Do you agree that this file will be created?")) - if ("rsasdtudioapi" %in% rownames(utils::installed.packages())) { - showQuestion <- import_fn("showQuestion", "rstudioapi") + showQuestion <- import_fn("showQuestion", "rstudioapi", error_on_fail = FALSE) + if (!is.null(showQuestion)) { q_continue <- showQuestion("Create new file in home directory", txt) } else { q_continue <- utils::menu(choices = c("OK", "Cancel"), graphics = FALSE, title = txt) diff --git a/R/pca.R b/R/pca.R index 914e2979..46f8f957 100755 --- a/R/pca.R +++ b/R/pca.R @@ -38,7 +38,7 @@ #' @export #' @inheritSection AMR Read more on Our Website! #' @examples -#' # `example_isolates` is a dataset available in the AMR package. +#' # `example_isolates` is a data set available in the AMR package. #' # See ?example_isolates. #' #' \donttest{ diff --git a/R/resistance_predict.R b/R/resistance_predict.R index 87fa244c..bf10a778 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -129,10 +129,10 @@ resistance_predict <- function(x, meet_criteria(x, allow_class = "data.frame") meet_criteria(col_ab, allow_class = "character", has_length = 1, is_in = colnames(x)) meet_criteria(col_date, allow_class = "character", has_length = 1, is_in = colnames(x), allow_NULL = TRUE) - meet_criteria(year_min, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE) - meet_criteria(year_max, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE) - meet_criteria(year_every, allow_class = c("numeric", "integer"), has_length = 1) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(year_min, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE) + meet_criteria(year_max, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE) + meet_criteria(year_every, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE) meet_criteria(model, allow_class = c("character", "function"), has_length = 1, allow_NULL = TRUE) meet_criteria(I_as_S, allow_class = "logical", has_length = 1) meet_criteria(preserve_measurements, allow_class = "logical", has_length = 1) @@ -143,7 +143,7 @@ resistance_predict <- function(x, dots <- unlist(list(...)) if (length(dots) != 0) { # backwards compatibility with old arguments - dots.names <- dots %pm>% names() + dots.names <- names(dots) if ("tbl" %in% dots.names) { x <- dots[which(dots.names == "tbl")] } diff --git a/R/rsi.R b/R/rsi.R index f30b038f..c8210e58 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -29,7 +29,7 @@ #' @inheritSection lifecycle Stable Lifecycle #' @rdname as.rsi #' @param x vector of values (for class [`mic`]: an MIC value in mg/L, for class [`disk`]: a disk diffusion radius in millimetres) -#' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()], will be determined automatically if the `dplyr` package is installed +#' @param mo any (vector of) text that can be coerced to a valid microorganism code with [as.mo()], can be left empty to determine it automatically #' @param ab any (vector of) text that can be coerced to a valid antimicrobial code with [as.ab()] #' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.rsi()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a 'specimen' and rows containing 'urin' (such as 'urine', 'urina') in that column will be regarded isolates from a UTI. See *Examples*. #' @inheritParams first_isolate @@ -479,7 +479,7 @@ as.rsi.data.frame <- function(x, uti = NULL, conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE, - reference_data = rsi_translation) { + reference_data = AMR::rsi_translation) { meet_criteria(x, allow_class = "data.frame") # will also check for dimensions > 0 meet_criteria(col_mo, allow_class = "character", is_in = colnames(x), allow_NULL = TRUE) meet_criteria(guideline, allow_class = "character", has_length = 1) @@ -994,7 +994,7 @@ plot.rsi <- function(x, main = paste("Resistance Overview of", deparse(substitute(x))), axes = FALSE, ...) { - meet_criteria(lwd, allow_class = c("numeric", "integer"), has_length = 1) + meet_criteria(lwd, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) meet_criteria(ylim, allow_class = c("numeric", "integer"), allow_NULL = TRUE) meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(xlab, allow_class = "character", has_length = 1) diff --git a/R/rsi_calc.R b/R/rsi_calc.R index e55c1949..3b1d52c1 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -37,7 +37,7 @@ rsi_calc <- function(..., only_all_tested = FALSE, only_count = FALSE) { meet_criteria(ab_result, allow_class = c("character", "numeric", "integer"), has_length = c(1, 2, 3), .call_depth = 1) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, .call_depth = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, .call_depth = 1) meet_criteria(as_percent, allow_class = "logical", has_length = 1, .call_depth = 1) meet_criteria(only_all_tested, allow_class = "logical", has_length = 1, .call_depth = 1) meet_criteria(only_count, allow_class = "logical", has_length = 1, .call_depth = 1) @@ -191,7 +191,7 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both" meet_criteria(data, allow_class = "data.frame", contains_column_class = "rsi", .call_depth = 1) meet_criteria(translate_ab, allow_class = c("character", "logical"), has_length = 1, allow_NA = TRUE, .call_depth = 1) meet_criteria(language, has_length = 1, is_in = c(LANGUAGES_SUPPORTED, ""), allow_NULL = TRUE, allow_NA = TRUE, .call_depth = 1) - meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, .call_depth = 1) + meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, .call_depth = 1) meet_criteria(as_percent, allow_class = "logical", has_length = 1, .call_depth = 1) meet_criteria(combine_SI, allow_class = "logical", has_length = 1, .call_depth = 1) meet_criteria(combine_SI_missing, allow_class = "logical", has_length = 1, .call_depth = 1) diff --git a/data-raw/AMR_1.5.0.9009.tar.gz b/data-raw/AMR_1.5.0.9010.tar.gz similarity index 85% rename from data-raw/AMR_1.5.0.9009.tar.gz rename to data-raw/AMR_1.5.0.9010.tar.gz index 0fc93b8c..7ac8d896 100644 Binary files a/data-raw/AMR_1.5.0.9009.tar.gz and b/data-raw/AMR_1.5.0.9010.tar.gz differ diff --git a/docs/404.html b/docs/404.html index 448c8675..1bef8ad1 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index bd4bd35e..8aa018b1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010 diff --git a/docs/articles/MDR.html b/docs/articles/MDR.html index ac82c95a..7591faed 100644 --- a/docs/articles/MDR.html +++ b/docs/articles/MDR.html @@ -39,7 +39,7 @@ AMR (for R) - 1.5.0 + 1.5.0.9010 @@ -201,15 +201,15 @@

With the function mdro(), you can determine which micro-organisms are multi-drug resistant organisms (MDRO).

-
-

-Type of input

+
+

+Type of input

The mdro() function takes a data set as input, such as a regular data.frame. It tries to automatically determine the right columns for info about your isolates, like the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command ?mdro.

For WHONET data (and most other data), all settings are automatically set correctly.

-
-

-Guidelines

+
+

+Guidelines

The function support multiple guidelines. You can select a guideline with the guideline parameter. Currently supported guidelines are (case-insensitive):

  • @@ -238,16 +238,44 @@

Please suggest your own (country-specific) guidelines by letting us know: https://github.com/msberends/AMR/issues/new.

-
-
+

-Examples

+Custom Guidelines +

You can also use your own custom guideline. Custom guidelines can be set with the custom_mdro_guideline() function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.

+

If you are familiar with case_when() of the dplyr package, you will recognise the input method to set your own rules. Rules must be set using what considers to be the ‘formula notation’:

+
+custom <- custom_mdro_guideline(CIP == "R" & age > 60 ~ "Elderly Type A",
+                                ERY == "R" & age > 60 ~ "Elderly Type B")
+

If a row/an isolate matches the first rule, the value after the first ~ (in this case ‘Elderly Type A’) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited.

+

You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.

+
+custom
+# A set of custom MDRO rules:
+#   1. CIP is "R" and age is higher than 60 -> Elderly Type A
+#   2. ERY is "R" and age is higher than 60 -> Elderly Type B
+#   3. Otherwise -> Negative
+# 
+# Unmatched rows will return NA.
+# Results will be of class <factor>, with ordered levels: Negative < Elderly Type A < Elderly Type B
+

The outcome of the function can be used for the guideline argument in the [mdro()] function:

+
+x <- mdro(example_isolates, guideline = custom)
+table(x)
+# x
+#       Negative Elderly Type A Elderly Type B 
+#           1066             43            891
+

The rules set (the custom object in this case) could be exported to a shared file location using saveRDS() if you collaborate with multiple users. The custom rules set could then be imported using readRDS().

+
+
+
+

+Examples

The mdro() function always returns an ordered factor. For example, the output of the default guideline by Magiorakos et al. returns a factor with levels ‘Negative’, ‘MDR’, ‘XDR’ or ‘PDR’ in that order.

The next example uses the example_isolates data set. This is a data set included with this package and contains 2,000 microbial isolates with their full antibiograms. It reflects reality and can be used to practice AMR analysis. If we test the MDR/XDR/PDR guideline on this data set, we get:

-
+
 library(dplyr)   # to support pipes: %>%
 library(cleaner) # to create frequency tables
-
+
 example_isolates %>% 
   mdro() %>% 
   freq() # show frequency table of the result
@@ -272,23 +300,23 @@ Unique: 2

1 Negative -1616 -92.50% -1616 -92.50% +1617 +92.56% +1617 +92.56% 2 Multi-drug-resistant (MDR) -131 -7.50% +130 +7.44% 1747 100.00%

For another example, I will create a data set to determine multi-drug resistant TB:

-
+
 # random_rsi() is a helper function to generate
 # a random vector with values S, I and R
 my_TB_data <- data.frame(rifampicin = random_rsi(5000),
@@ -299,7 +327,7 @@ Unique: 2

moxifloxacin = random_rsi(5000), kanamycin = random_rsi(5000))

Because all column names are automatically verified for valid drug names or codes, this would have worked exactly the same:

-
+
 my_TB_data <- data.frame(RIF = random_rsi(5000),
                          INH = random_rsi(5000),
                          GAT = random_rsi(5000),
@@ -308,32 +336,32 @@ Unique: 2

MFX = random_rsi(5000), KAN = random_rsi(5000))

The data set now looks like this:

-
+
 head(my_TB_data)
 #   rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1          S         R            S          S            I            R
-# 2          R         I            S          I            S            I
-# 3          I         I            R          S            I            S
-# 4          R         S            R          I            R            S
-# 5          I         R            I          I            I            R
-# 6          I         R            I          R            S            R
+# 1          I         R            I          R            I            I
+# 2          R         R            I          S            R            I
+# 3          I         S            S          I            S            I
+# 4          I         I            R          S            R            I
+# 5          I         R            I          S            S            I
+# 6          S         I            I          I            R            R
 #   kanamycin
-# 1         R
-# 2         I
-# 3         I
-# 4         I
+# 1         I
+# 2         R
+# 3         S
+# 4         R
 # 5         S
-# 6         S
+# 6 I

We can now add the interpretation of MDR-TB to our data set. You can use:

-
+
 mdro(my_TB_data, guideline = "TB")

or its shortcut mdr_tb():

-
+
 my_TB_data$mdr <- mdr_tb(my_TB_data)
-# NOTE: No column found as input for `col_mo`, assuming all records contain
-#       Mycobacterium tuberculosis.
+# NOTE: No column found as input for `col_mo`, assuming all records +# containMycobacterium tuberculosis.

Create a frequency table of the results:

-
+
 freq(my_TB_data$mdr)

Frequency table

Class: factor > ordered (numeric)
@@ -354,40 +382,40 @@ Unique: 5

1 Mono-resistant -3286 -65.72% -3286 -65.72% +3228 +64.56% +3228 +64.56% 2 Negative -992 -19.84% -4278 -85.56% +1017 +20.34% +4245 +84.90% 3 Multi-drug-resistant -424 -8.48% -4702 -94.04% +421 +8.42% +4666 +93.32% 4 Poly-resistant -214 -4.28% -4916 -98.32% +231 +4.62% +4897 +97.94% 5 Extensively drug-resistant -84 -1.68% +103 +2.06% 5000 100.00% diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html index c452efdd..f9183cac 100644 --- a/docs/articles/SPSS.html +++ b/docs/articles/SPSS.html @@ -39,7 +39,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010
@@ -193,7 +193,7 @@

How to import data from SPSS / SAS / Stata

Matthijs S. Berends

-

22 January 2021

+

24 January 2021

Source: vignettes/SPSS.Rmd @@ -228,7 +228,7 @@
  • R has a huge community.

    -

    Many R users just ask questions on websites like StackOverflow.com, the largest online community for programmers. At the time of writing, 383,346 R-related questions have already been asked on this platform (that covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.

    +

    Many R users just ask questions on websites like StackOverflow.com, the largest online community for programmers. At the time of writing, 384,445 R-related questions have already been asked on this platform (that covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.

  • R understands any data type, including SPSS/SAS/Stata.

    diff --git a/docs/articles/index.html b/docs/articles/index.html index 4c0fd66b..78f77492 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010
  • diff --git a/docs/authors.html b/docs/authors.html index ac9000cc..53287bd7 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010
    diff --git a/docs/index.html b/docs/index.html index 118fea25..e0757438 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010
    diff --git a/docs/news/index.html b/docs/news/index.html index d396b2d4..a81565ee 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9009 + 1.5.0.9010
    @@ -236,13 +236,13 @@ Source: NEWS.md
    -
    -

    -AMR 1.5.0.9009 Unreleased +
    +

    +AMR 1.5.0.9010 Unreleased

    -
    +

    -Last updated: 22 January 2021 +Last updated: 24 January 2021

    @@ -288,6 +288,7 @@
  • Fix for verbose output of mdro(..., verbose = TRUE) for German guideline (3MGRN and 4MGRN) and Dutch guideline (BRMO, only P. aeruginosa)
  • is.rsi.eligible() now returns FALSE immediately if the input does not contain any of the values “R”, “S” or “I”. This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns.
  • +
  • Functions get_episode() and is_new_episode() now support less than a day as value for argument episode_days (e.g., to include one patient/test per hour)
  • @@ -614,7 +615,7 @@

    Making this package independent of especially the tidyverse (e.g. packages dplyr and tidyr) tremendously increases sustainability on the long term, since tidyverse functions change quite often. Good for users, but hard for package maintainers. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. Another upside it that this package can now be used with all versions of R since R-3.0.0 (April 2013). Our package is being used in settings where the resources are very limited. Fewer dependencies on newer software is helpful for such settings.

    Negative effects of this change are:

      -
    • Function freq() that was borrowed from the cleaner package was removed. Use cleaner::freq(), or run library("cleaner") before you use freq().
    • +
    • Function freq() that was borrowed from the cleaner package was removed. Use cleaner::freq(), or run library("cleaner") before you use freq().
    • Printing values of class mo or rsi in a tibble will no longer be in colour and printing rsi in a tibble will show the class <ord>, not <rsi> anymore. This is purely a visual effect.
    • All functions from the mo_* family (like mo_name() and mo_gramstain()) are noticeably slower when running on hundreds of thousands of rows.
    • For developers: classes mo and ab now both also inherit class character, to support any data transformation. This change invalidates code that checks for class length == 1.
    • @@ -951,7 +952,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ #> invalid microorganism code, NA generated

    This is important, because a value like "testvalue" could never be understood by e.g. mo_name(), although the class would suggest a valid microbial code.

    -
  • Function freq() has moved to a new package, clean (CRAN link), since creating frequency tables actually does not fit the scope of this package. The freq() function still works, since it is re-exported from the clean package (which will be installed automatically upon updating this AMR package).

  • +
  • Function freq() has moved to a new package, clean (CRAN link), since creating frequency tables actually does not fit the scope of this package. The freq() function still works, since it is re-exported from the clean package (which will be installed automatically upon updating this AMR package).

  • Renamed data set septic_patients to example_isolates

  • @@ -1220,7 +1221,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
  • The age() function gained a new argument exact to determine ages with decimals
  • Removed deprecated functions guess_mo(), guess_atc(), EUCAST_rules(), interpretive_reading(), rsi()
  • -
  • Frequency tables (freq()): +
  • Frequency tables (freq()):
    • speed improvement for microbial IDs

    • fixed factor level names for R Markdown

    • @@ -1230,12 +1231,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
       
       septic_patients %>% 
      -  freq(age) %>% 
      +  freq(age) %>% 
         boxplot()
       # grouped boxplots:
       septic_patients %>% 
         group_by(hospital_id) %>% 
      -  freq(age) %>%
      +  freq(age) %>%
         boxplot()
    @@ -1245,7 +1246,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
  • Added ceftazidim intrinsic resistance to Streptococci
  • Changed default settings for age_groups(), to let groups of fives and tens end with 100+ instead of 120+
  • -
  • Fix for freq() for when all values are NA +
  • Fix for freq() for when all values are NA
  • Fix for first_isolate() for when dates are missing
  • Improved speed of guess_ab_col() @@ -1486,7 +1487,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
  • -
  • Frequency tables (freq() function): +
  • Frequency tables (freq() function):
    • Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:

      @@ -1496,15 +1497,15 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ # OLD WAY septic_patients %>% mutate(genus = mo_genus(mo)) %>% - freq(genus) + freq(genus) # NEW WAY septic_patients %>% - freq(mo_genus(mo)) + freq(mo_genus(mo)) # Even supports grouping variables: septic_patients %>% group_by(gender) %>% - freq(mo_genus(mo))
  • + freq(mo_genus(mo))
  • Header info is now available as a list, with the header function

  • The argument header is now set to TRUE at default, even for markdown

  • @@ -1587,7 +1588,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
  • Using portion_* functions now throws a warning when total available isolate is below argument minimum

  • Functions as.mo, as.rsi, as.mic, as.atc and freq will not set package name as attribute anymore

  • -

    Frequency tables - freq():

    +

    Frequency tables - freq():

    • Support for grouping variables, test with:

      @@ -1595,14 +1596,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ septic_patients %>% group_by(hospital_id) %>% - freq(gender) + freq(gender)
    • Support for (un)selecting columns:

       
       septic_patients %>% 
      -  freq(hospital_id) %>% 
      +  freq(hospital_id) %>% 
         select(-count, -cum_count) # only get item, percent, cum_percent
    • Check for hms::is.hms

    • @@ -1620,7 +1621,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
    • Removed diacritics from all authors (columns microorganisms$ref and microorganisms.old$ref) to comply with CRAN policy to only allow ASCII characters

    • Fix for mo_property not working properly

    • Fix for eucast_rules where some Streptococci would become ceftazidime R in EUCAST rule 4.5

    • -
    • Support for named vectors of class mo, useful for top_freq()

    • +
    • Support for named vectors of class mo, useful for top_freq()

    • ggplot_rsi and scale_y_percent have breaks argument

    • AI improvements for as.mo:

      @@ -1788,13 +1789,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
       
       my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
      -freq(my_matrix)
      +freq(my_matrix)

      For lists, subsetting is possible:

       
       my_list = list(age = septic_patients$age, gender = septic_patients$gender)
      -my_list %>% freq(age)
      -my_list %>% freq(gender)
      +my_list %>% freq(age) +my_list %>% freq(gender)
    @@ -1868,13 +1869,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
    • A vignette to explain its usage
    • Support for rsi (antimicrobial resistance) to use as input
    • -
    • Support for table to use as input: freq(table(x, y)) +
    • Support for table to use as input: freq(table(x, y))
    • Support for existing functions hist and plot to use a frequency table as input: hist(freq(df$age))
    • Support for as.vector, as.data.frame, as_tibble and format
    • -
    • Support for quasiquotation: freq(mydata, mycolumn) is the same as mydata %>% freq(mycolumn) +
    • Support for quasiquotation: freq(mydata, mycolumn) is the same as mydata %>% freq(mycolumn)
    • Function top_freq function to return the top/below n items as vector
    • Header of frequency tables now also show Mean Absolute Deviaton (MAD) and Interquartile Range (IQR)
    • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c14e4ac5..43ba565a 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-01-22T09:54Z +last_built: 2021-01-24T13:47Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index 954b9a29..c1faa64d 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9008 + 1.5.0.9010 @@ -306,7 +306,7 @@ The lifecycle of this function is stable

      filter_ab_class() for the filter() equivalent.

      Examples

      -
      # `example_isolates` is a dataset available in the AMR package.
      +    
      # `example_isolates` is a data set available in the AMR package.
       # See ?example_isolates.
       
       # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
      diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html
      index 9a87940a..e067e2f7 100644
      --- a/docs/reference/as.rsi.html
      +++ b/docs/reference/as.rsi.html
      @@ -82,7 +82,7 @@
             
             
               AMR (for R)
      -        1.5.0.9008
      +        1.5.0.9010
             
           
       
      @@ -282,7 +282,7 @@
         uti = NULL,
         conserve_capped_values = FALSE,
         add_intrinsic_resistance = FALSE,
      -  reference_data = rsi_translation
      +  reference_data = AMR::rsi_translation
       )

      Arguments

      @@ -302,7 +302,7 @@ mo -

      any (vector of) text that can be coerced to a valid microorganism code with as.mo(), will be determined automatically if the dplyr package is installed

      +

      any (vector of) text that can be coerced to a valid microorganism code with as.mo(), can be left empty to determine it automatically

      ab diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index 146f35b8..e00485b3 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9008 + 1.5.0.9010 @@ -366,7 +366,7 @@

      A logical vector

      Details

      -

      These functions are context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, see Examples.

      +

      These functions are context-aware. This means that then the x argument can be left blank, see Examples.

      The first_isolate() function is a wrapper around the is_new_episode() function, but more efficient for data sets containing microorganism codes or names.

      All isolates with a microbial ID of NA will be excluded as first isolate.

      Why this is so Important

      @@ -419,7 +419,7 @@ The lifecycle of this function is stable

      key_antibiotics()

      Examples

      -
      # `example_isolates` is a dataset available in the AMR package.
      +    
      # `example_isolates` is a data set available in the AMR package.
       # See ?example_isolates.
       
       # basic filtering on first isolates
      diff --git a/docs/reference/get_episode.html b/docs/reference/get_episode.html
      index 9093c38c..f8ef181a 100644
      --- a/docs/reference/get_episode.html
      +++ b/docs/reference/get_episode.html
      @@ -82,7 +82,7 @@
             
             
               AMR (for R)
      -        1.5.0.9008
      +        1.5.0.9010
             
           
       
      @@ -255,11 +255,11 @@
           
           
             episode_days
      -      

      length of the required episode in days, see Details

      +

      length of the required episode length in days, can also be less than a day, see Details

      ... -

      arguments passed on to as.Date()

      +

      arguments passed on to as.POSIXct()

      @@ -293,15 +293,20 @@ The lifecycle of this function is stable

      first_isolate()

      Examples

      -
      # `example_isolates` is a dataset available in the AMR package.
      +    
      # `example_isolates` is a data set available in the AMR package.
       # See ?example_isolates.
       
      -get_episode(example_isolates$date, episode_days = 60)
      -is_new_episode(example_isolates$date, episode_days = 60)
      +get_episode(example_isolates$date, episode_days = 60)    # indices
      +is_new_episode(example_isolates$date, episode_days = 60) # TRUE/FALSE
       
       # filter on results from the third 60-day episode only, using base R
       example_isolates[which(get_episode(example_isolates$date, 60) == 3), ]
       
      +# the functions also work for less than a day, e.g. to include one per hour:
      +get_episode(c(Sys.time(),
      +              Sys.time() + 60 * 60),
      +            episode_days = 1/24)
      +
       # \donttest{
       if (require("dplyr")) {
         # is_new_episode() can also be used in dplyr verbs to determine patient
      diff --git a/docs/reference/ggplot_pca.html b/docs/reference/ggplot_pca.html
      index 03ad375d..7fc7d321 100644
      --- a/docs/reference/ggplot_pca.html
      +++ b/docs/reference/ggplot_pca.html
      @@ -82,7 +82,7 @@
             
             
               AMR (for R)
      -        1.5.0.9008
      +        1.5.0.9010
             
           
       
      @@ -392,7 +392,7 @@
       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').

      Examples

      -
      # `example_isolates` is a dataset available in the AMR package.
      +    
      # `example_isolates` is a data set available in the AMR package.
       # See ?example_isolates.
       
       # See ?pca for more info about Principal Component Analysis (PCA).
      diff --git a/docs/reference/index.html b/docs/reference/index.html
      index 44091b32..fdd67b44 100644
      --- a/docs/reference/index.html
      +++ b/docs/reference/index.html
      @@ -81,7 +81,7 @@
             
             
               AMR (for R)
      -        1.5.0.9009
      +        1.5.0.9010
             
           
       
      diff --git a/docs/reference/isolate_identifier.html b/docs/reference/isolate_identifier.html
      index c2894867..607a6f31 100644
      --- a/docs/reference/isolate_identifier.html
      +++ b/docs/reference/isolate_identifier.html
      @@ -82,7 +82,7 @@
             
             
               AMR (for R)
      -        1.5.0.9009
      +        1.5.0.9010
             
           
       
      diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html
      index 21e512d5..a0e2eb5a 100644
      --- a/docs/reference/key_antibiotics.html
      +++ b/docs/reference/key_antibiotics.html
      @@ -82,7 +82,7 @@
             
             
               AMR (for R)
      -        1.5.0.9008
      +        1.5.0.9010
             
           
       
      @@ -281,7 +281,7 @@
           
           
             x
      -      

      a data.frame with antibiotics columns, like AMX or amox. Can be left blank when used inside dplyr verbs, such as filter(), mutate() and summarise().

      +

      a data.frame with antibiotics columns, like AMX or amox. Can be left blank to determine automatically

      col_mo @@ -331,7 +331,7 @@

      Details

      -

      The key_antibiotics() function is context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, see Examples.

      +

      The key_antibiotics() function is context-aware. This means that then the x argument can be left blank, see Examples.

      The function key_antibiotics() returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using key_antibiotics_equal(), to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (".") by key_antibiotics() and ignored by key_antibiotics_equal().

      The first_isolate() function only uses this function on the same microbial species from the same patient. Using this, e.g. an MRSA will be included after a susceptible S. aureus (MSSA) is found within the same patient episode. Without key antibiotic comparison it would not. See first_isolate() for more info.

      At default, the antibiotics that are used for Gram-positive bacteria are:

        @@ -393,7 +393,7 @@ The lifecycle of this function is stable

        first_isolate()

        Examples

        -
        # `example_isolates` is a dataset available in the AMR package.
        +    
        # `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # output of the `key_antibiotics()` function could be like this:
        diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html
        index daccc21f..b964d0dc 100644
        --- a/docs/reference/mdro.html
        +++ b/docs/reference/mdro.html
        @@ -82,7 +82,7 @@
               
               
                 AMR (for R)
        -        1.5.0.9008
        +        1.5.0.9010
               
             
         
        @@ -325,7 +325,7 @@ Ordered factor with levels Details
         
        -    

        These functions are context-aware when used inside dplyr verbs, such as filter(), mutate() and summarise(). This means that then the x argument can be left blank, see Examples.

        +

        These functions are context-aware. This means that then the x argument can be left blank, see Examples.

        For the pct_required_classes argument, values above 1 will be divided by 100. This is to support both fractions (0.75 or 3/4) and percentages (75).

        Note: Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named order Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu et al. in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this mdro() function makes sure that results from before 2016 and after 2016 are identical.

        Supported International / National Guidelines

        @@ -375,7 +375,7 @@ Ordered factor with levels #> 43 891 1066
        -

        The rules set (the custom object in this case) could be exported to a shared file location using saveRDS() if you collaborate with multiple users. The custom rules set could then be imported using readRDS(),

        +

        The rules set (the custom object in this case) could be exported to a shared file location using saveRDS() if you collaborate with multiple users. The custom rules set could then be imported using readRDS().

        Stable Lifecycle

        diff --git a/docs/reference/pca.html b/docs/reference/pca.html index 2379e238..e34d0367 100644 --- a/docs/reference/pca.html +++ b/docs/reference/pca.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9008 + 1.5.0.9010 @@ -324,7 +324,7 @@ The lifecycle of this function is maturing<

        On our website https://msberends.github.io/AMR/ you can find a comprehensive tutorial about how to conduct AMR analysis, the complete documentation of all functions and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey!

        Examples

        -
        # `example_isolates` is a dataset available in the AMR package.
        +    
        # `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # \donttest{
        diff --git a/docs/survey.html b/docs/survey.html
        index bd92ece4..24672f93 100644
        --- a/docs/survey.html
        +++ b/docs/survey.html
        @@ -81,7 +81,7 @@
               
               
                 AMR (for R)
        -        1.5.0.9009
        +        1.5.0.9010
               
             
         
        diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd
        index b34778a1..764fc081 100644
        --- a/man/antibiotic_class_selectors.Rd
        +++ b/man/antibiotic_class_selectors.Rd
        @@ -76,7 +76,7 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
        diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd
        index 61c247c4..763b1f7e 100755
        --- a/man/as.rsi.Rd
        +++ b/man/as.rsi.Rd
        @@ -47,7 +47,7 @@ is.rsi.eligible(x, threshold = 0.05)
           uti = NULL,
           conserve_capped_values = FALSE,
           add_intrinsic_resistance = FALSE,
        -  reference_data = rsi_translation
        +  reference_data = AMR::rsi_translation
         )
         }
         \arguments{
        @@ -57,7 +57,7 @@ is.rsi.eligible(x, threshold = 0.05)
         
         \item{threshold}{maximum fraction of invalid antimicrobial interpretations of \code{x}, see \emph{Examples}}
         
        -\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}, will be determined automatically if the \code{dplyr} package is installed}
        +\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}, can be left empty to determine it automatically}
         
         \item{ab}{any (vector of) text that can be coerced to a valid antimicrobial code with \code{\link[=as.ab]{as.ab()}}}
         
        diff --git a/man/first_isolate.Rd b/man/first_isolate.Rd
        index 48dbe7d3..9624d743 100755
        --- a/man/first_isolate.Rd
        +++ b/man/first_isolate.Rd
        @@ -93,7 +93,7 @@ A \code{\link{logical}} vector
         Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use \code{\link[=is_new_episode]{is_new_episode()}} that also supports grouping with the \code{dplyr} package.
         }
         \details{
        -These functions are context-aware when used inside \code{dplyr} verbs, such as \code{filter()}, \code{mutate()} and \code{summarise()}. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
        +These functions are context-aware. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
         
         The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around the \code{\link[=is_new_episode]{is_new_episode()}} function, but more efficient for data sets containing microorganism codes or names.
         
        @@ -148,7 +148,7 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # basic filtering on first isolates
        diff --git a/man/get_episode.Rd b/man/get_episode.Rd
        index 43ee3fa3..40397f96 100644
        --- a/man/get_episode.Rd
        +++ b/man/get_episode.Rd
        @@ -12,9 +12,9 @@ is_new_episode(x, episode_days, ...)
         \arguments{
         \item{x}{vector of dates (class \code{Date} or \code{POSIXt})}
         
        -\item{episode_days}{length of the required episode in days, see \emph{Details}}
        +\item{episode_days}{length of the required episode length in days, can also be less than a day, see \emph{Details}}
         
        -\item{...}{arguments passed on to \code{\link[=as.Date]{as.Date()}}}
        +\item{...}{arguments passed on to \code{\link[=as.POSIXct]{as.POSIXct()}}}
         }
         \value{
         \itemize{
        @@ -46,15 +46,20 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
        -get_episode(example_isolates$date, episode_days = 60)
        -is_new_episode(example_isolates$date, episode_days = 60)
        +get_episode(example_isolates$date, episode_days = 60)    # indices
        +is_new_episode(example_isolates$date, episode_days = 60) # TRUE/FALSE
         
         # filter on results from the third 60-day episode only, using base R
         example_isolates[which(get_episode(example_isolates$date, 60) == 3), ]
         
        +# the functions also work for less than a day, e.g. to include one per hour:
        +get_episode(c(Sys.time(),
        +              Sys.time() + 60 * 60),
        +            episode_days = 1/24)
        +
         \donttest{
         if (require("dplyr")) {
           # is_new_episode() can also be used in dplyr verbs to determine patient
        diff --git a/man/ggplot_pca.Rd b/man/ggplot_pca.Rd
        index e918c4f8..55ed68b9 100644
        --- a/man/ggplot_pca.Rd
        +++ b/man/ggplot_pca.Rd
        @@ -115,7 +115,7 @@ The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unly
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # See ?pca for more info about Principal Component Analysis (PCA).
        diff --git a/man/key_antibiotics.Rd b/man/key_antibiotics.Rd
        index 0ea4348b..d8d2a49c 100755
        --- a/man/key_antibiotics.Rd
        +++ b/man/key_antibiotics.Rd
        @@ -40,7 +40,7 @@ key_antibiotics_equal(
         )
         }
         \arguments{
        -\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank when used inside \code{dplyr} verbs, such as \code{filter()}, \code{mutate()} and \code{summarise()}.}
        +\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically}
         
         \item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
         
        @@ -68,7 +68,7 @@ key_antibiotics_equal(
         These function can be used to determine first isolates (see \code{\link[=first_isolate]{first_isolate()}}). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates can then be called first 'weighted' isolates.
         }
         \details{
        -The \code{\link[=key_antibiotics]{key_antibiotics()}} function is context-aware when used inside \code{dplyr} verbs, such as \code{filter()}, \code{mutate()} and \code{summarise()}. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
        +The \code{\link[=key_antibiotics]{key_antibiotics()}} function is context-aware. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
         
         The function \code{\link[=key_antibiotics]{key_antibiotics()}} returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using \code{\link[=key_antibiotics_equal]{key_antibiotics_equal()}}, to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (\code{"."}) by \code{\link[=key_antibiotics]{key_antibiotics()}} and ignored by \code{\link[=key_antibiotics_equal]{key_antibiotics_equal()}}.
         
        @@ -135,7 +135,7 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         # output of the `key_antibiotics()` function could be like this:
        diff --git a/man/mdro.Rd b/man/mdro.Rd
        index 97b1f01e..dc60161c 100644
        --- a/man/mdro.Rd
        +++ b/man/mdro.Rd
        @@ -77,7 +77,7 @@ Ordered \link{factor} with levels \code{Negative} < \verb{Positive, unconfirmed}
         Determine which isolates are multidrug-resistant organisms (MDRO) according to international, national and custom guidelines.
         }
         \details{
        -These functions are context-aware when used inside \code{dplyr} verbs, such as \code{filter()}, \code{mutate()} and \code{summarise()}. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
        +These functions are context-aware. This means that then the \code{x} argument can be left blank, see \emph{Examples}.
         
         For the \code{pct_required_classes} argument, values above 1 will be divided by 100. This is to support both fractions (\code{0.75} or \code{3/4}) and percentages (\code{75}).
         
        @@ -137,7 +137,7 @@ table(x)
         #>             43            891           1066 
         }
         
        -The rules set (the \code{custom} object in this case) could be exported to a shared file location using \code{\link[=saveRDS]{saveRDS()}} if you collaborate with multiple users. The custom rules set could then be imported using \code{\link[=readRDS]{readRDS()}},
        +The rules set (the \code{custom} object in this case) could be exported to a shared file location using \code{\link[=saveRDS]{saveRDS()}} if you collaborate with multiple users. The custom rules set could then be imported using \code{\link[=readRDS]{readRDS()}}.
         }
         
         \section{Stable Lifecycle}{
        diff --git a/man/pca.Rd b/man/pca.Rd
        index c24f142e..92cf51a6 100644
        --- a/man/pca.Rd
        +++ b/man/pca.Rd
        @@ -71,7 +71,7 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
         }
         
         \examples{
        -# `example_isolates` is a dataset available in the AMR package.
        +# `example_isolates` is a data set available in the AMR package.
         # See ?example_isolates.
         
         \donttest{
        diff --git a/vignettes/MDR.Rmd b/vignettes/MDR.Rmd
        index 17c877d3..a811741b 100644
        --- a/vignettes/MDR.Rmd
        +++ b/vignettes/MDR.Rmd
        @@ -21,13 +21,13 @@ library(AMR)
         
         With the function `mdro()`, you can determine which micro-organisms are multi-drug resistant organisms (MDRO).
         
        -#### Type of input
        +### Type of input
         
        -The  `mdro()` function takes a data set as input, such as a regular `data.frame`. It tries to automatically determine the right columns for info about your isolates, like the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command `?mdro`. 
        +The `mdro()` function takes a data set as input, such as a regular `data.frame`. It tries to automatically determine the right columns for info about your isolates, like the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command `?mdro`. 
         
         For WHONET data (and most other data), all settings are automatically set correctly.
         
        -#### Guidelines
        +### Guidelines
         
         The function support multiple guidelines. You can select a guideline with the `guideline` parameter. Currently supported guidelines are (case-insensitive):
         
        @@ -56,8 +56,36 @@ The function support multiple guidelines. You can select a guideline with the `g
           The Dutch national guideline - Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) (ZKH)" ([link](https://www.rivm.nl/wip-richtlijn-brmo-bijzonder-resistente-micro-organismen-zkh))
         
         Please suggest your own (country-specific) guidelines by letting us know: .
        +
        +#### Custom Guidelines
        +
        +You can also use your own custom guideline. Custom guidelines can be set with the `custom_mdro_guideline()` function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.
        +
        +If you are familiar with `case_when()` of the `dplyr` package, you will recognise the input method to set your own rules. Rules must be set using what \R considers to be the 'formula notation':
        +
        +```{r}
        +custom <- custom_mdro_guideline(CIP == "R" & age > 60 ~ "Elderly Type A",
        +                                ERY == "R" & age > 60 ~ "Elderly Type B")
        +```
        +
        +If a row/an isolate matches the first rule, the value after the first `~` (in this case *'Elderly Type A'*) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited. 
        +
        +You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.
        +
        +```{r}
        +custom
        +```
        +
        +The outcome of the function can be used for the `guideline` argument in the [mdro()] function:
        +
        +```{r}
        +x <- mdro(example_isolates, guideline = custom)
        +table(x)
        +```
        +
        +The rules set (the `custom` object in this case) could be exported to a shared file location using `saveRDS()` if you collaborate with multiple users. The custom rules set could then be imported using `readRDS()`.
           
        -#### Examples
        +### Examples
         
         The `mdro()` function always returns an ordered `factor`. For example, the output of the default guideline by Magiorakos *et al.* returns a `factor` with levels 'Negative', 'MDR', 'XDR' or 'PDR' in that order.