当将管道操作器%>%
与dplyr
、ggvis
、dycharts
等包一起使用时,如何有条件地执行步骤?例如
step_1 %>%
step_2 %>%
if(condition)
step_3
这些方法似乎不起作用:
step_1 %>%
step_2
if(condition) %>% step_3
step_1 %>%
step_2 %>%
if(condition) step_3
还有很长的路要走:
if(condition)
{
step_1 %>%
step_2
}else{
step_1 %>%
step_2 %>%
step_3
}
有没有更好的方法不需要所有的冗余?