Learn R Programming

wrapr (version 2.1.0)

reduceexpand: Use function to reduce or expand arguments.

Description

x %.|% f stands for f(x[[1]], x[[2]], ..., x[[length(x)]]). v %|.% x also stands for f(x[[1]], x[[2]], ..., x[[length(x)]]). The two operators are the same, the variation just allowing the user to choose the order they write things. The mnemonic is: "data goes on the dot-side of the operator."

Usage

f %|.% args

args %.|% f

Value

f(args) where args elements become individual arguments of f.

Arguments

f

function.

args

argument list or vector, entries expanded as function arguments.

Functions

  • f %|.% args: f reduce args

  • args %.|% f: args expand f

Details

Note: the reduce operation is implemented by do.call(), so has standard R named argument semantics.

See Also

Examples

Run this code

args <- list('prefix_', c(1:3), '_suffix')
args %.|% paste0
# prefix_1_suffix" "prefix_2_suffix" "prefix_3_suffix"
paste0 %|.% args
# prefix_1_suffix" "prefix_2_suffix" "prefix_3_suffix"

Run the code above in your browser using DataLab