Skip to content

Instantly share code, notes, and snippets.

@kohske
Created January 21, 2012 17:41
Show Gist options
  • Save kohske/1653395 to your computer and use it in GitHub Desktop.
Save kohske/1653395 to your computer and use it in GitHub Desktop.
R pipe
`|` <- function(a, b) {
env <- parent.frame()
ret <- eval(a, env)
bb <- llply(substitute(b), function(x) if(x==alist(,)[[1]]) ret else x)
if (length(bb) == 1) bb[[2]] <- ret
invisible(eval(as.call(bb), env))
}
s <- "a"
(1 + 1) | paste(,2, sep=s) | sub("a", "b", ) | print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment