knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
Lambda contains only one function f()
, which allows you to write new
functions in a very compact format.
Simply write the body of the function as you would normally. If you want a
given variable to appear as one of the arguments to the function, surround it with
.()
. Default arguments can be also be specified within .()
as you normally
would in the argument list.
library(lambda) function(x, y) x + y f(.(x) + .(y)) Reduce(f(.(x) + .(y)), 1:10) add <- f(.(x) + .(y = 5)) add add(1) add(1, 2)
It works very well as a way to compactly define simple utility functions
x <- list(1, list(NULL), 2) compact <- f(Filter(Negate(is.null), .(x))) compact compact(x)
Or for partial function application
f1 <- f(runif(n = rpois(1, 5), .(...))) f1
For a different (better?) approach to this same idea, see pryr::f().
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.