diff --git a/DESCRIPTION b/DESCRIPTION index e58e982b..1c4e30e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.7.1.9009 +Version: 0.7.1.9010 Date: 2019-07-09 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 335b1824..a5375b27 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9009 +# AMR 0.7.1.9010 ### New * Additional way to calculate co-resistance, i.e. when using multiple antibiotics as input for `portion_*` functions or `count_*` functions. This can be used to determine the empiric susceptibily of a combination therapy. A new parameter `only_all_tested` (**which defaults to `FALSE`**) replaces the old `also_single_tested` and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the `portion` and `count` help pages), where the %SI is being determined: @@ -41,6 +41,7 @@ * Fix for frequency tables when creating one directly on a group (using `group_by()`) * The name of `RIF` is now Rifampicin instead of Rifampin * The `antibiotics` data set is now sorted by name +* Using verbose mode with `eucast_rules(..., verbose = TRUE)` returns more informative and readable output # AMR 0.7.1 diff --git a/R/eucast_rules.R b/R/eucast_rules.R index e237556a..0ba28456 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -29,7 +29,7 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016" #' @param x data with antibiotic columns, like e.g. \code{AMX} and \code{AMC} #' @param info print progress #' @param rules a character vector that specifies which rules should be applied - one or more of \code{c("breakpoints", "expert", "other", "all")} -#' @param verbose a logical to indicate whether extensive info should be returned as a \code{data.frame} with info about which rows and columns are effected. It runs all EUCAST rules, but will not be applied to an output - only an informative \code{data.frame} with changes will be returned as output. +#' @param verbose a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a \code{data.frame} with extensive info about which rows and columns would be effected and in which way. #' @param ... column name of an antibiotic, see section Antibiotics #' @inheritParams first_isolate #' @details @@ -119,7 +119,7 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016" #' @rdname eucast_rules #' @export #' @importFrom dplyr %>% select pull mutate_at vars group_by summarise n -#' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic strip_style white +#' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic strip_style white red #' @return The input of \code{x}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations. #' @source #' \itemize{ @@ -186,8 +186,6 @@ eucast_rules <- function(x, verbose = FALSE, ...) { - x <- x - if (!is.data.frame(x)) { stop("`x` must be a data frame.", call. = FALSE) } @@ -498,6 +496,15 @@ eucast_rules <- function(x, } y[y != "" & y %in% colnames(df)] } + get_antibiotic_names <- function(x) { + x %>% + strsplit(",") %>% + unlist() %>% + trimws() %>% + sapply(function(x) if(x %in% AMR::antibiotics$ab) ab_name(x, language = NULL, tolower = TRUE) else x) %>% + sort() %>% + paste(collapse = ", ") + } eucast_rules_df <- eucast_rules_file # internal data file no_of_changes <- 0 @@ -510,10 +517,11 @@ eucast_rules <- function(x, rule_group_current <- eucast_rules_df[i, "reference.rule_group"] rule_group_next <- eucast_rules_df[min(nrow(eucast_rules_df), i + 1), "reference.rule_group"] if (is.na(eucast_rules_df[i, 4])) { - rule_text <- paste("always:", eucast_rules_df[i, 6], "=", eucast_rules_df[i, 7]) + rule_text <- paste0("always report as '", eucast_rules_df[i, 7], "': ", get_antibiotic_names(eucast_rules_df[i, 6])) } else { - rule_text <- paste("if", eucast_rules_df[i, 4], "=", eucast_rules_df[i, 5], - "then", eucast_rules_df[i, 6], "=", eucast_rules_df[i, 7]) + rule_text <- paste0("report as '", eucast_rules_df[i, 7], "' when ", + get_antibiotic_names(eucast_rules_df[i, 4]), " is '", eucast_rules_df[i, 5], "': ", + get_antibiotic_names(eucast_rules_df[i, 6])) } if (i == 1) { rule_previous <- "" @@ -736,7 +744,9 @@ eucast_rules <- function(x, cat(paste0(silver(strrep("-", options()$width - 1)), "\n")) if (verbose == FALSE & nrow(verbose_info) > 0) { - cat(paste("\nUse", bold("verbose = TRUE"), "to get a data.frame with all specified edits instead.\n")) + cat(paste("\nUse", bold("verbose = TRUE"), "(on your original data) to get a data.frame with all specified edits instead.\n")) + } else if (verbose == TRUE) { + cat(paste(red("\nUsed 'Verbose mode' (verbose = TRUE)."), "This returns a data.frame with all specified edits.\nUse", bold("verbose = FALSE"), "to apply the rules on your data.\n")) } } diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index bb0f3760..ce2d5e1f 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 diff --git a/docs/articles/index.html b/docs/articles/index.html index 1f465d3e..63a90a6a 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 diff --git a/docs/authors.html b/docs/authors.html index e0bb7f50..7516492f 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 diff --git a/docs/index.html b/docs/index.html index c8d3ae02..36ab43d6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 diff --git a/docs/news/index.html b/docs/news/index.html index 84b8ef9b..0dd8aaad 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 @@ -232,9 +232,9 @@ -
+

-AMR 0.7.1.9009 Unreleased +AMR 0.7.1.9010 Unreleased

@@ -284,6 +284,7 @@
  • Fix for frequency tables when creating one directly on a group (using group_by())
  • The name of RIF is now Rifampicin instead of Rifampin
  • The antibiotics data set is now sorted by name
  • +
  • Using verbose mode with eucast_rules(..., verbose = TRUE) returns more informative and readable output
  • @@ -1196,7 +1197,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

    @@ -265,7 +265,7 @@ verbose -

    a logical to indicate whether extensive info should be returned as a data.frame with info about which rows and columns are effected. It runs all EUCAST rules, but will not be applied to an output - only an informative data.frame with changes will be returned as output.

    +

    a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data.frame with extensive info about which rows and columns would be effected and in which way.

    ... diff --git a/docs/reference/index.html b/docs/reference/index.html index 0176811b..24b8b760 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9009 + 0.7.1.9010 diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd index bf13470f..7b400c2f 100644 --- a/man/eucast_rules.Rd +++ b/man/eucast_rules.Rd @@ -33,7 +33,7 @@ eucast_rules(x, col_mo = NULL, info = TRUE, rules = c("breakpoints", \item{rules}{a character vector that specifies which rules should be applied - one or more of \code{c("breakpoints", "expert", "other", "all")}} -\item{verbose}{a logical to indicate whether extensive info should be returned as a \code{data.frame} with info about which rows and columns are effected. It runs all EUCAST rules, but will not be applied to an output - only an informative \code{data.frame} with changes will be returned as output.} +\item{verbose}{a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a \code{data.frame} with extensive info about which rows and columns would be effected and in which way.} \item{...}{column name of an antibiotic, see section Antibiotics} }