<分区>
是tacit programming也称为无点样式 - R 中的一个选项?
<分区>
是tacit programming也称为无点样式 - R 中的一个选项?
最佳答案
检查 magrittr包,因为它似乎最接近您的要求。 Wikipedia引用一个例子:
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
在带有 magrittr
的 R 中,它可以写成
x %>% foo %>% bar %>% baz
其中 %>%
运算符用于组成函数链,以便将前一个函数的输出作为后续函数的第一个参数传递。请参阅 magrittr
小插图以了解更多信息。
可以定义函数
# explicitly
example <- function(x) x %>% foo %>% bar %>% baz
# or simply (as @bergant noticed)
example <- . %>% foo %>% bar %>% baz
关于r - 统计编程语言 R 中的默认编程是否可行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30121731/