Skip to content

Instantly share code, notes, and snippets.

@renkun-ken
Last active August 29, 2015 14:08
Show Gist options
  • Save renkun-ken/7060debc32cce49dc57d to your computer and use it in GitHub Desktop.
Save renkun-ken/7060debc32cce49dc57d to your computer and use it in GitHub Desktop.
simpler pipeR_world
# inspired by the amazing idea of hoxo_m
# see http://qiita.com/hoxo_m/items/3fd3d2520fa014a248cb
# shocked even if you don't understand Japanese!
pipes <- function(expr) {
expr <- substitute(expr)
pipe_expr <- if(expr == "{") {
Reduce(function(pl, p) as.call(list(quote(`%>>%`), pl, p)), expr[-1L])
} else expr
eval(pipe_expr, envir = parent.frame())
}
@renkun-ken
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment