renkun-ken / pipeR

Multi-Paradigm Pipeline Implementation
Other
167 stars 39 forks source link

Support operator-free pipeline #60

Closed renkun-ken closed 9 years ago

renkun-ken commented 9 years ago

In this post, @hoxo_m creates a very interesting function called pipeR_world() that allows users to build pipeline without using any noisy operator.

Here's my simplified implementation: https://gist.github.com/renkun-ken/7060debc32cce49dc57d

This feature uses NSE at expression level and allows the following code:

library(dplyr)
library(pipeR)
pipes({
  mtcars
  group_by(vs)
  summarise(mean_mpg = mean(mpg))
})
# Source: local data frame [2 x 2]
# 
#   vs mean_mpg
#1  0 16.61667
#2  1 24.55714

If there's no critical potential problem about it, consider to support this feature in future.

renkun-ken commented 9 years ago

Since %>>% is a user-defined operator and has to deal with the priority issues with other symbols like ~, then expressions using these symbols need to be enclosed in () to take effect. This can be simplified using pipeline() which directly takes an expression object so that I bring the syntax for special symbols inside () to an outer level, which does not affect %>>% but allows pipeline() to run the following code:

pipeline({
  mtcars
  ~ cat("rows:", nrow(.))
  lm(formula = mpg ~ wt + cyl)
  summary
})
yanlinlin82 commented 9 years ago

That is a very interesting idea, which may have opened a door to more possibilities.