2015-05-08 36 views

回答

2

检查magrittr包,因为它似乎最接近你问的。 Wikipedia引用一个例子:

例如,操作像 一个适用语言的顺序如下:

def example(x): 
    y = foo(x) 
    z = bar(y) 
    w = baz(z) 
    return w 

...是用自由点式的序列组成的 功能,如果没有参数:

def example: baz bar foo

在R 2与它magrittr可以写成

x %>% foo %>% bar %>% baz 

其中%>%操作者用于撰写的功能的链,从而使前一函数的输出作为后续函数的第一个参数传递。了解更多信息,请参阅magrittr小插曲。

的功能可以被定义

# explicitly 
example <- function(x) x %>% foo %>% bar %>% baz 

# or simply (as @bergant noticed) 
example <- . %>% foo %>% bar %>% baz 
+1

定义一个函数:'example <- . %>%foo%>%bar%>%baz'。 – bergant