Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to vectors before calling case_when() #234

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions R/mapping-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ by_regex <- function(..., .grepl_args = list(), ignore_na = TRUE) {
#'
#' `by_colorspace()` can be used to set background, border or
#' text colors, visually differentiating high or low values.
#'
#'
#' @param ... Colors
#' @param range Numeric endpoints. If `NULL`, these are determined from the data.
#' @param na_color Color to return for `NA` values. Can be `NA` itself.
Expand Down Expand Up @@ -579,9 +579,13 @@ by_cases <- function (..., ignore_na = TRUE) {
case_fn <- function (ht, rows, cols, current) {
res <- current
myenv <- new.env()
assign(".", as.matrix(ht[rows, cols]), envir = myenv)
selection <- as.matrix(ht[rows, cols])
dim <- dim(selection)
selection <- as.vector(selection)
assign(".", selection, envir = myenv)
cases <- lapply(cases, stats::as.formula, env = myenv)
vals <- dplyr::case_when(!!! cases)
vals <- array(vals, dim = dim)
res[] <- vals
res <- maybe_ignore_na(res, current, ignore_na)
res
Expand Down