Skip to content

Commit

Permalink
Splice dots in case_when()
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Mar 31, 2017
1 parent 8629b67 commit db35cc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion R/case_when.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' The LHS must evaluate to a logical vector. Each logical vector can
#' either have length 1 or a common length. All RHSs must evaluate to
#' the same type of vector.
#'
#' These dots are evaluated with [explicit splicing][rlang::dots_list].
#' @export
#' @return A vector as long as the longest LHS, with the type (and
#' attributes) of the first RHS. Inconsistent lengths or types will
Expand Down Expand Up @@ -44,8 +46,17 @@
#' TRUE ~ "other"
#' )
#' )
#'
#' # Dots support splicing:
#' patterns <- list(
#' TRUE ~ as.character(x),
#' x %% 5 == 0 ~ "fizz",
#' x %% 7 == 0 ~ "buzz",
#' x %% 35 == 0 ~ "fizz buzz"
#' )
#' case_when(splice(patterns))
case_when <- function(...) {
formulas <- list(...)
formulas <- dots_list(...)
n <- length(formulas)

if (n == 0) {
Expand Down
13 changes: 12 additions & 1 deletion man/case_when.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db35cc9

Please sign in to comment.