Description Usage Arguments Details Value Examples
Apply a transformation on the data only if a condition is met, by default if condition is not met the input is returned unchanged.
1 |
x |
An object |
p |
A predicate function, a formula describing such a predicate function, or an expression. |
true, false |
Functions to apply to the data, formulas describing such functions, or expressions. |
The use of formula or functions is recommended over the use of expressions for the following reasons :
If true
and/or false
are provided as expressions they
will be evaluated wether the condition is TRUE
or FALSE
.
Functions or formulas on the other hand will be applied on the data only if
the relevant condition is met
Formulas support calling directly a column of the data by its name
without x$foo
notation.
Dot notation will work in expressions only if 'pif' is used in a pipe chain
The output of true
or false
, either as expressions or applied on data as functions
1 2 3 4 5 6 7 8 9 | # using functions
iris %>% pif(is.data.frame, dim, nrow)
# using formulas
iris %>% pif(~is.numeric(Species), ~"numeric :)",~paste(class(Species)[1],":("))
# using expressions
iris %>% pif(nrow(.) > 2, head(.,2))
# careful with expressions
iris %>% pif(TRUE, dim, warning("this will be evaluated"))
iris %>% pif(TRUE, dim, ~warning("this won't be evaluated"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.