1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-10 12:21:53 +02:00

parameter combine_IR

This commit is contained in:
2018-10-16 09:59:31 +02:00
parent 5b5b95a47b
commit d5a41de711
10 changed files with 110 additions and 48 deletions

View File

@ -163,7 +163,8 @@ n_rsi <- function(...) {
#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything
#' @export
count_df <- function(data,
translate_ab = getOption("get_antibiotic_names", "official")) {
translate_ab = getOption("get_antibiotic_names", "official"),
combine_IR = FALSE) {
if (!"data.frame" %in% class(data)) {
stop("`count_df` must be called on a data.frame")
@ -184,23 +185,37 @@ count_df <- function(data,
mutate(Interpretation = "S") %>%
select(Interpretation, everything())
resI <- summarise_if(.tbl = data,
.predicate = is.rsi,
.funs = count_I) %>%
mutate(Interpretation = "I") %>%
select(Interpretation, everything())
if (combine_IR == FALSE) {
resI <- summarise_if(.tbl = data,
.predicate = is.rsi,
.funs = count_I) %>%
mutate(Interpretation = "I") %>%
select(Interpretation, everything())
resR <- summarise_if(.tbl = data,
.predicate = is.rsi,
.funs = count_R) %>%
mutate(Interpretation = "R") %>%
select(Interpretation, everything())
resR <- summarise_if(.tbl = data,
.predicate = is.rsi,
.funs = count_R) %>%
mutate(Interpretation = "R") %>%
select(Interpretation, everything())
data.groups <- group_vars(data)
data.groups <- group_vars(data)
res <- bind_rows(resS, resI, resR) %>%
mutate(Interpretation = factor(Interpretation, levels = c("R", "I", "S"), ordered = TRUE)) %>%
tidyr::gather(Antibiotic, Value, -Interpretation, -data.groups)
res <- bind_rows(resS, resI, resR) %>%
mutate(Interpretation = factor(Interpretation, levels = c("R", "I", "S"), ordered = TRUE)) %>%
tidyr::gather(Antibiotic, Value, -Interpretation, -data.groups)
} else {
resIR <- summarise_if(.tbl = data,
.predicate = is.rsi,
.funs = count_IR) %>%
mutate(Interpretation = "IR") %>%
select(Interpretation, everything())
data.groups <- group_vars(data)
res <- bind_rows(resS, resIR) %>%
mutate(Interpretation = factor(Interpretation, levels = c("IR", "S"), ordered = TRUE)) %>%
tidyr::gather(Antibiotic, Value, -Interpretation, -data.groups)
}
if (!translate_ab == FALSE) {
if (!tolower(translate_ab) %in% tolower(colnames(AMR::antibiotics))) {