Is such silent programming possible in the statistical programming language R?
1 answer
Check the magrittr package as it seems closest to what you are asking for. Wikipedia gives an example:
For example, a sequence of operations in an applicative language such as the following:
def example(x): y = foo(x) z = bar(y) w = baz(z) return w
... is written in dotted style as the composition of a sequence of functions without parameters:
def example: baz bar foo
In R c magrittr
it can be written as
x %>% foo %>% bar %>% baz
where the operator is %>%
used to chain the functions so that the output of the previous function is passed as the first argument to the next function. See Vignette magrittr
for more information.
The function can be defined
# explicitly
example <- function(x) x %>% foo %>% bar %>% baz
# or simply (as @bergant noticed)
example <- . %>% foo %>% bar %>% baz
+2
source to share