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.

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

Examples

# basic examples 1:10 %.|% sum
#> [1] 55
1:10 %.|% base::sum
#> [1] 55
1:10 %.|% function(...) { sum(...) }
#> [1] 55
# simulate partial application of log(., base=2) 1:4 %.>% do.call(log, list(., base = 2))
#> [1] 0.000000 1.000000 1.584963 2.000000
# # simluate 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))