统计编程语言 R 中的默认编程是否可行?
Is tacit programming possible in the statistical programming language R?
是tacit programming also known as point-free style - an option in R吗?
检查 magrittr package since it seems closest to what you are asking. 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
是tacit programming also known as point-free style - an option in R吗?
检查 magrittr package since it seems closest to what you are asking. 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