Skip to content

Instantly share code, notes, and snippets.

@fernandojunior
Forked from klmr/lambda.r
Created June 26, 2016 22:02
Show Gist options
  • Save fernandojunior/894f231fac9f2aaab79ae5686dfad55b to your computer and use it in GitHub Desktop.
Save fernandojunior/894f231fac9f2aaab79ae5686dfad55b to your computer and use it in GitHub Desktop.
Finally a proper lambda for R
`<-` = function (body, params) {
vars = all.vars(substitute(params))
formals = as.pairlist(setNames(replicate(length(vars), quote(expr = )), vars))
eval.parent(call('function', formals, substitute(body)))
}
sapply(1 : 4, x -> 2 * x)
# 2 4 6 8
mapply(x ~ y -> x + y,
seq(1, 5), seq(10, 50, by = 10))
# 11 22 33 44 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment