Do you mean lambda (anonymous function)? You can add something like this to your ~/.Rprofile file:
`{` <- function(...) base::`{`( if (length(sys.calls()) >= 4 && identical(as.character(sys.call()[[1]]), "{") && identical(as.character(sys.call(-4)[[1]]), "{")) base::`{`(fn <- new('function'), formals(fn) <- alist(x=), body(fn) <- sys.call(), fn) else eval.parent(substitute(base::`{`(...))) )
Then you can do things like:
sapply(1:10, {{x + 5}})
This is closer to languages like Ruby or Coffeescript that don't need to refer to a keyword to create a lambda (they use -> , but this is already done in R, so I used double curly braces). I just came up with this, so if there are any errors let me know.
source share