Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get F#'s function application "|>" operator in R? [duplicate]

Possible Duplicate:
R Pipelining functions

I find R syntax very unwieldy compared to F#:

In R - Instead of:

plot(exp(cumsum(returns)))

I would love to do

returns |> cumsum |> exp |> plot

Is there a way to overload an operator in R to achieve a similar effect?

thanks

like image 481
nxstock-trader Avatar asked Nov 30 '22 13:11

nxstock-trader


2 Answers

sure, why not,

`%|>%` = function(x, y) y(x)
1:10 %|>% cumsum %|>% plot
like image 181
baptiste Avatar answered Dec 04 '22 15:12

baptiste


Stolen from the Reduce help page:

Funcall <- function(f, ...) f(...)
Reduce(Funcall, list(plot, exp, cumsum), 1:10, right = TRUE)
like image 37
IRTFM Avatar answered Dec 04 '22 14:12

IRTFM