mirror of
https://github.com/msberends/AMR.git
synced 2025-07-10 22:22:19 +02:00
(v0.7.1.9059) bug_drug_combinations
This commit is contained in:
@ -21,9 +21,10 @@
|
||||
|
||||
#' Check availability of columns
|
||||
#'
|
||||
#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antibiotic combination can be used for calculation with e.g. \code{\link{portion_IR}}.
|
||||
#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{portion_R}}.
|
||||
#' @param tbl a \code{data.frame} or \code{list}
|
||||
#' @param width number of characters to present the visual availability, defaults to filling the width of the console
|
||||
#' @details The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{portion_R}}.
|
||||
#' @return \code{data.frame} with column names of \code{tbl} as row names
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
@ -44,10 +45,10 @@
|
||||
availability <- function(tbl, width = NULL) {
|
||||
x <- base::sapply(tbl, function(x) { 1 - base::sum(base::is.na(x)) / base::length(x) })
|
||||
n <- base::sapply(tbl, function(x) base::length(x[!base::is.na(x)]))
|
||||
IR <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_IR(x, minimum = 0), NA))
|
||||
IR_print <- character(length(IR))
|
||||
IR_print[!is.na(IR)] <- percent(IR[!is.na(IR)], round = 1, force_zero = TRUE)
|
||||
IR_print[is.na(IR)] <- ""
|
||||
R <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_R(x, minimum = 0), NA))
|
||||
R_print <- character(length(R))
|
||||
R_print[!is.na(R)] <- percent(R[!is.na(R)], round = 1, force_zero = TRUE)
|
||||
R_print[is.na(R)] <- ""
|
||||
|
||||
if (is.null(width)) {
|
||||
width <- options()$width -
|
||||
@ -63,14 +64,14 @@ availability <- function(tbl, width = NULL) {
|
||||
width <- width / 2
|
||||
}
|
||||
|
||||
if (length(IR[is.na(IR)]) == ncol(tbl)) {
|
||||
if (length(R[is.na(R)]) == ncol(tbl)) {
|
||||
width <- width * 2 + 10
|
||||
}
|
||||
|
||||
x_chars_IR <- strrep("#", round(width * IR, digits = 2))
|
||||
x_chars_S <- strrep("-", width - nchar(x_chars_IR))
|
||||
vis_resistance <- paste0("|", x_chars_IR, x_chars_S, "|")
|
||||
vis_resistance[is.na(IR)] <- ""
|
||||
x_chars_R <- strrep("#", round(width * R, digits = 2))
|
||||
x_chars_SI <- strrep("-", width - nchar(x_chars_R))
|
||||
vis_resistance <- paste0("|", x_chars_R, x_chars_SI, "|")
|
||||
vis_resistance[is.na(R)] <- ""
|
||||
|
||||
x_chars <- strrep("#", round(x, digits = 2) / (1 / width))
|
||||
x_chars_empty <- strrep("-", width - nchar(x_chars))
|
||||
@ -78,9 +79,9 @@ availability <- function(tbl, width = NULL) {
|
||||
df <- data.frame(count = n,
|
||||
available = percent(x, round = 1, force_zero = TRUE),
|
||||
visual_availabilty = paste0("|", x_chars, x_chars_empty, "|"),
|
||||
resistant = IR_print,
|
||||
resistant = R_print,
|
||||
visual_resistance = vis_resistance)
|
||||
if (length(IR[is.na(IR)]) == ncol(tbl)) {
|
||||
if (length(R[is.na(R)]) == ncol(tbl)) {
|
||||
df[,1:3]
|
||||
} else {
|
||||
df
|
||||
|
Reference in New Issue
Block a user