Is tacit programming also known as point-free style - an option in R?
Asked
Active
Viewed 156 times
3
-
`Negate`, `Vectorize` and identity are available without any additional addon packages. The functional package has `compose` and `Curry` and some others. Also see the lambda.r package. – G. Grothendieck May 08 '15 at 12:04
1 Answers
2
Check magrittr package since it seems closest to what you are asking. Wikipedia quotes an example:
For example, a sequence of operations in an applicative language like the following:
def example(x): y = foo(x) z = bar(y) w = baz(z) return w
...is written in point-free style as the composition of a sequence of functions, without parameters:
def example: baz bar foo
In R with magrittr
it could be written as
x %>% foo %>% bar %>% baz
where %>%
operator is used to compose a chain of functions, so that the output of a previous function is passed as a first argument of subsequent function. See the magrittr
vignette for learning more.
The function could be defined
# explicitly
example <- function(x) x %>% foo %>% bar %>% baz
# or simply (as @bergant noticed)
example <- . %>% foo %>% bar %>% baz

Tim
- 7,075
- 6
- 29
- 58