Is there a way to `pipe through a list'?

拟墨画扇 提交于 2019-12-04 04:49:51

To construct a sequence of magrittr steps, start with .

action = . %>% group_by(am, gear) %>% summarise(mean = mean(mpg), sd = sd(mpg))

Then it can be used as imagined in the OP:

mtcars %>% action

Like a list, we can subset to see each step:

action[[1]]
# function (.) 
# group_by(., am, gear)

To review all steps, use functions(action) or just type the name:

action
# Functional sequence with the following components:
# 
#  1. group_by(., am, gear)
#  2. summarise(., mean = mean(mpg), sd = sd(mpg))
# 
# Use 'functions' to extract the individual functions. 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!