Learn R Programming

wrapr (version 1.9.6)

reduceexpand: Use function to reduce or expand arguments.

Description

The operators %.|% and %|.% are wrappers for do.call. These functions are used to pass arguments from a list to variadic function (such as sum). The operator symbols are meant to invoke non-tilted versions of APL's reduce and expand operators. Unevaluated expressions containing %.|%, %|.%, or do.call can be used simulate partial function application or simulate function Currying. The take-away is one can delegate all variadic argument construction to list, and manipulation to c.

Usage

f %|.% args

args %.|% f

Arguments

f

function.

args

argument list or vector, entries expanded as function arguments.

Value

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

Functions

  • %|.%: f reduce args

  • %.|%: args expand f

See Also

do.call, list, c

Examples

Run this code
# NOT RUN {
# basic examples
1:10 %.|% sum
1:10 %.|% base::sum
1:10 %.|% function(...) { sum(...) }

# simulate partial application of log(., base=2)
1:4 %.>% do.call(log, list(., base = 2))

# # simulate partial application with dplyr
# # can be used with dplyr/rlang as follows
# d <- data.frame(x=1, y=2, z=3)
# syms <- rlang::syms(c("x", "y"))
# d %.>% do.call(dplyr::select, c(list(.), syms))

# }

Run the code above in your browser using DataLab