1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 08:46:11 +01:00

(v0.7.1.9010) eucast informative text in verbose mode

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-07-09 13:36:03 +02:00
parent b15d59cf03
commit b452de2fe4
11 changed files with 34 additions and 22 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 0.7.1.9009 Version: 0.7.1.9010
Date: 2019-07-09 Date: 2019-07-09
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(

View File

@ -1,4 +1,4 @@
# AMR 0.7.1.9009 # AMR 0.7.1.9010
### New ### 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: * 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()`) * 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 name of `RIF` is now Rifampicin instead of Rifampin
* The `antibiotics` data set is now sorted by name * 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 # AMR 0.7.1

View File

@ -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 x data with antibiotic columns, like e.g. \code{AMX} and \code{AMC}
#' @param info print progress #' @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 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 #' @param ... column name of an antibiotic, see section Antibiotics
#' @inheritParams first_isolate #' @inheritParams first_isolate
#' @details #' @details
@ -119,7 +119,7 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016"
#' @rdname eucast_rules #' @rdname eucast_rules
#' @export #' @export
#' @importFrom dplyr %>% select pull mutate_at vars group_by summarise n #' @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. #' @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 #' @source
#' \itemize{ #' \itemize{
@ -186,8 +186,6 @@ eucast_rules <- function(x,
verbose = FALSE, verbose = FALSE,
...) { ...) {
x <- x
if (!is.data.frame(x)) { if (!is.data.frame(x)) {
stop("`x` must be a data frame.", call. = FALSE) stop("`x` must be a data frame.", call. = FALSE)
} }
@ -498,6 +496,15 @@ eucast_rules <- function(x,
} }
y[y != "" & y %in% colnames(df)] 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 eucast_rules_df <- eucast_rules_file # internal data file
no_of_changes <- 0 no_of_changes <- 0
@ -510,10 +517,11 @@ eucast_rules <- function(x,
rule_group_current <- eucast_rules_df[i, "reference.rule_group"] 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"] rule_group_next <- eucast_rules_df[min(nrow(eucast_rules_df), i + 1), "reference.rule_group"]
if (is.na(eucast_rules_df[i, 4])) { 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 { } else {
rule_text <- paste("if", eucast_rules_df[i, 4], "=", eucast_rules_df[i, 5], rule_text <- paste0("report as '", eucast_rules_df[i, 7], "' when ",
"then", eucast_rules_df[i, 6], "=", eucast_rules_df[i, 7]) 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) { if (i == 1) {
rule_previous <- "" rule_previous <- ""
@ -736,7 +744,9 @@ eucast_rules <- function(x,
cat(paste0(silver(strrep("-", options()$width - 1)), "\n")) cat(paste0(silver(strrep("-", options()$width - 1)), "\n"))
if (verbose == FALSE & nrow(verbose_info) > 0) { 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"))
} }
} }

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>

View File

@ -42,7 +42,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>
@ -232,9 +232,9 @@
</div> </div>
<div id="amr-0719009" class="section level1"> <div id="amr-0719010" class="section level1">
<h1 class="page-header"> <h1 class="page-header">
<a href="#amr-0719009" class="anchor"></a>AMR 0.7.1.9009<small> Unreleased </small> <a href="#amr-0719010" class="anchor"></a>AMR 0.7.1.9010<small> Unreleased </small>
</h1> </h1>
<div id="new" class="section level3"> <div id="new" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -284,6 +284,7 @@
<li>Fix for frequency tables when creating one directly on a group (using <code>group_by()</code>)</li> <li>Fix for frequency tables when creating one directly on a group (using <code>group_by()</code>)</li>
<li>The name of <code>RIF</code> is now Rifampicin instead of Rifampin</li> <li>The name of <code>RIF</code> is now Rifampicin instead of Rifampin</li>
<li>The <code>antibiotics</code> data set is now sorted by name</li> <li>The <code>antibiotics</code> data set is now sorted by name</li>
<li>Using verbose mode with <code><a href="../reference/eucast_rules.html">eucast_rules(..., verbose = TRUE)</a></code> returns more informative and readable output</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -1196,7 +1197,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
<div id="tocnav"> <div id="tocnav">
<h2>Contents</h2> <h2>Contents</h2>
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="#amr-0719009">0.7.1.9009</a></li> <li><a href="#amr-0719010">0.7.1.9010</a></li>
<li><a href="#amr-071">0.7.1</a></li> <li><a href="#amr-071">0.7.1</a></li>
<li><a href="#amr-070">0.7.0</a></li> <li><a href="#amr-070">0.7.0</a></li>
<li><a href="#amr-061">0.6.1</a></li> <li><a href="#amr-061">0.6.1</a></li>

View File

@ -80,7 +80,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9005</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>
@ -265,7 +265,7 @@
</tr> </tr>
<tr> <tr>
<th>verbose</th> <th>verbose</th>
<td><p>a logical to indicate whether extensive info should be returned as a <code>data.frame</code> 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</code> with changes will be returned as output.</p></td> <td><p>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</code> with extensive info about which rows and columns would be effected and in which way.</p></td>
</tr> </tr>
<tr> <tr>
<th>...</th> <th>...</th>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9009</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9010</span>
</span> </span>
</div> </div>

View File

@ -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{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} \item{...}{column name of an antibiotic, see section Antibiotics}
} }