Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active April 13, 2023 11:27
Show Gist options
  • Save klmr/25dc765211c59bb749b0 to your computer and use it in GitHub Desktop.
Save klmr/25dc765211c59bb749b0 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