#' Filter for Totals Rows
#'
#' @description Filter a data frame for rows with the "TOTAL" value
#'
#' @param data A data frame
#' @param dims Character vector of columns to filter for totals in
#' @param tv Character, totals value. See ?totals_value
#'
#' @return Data frame
#'
#' @export
filter_for_totals <- function(data, dims, tv = totals_value()) {
dplyr::filter(
data,
dplyr::if_any(dplyr::any_of(dims), ~ . == tv)
)
}
#' Filter for Non-Totals Rows
#'
#' @description Filter a data frame to remove rows with the "TOTAL" value
#'
#' @param data A data frame
#' @param dims Character vector of columns to remove totals rows from
#' @param tv Character, totals value. See ?totals_value
#'
#' @return Data frame
#'
#' @export
filter_remove_totals <- function(data, dims, tv = totals_value()) {
dplyr::filter(
data,
dplyr::if_all(dplyr::any_of(dims), ~ . != tv)
)
}
#' Value to Use as Indicator of a Rollup
#'
#' @param dq Logical, whether or not to wrap in single quotes as well as double
#' quotes
#'
#' @return Character
#'
#' @export
totals_value <- function(dq = FALSE) {
ifelse(dq, "'TOTAL'", "TOTAL")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.