Skip to content
Prev 393504 / 398503 Next

[External Email] Pipe operator

I think there are probably a number of purposes for (advantages to?)
the pipe operator. One is that it can avoid nested operations:

plot(mean(sqrt(c(1:10))))  ## this is my silly example code

which can get difficult to read.  This is arguably easier to read and
understand:

c(1:10) %>% sqrt() %>% mean() %>% plot()

As the chain of operations become longer, and as each "link" in the
chain becomes more complex, the value of the pipe approach, compared
to deep nesting in parentheses, increases, in my view.

--Chris Ryan
On Tue, Jan 3, 2023 at 11:48 AM Sorkin, John <jsorkin at som.umaryland.edu> wrote:
Message-ID: <CAM+rpYm5GaG+0Ed04meDaWNhihJGXTHZqgPUKnD8avODQt=J2A@mail.gmail.com>
In-Reply-To: <MW4PR03MB63630F75F8C75E3448161E00E2F49@MW4PR03MB6363.namprd03.prod.outlook.com>