Learn R Programming

wrapr (version 1.0.1)

makeFunction_se: Build an anonymous function.

Description

Developed from: http://www.win-vector.com/blog/2016/12/the-case-for-using-in-r/comment-page-1/#comment-66399, https://github.com/klmr/functional#a-concise-lambda-syntax, https://github.com/klmr/functional/blob/master/lambda.r Called from := operator.

Usage

makeFunction_se(params, body, env = parent.frame())

Arguments

params

formal parameters of function, unbound names.

body

subsituted body of function to map arguments into (braces required for ":=" notation).

env

environment to work in.

Value

user defined function.

Examples

Run this code
# NOT RUN {
f <- makeFunction_se(as.name('x'), substitute({x*x}))
f(7)

f <- x := { x*x }
f(7)

g <- makeFunction_se(c(as.name('x'), as.name('y')), substitute({ x + 3*y }))
g(1,100)

g <- c(x,y) := { x + 3*y }
g(1,100)

# }

Run the code above in your browser using DataLab