Description Usage Arguments Details Value Methods (by generic) Examples
View source: R/create_case_when.R
create_case_when
allows to create reusable dplyr::case_when()
functions.
It returns a function that can be used in place of
dplyr::case_when()
. The arguments of the returned function are
given by the vars
argument of create_case_when()
.
1 2 3 4 5 6 7 8 9 10 | create_case_when(..., vars = "x")
## S3 method for class 'case_when'
formulas(x, ...)
## S3 method for class 'case_when'
variable.names(object, ...)
## S3 method for class 'case_when'
print(x, ...)
|
... |
A sequence of two-sided formulas. The left hand side (LHS) determines which values match this case. The right hand side (RHS) provides the replacement value. 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. |
vars |
A character vector that determined the names of the arguments of the returned function. |
x, object |
A |
The returned function is of class case_when
.
A function, usable in place of dplyr::case_when()
.
formulas
: Get the formulas of a case_when
function.
variable.names
: Get the variable names of a case_when
function.
print
: Print informations about a case_when
function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | x <- 1:50
y <- 51:100
cw_fb <- create_case_when(
number %% 35 == 0 ~ "fizz buzz",
number %% 5 == 0 ~ "fizz",
number %% 7 == 0 ~ "buzz",
TRUE ~ as.character(number),
vars = "number"
)
cw_fb(number = x)
cw_fb(number = y)
# Formulas and variable names can be extracted
patterns <- formulas(cw_fb)
var_name <- variable.names(cw_fb)
# Dots support splicing
create_case_when(!!! patterns, vars = var_name)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.