%F%
Javascript-style arrow (=>
) function expressions in R.
library(fu)
f <- c(a, b, c) %F% {a + b * c}
f
#> function (a, b, c)
#> {
#> a + b * c
#> }
f(10, 10, 10)
#> [1] 110
Functions with no arguments can be expressed with an empty vector c()
:
greet_user <- c() %F% cat("hi", Sys.getenv("USER"), "!")
For unary functions the use of c
is optional:
f <- d %F% {d * d}
Functions with default arguments can be expressed as a named vector:
f <- c(a, b = 10) %F% {a * a * b}
%F%
has two aliases: %f%
and %=>%
although the latter is less pleasant to type.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.