pif: Pipe friendly conditional operation

Description Usage Arguments Details Value Examples

View source: R/05_pif.R

Description

Apply a transformation on the data only if a condition is met, by default if condition is not met the input is returned unchanged.

Usage

1
pif(x, p, true, false = identity)

Arguments

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.

Details

The use of formula or functions is recommended over the use of expressions for the following reasons :

Value

The output of true or false, either as expressions or applied on data as functions

Examples

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"))

moodymudskipper/mmpipe documentation built on May 17, 2019, 10:39 a.m.