huxtable (version 4.5.0)

by_cases: Map cell contents to properties using case_when

Description

This function uses dplyr::case_when() to set cell properties.

Usage

by_cases(..., ignore_na = TRUE)

Arguments

...

A list of two-sided formulas interpreted by case_when.

ignore_na

If TRUE, NA values in the result will be left unchanged. Otherwise, NA normally resets to the default.

Value

A function for use in map_*** functions.

Details

Within the formulas, the variable . will refer to the content of ht[rows, cols] (converted by as.matrix).

case_when returns NA when no formula LHS is matched. To avoid this, set a default in the last formula: TRUE ~ default.

See Also

mapping-functions

Other mapping functions: by_colorspace, by_function, by_quantiles, by_ranges, by_regex, by_rows, by_values

Examples

Run this code
# NOT RUN {
if (! requireNamespace("dplyr")) {
  stop("Please install the 'dplyr' package to run this example")
}

ht <- hux(runif(5), letters[1:5])

map_background_color(ht, by_cases(
        . == "a" ~ "red",
        . %in% letters ~ "green",
        . < 0.5 ~ "pink"
      ))
# }

Run the code above in your browser using DataCamp Workspace