in_case_list {incase} | R Documentation |
Case statements returning a list
Description
These functions are equivalent to in_case()
, switch_case()
,
grep_case()
, fn_case()
, and fn_switch_case()
but return
lists.
Usage
in_case_list(..., preserve = FALSE, default = NA)
switch_case_list(x, ..., preserve = FALSE, default = NA)
grep_case_list(x, ..., preserve = FALSE, default = NA)
fn_case_list(x, fn, ..., preserve = FALSE, default = NA)
fn_switch_case_list(x, fn, ..., preserve = FALSE, default = NA)
Arguments
... |
<
|
preserve |
If |
default |
If |
x |
A vector |
fn |
A function to apply to the left-hand side of each formula in Either a quoted or unquoted function name, an anonymous The function should take two inputs, the first being |
Details
This can be useful when returning a non-atomic value and/or when you want to create a list column inside a tibble.
Value
A list of length 1 or n, matching the length of the logical input vector.
See Also
in_case()
, switch_case()
, grep_case()
, fn_case()
, and
fn_case_fct()
on which these functions are based.
Examples
1:3 %>%
in_case_list(
. < 2 ~ mtcars,
default = letters
)