R/if-else.R

Defines functions if_else

#' @export
if_else <- function(condition,
                    true,
                    false,
                    ...,
                    missing = NULL,
                    ptype = NULL,
                    size = NULL) {
  check_dots_empty0(...)

  # Assert early since we `!` the `condition`
  vec_assert(
    x = condition,
    ptype = logical(),
    arg = "condition"
  )

  conditions <- list(
    condition,
    !condition
  )
  values <- list(
    true = true,
    false = false
  )

  vec_case_when(
    conditions = conditions,
    values = values,
    default = missing,
    default_arg = "missing",
    ptype = ptype,
    size = size
  )
}
DavisVaughan/extrafun documentation built on June 19, 2022, 11:14 p.m.