diff --git a/NAMESPACE b/NAMESPACE index fcc31c14..069de508 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -173,6 +173,7 @@ importFrom(crayon,green) importFrom(crayon,italic) importFrom(crayon,red) importFrom(crayon,silver) +importFrom(crayon,strip_style) importFrom(curl,nslookup) importFrom(data.table,as.data.table) importFrom(data.table,data.table) @@ -190,6 +191,7 @@ importFrom(dplyr,desc) importFrom(dplyr,everything) importFrom(dplyr,filter) importFrom(dplyr,filter_all) +importFrom(dplyr,filter_at) importFrom(dplyr,full_join) importFrom(dplyr,funs) importFrom(dplyr,group_by) diff --git a/R/eucast.R b/R/eucast.R index 977f55eb..bc6b9df6 100755 --- a/R/eucast.R +++ b/R/eucast.R @@ -97,7 +97,7 @@ #' @rdname EUCAST #' @export #' @importFrom dplyr %>% select pull mutate_at vars -#' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic +#' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic strip_style #' @return The input of \code{tbl}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with verbose info. #' @source #' \itemize{ @@ -376,8 +376,8 @@ EUCAST_rules <- function(tbl, if (verbose == TRUE) { for (i in 1:length(cols)) { # add new row for every affected column - verbose_new <- data.frame(rule_type = rule[1], - rule_set = rule[2], + verbose_new <- data.frame(rule_type = strip_style(rule[1]), + rule_set = strip_style(rule[2]), force_to = to, found = length(before), changed = sum(before != after, na.rm = TRUE), diff --git a/R/freq.R b/R/freq.R index ded0d3b8..5a5693d5 100755 --- a/R/freq.R +++ b/R/freq.R @@ -59,7 +59,7 @@ #' The function \code{top_freq} uses \code{\link[dplyr]{top_n}} internally and will include more than \code{n} rows if there are ties. #' @importFrom stats fivenum sd mad #' @importFrom grDevices boxplot.stats -#' @importFrom dplyr %>% arrange arrange_at desc funs group_by mutate mutate_at n_distinct pull select summarise tibble ungroup vars +#' @importFrom dplyr %>% arrange arrange_at desc filter_at funs group_by mutate mutate_at n_distinct pull select summarise tibble ungroup vars all_vars #' @importFrom utils browseVignettes #' @importFrom hms is.hms #' @importFrom crayon red green silver @@ -206,6 +206,9 @@ frequency_tbl <- function(x, df <- x %>% group_by_at(vars(x.group_cols)) %>% summarise(count = n()) + if (na.rm == TRUE) { + df <- df %>% filter_at(vars(cols), all_vars(!is.na(.))) + } if (!missing(sort.count)) { if (sort.count == TRUE) { df <- df %>% arrange_at(c(x.group, "count"), desc) diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index c8959002..2dba7dc7 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -63,6 +63,8 @@ test_that("frequency table works", { # grouping variable expect_output(print(septic_patients %>% group_by(gender) %>% freq(hospital_id))) + expect_output(print(septic_patients %>% group_by(gender) %>% freq(amox, quote = TRUE))) + expect_output(print(septic_patients %>% group_by(gender) %>% freq(amox, markdown = TRUE))) # top 5 expect_equal(