Skip to content
Prev 393523 / 398503 Next

Pipe operator

"Does saving of variables speed up processing" no
"or save memory" no.
The manual is quite explicit:
...
Currently, pipe operations are implemented as syntax
transformations.  So an expression written as 'x |> f(y)' is
parsed as 'f(x, y)'.

Strictly speaking, using |> *doesn't* save any variables.
x |> f(y) |> g() |> h(1,z)
simply is h(g(f(x,y)),1,z) in which precisely the same
variables appear.  All that changes is the order in which
you write the function names; the order in which things are
evaluated does not change (the manual is explicit about
that too).

I personally find |> in R extremely confusing because
in x |> f(y) |> g() |> h(1,z)
it LOOKS as if there are calls to f(f), to g(), and to
h(1,z) and in Haskell or F# that would be true, but in
R the expressions f(y), g(), and h(1,z) are NOT
evaluated.  |> is and has to be special syntax with a
very restricted right-hand side.

Eliminating well-chosen variables can of course make
code much less readable.  It's funny how my code seems
prettier using |> but other people's code seems hopelessly
obscure...
On Wed, 4 Jan 2023 at 06:19, Sorkin, John <jsorkin at som.umaryland.edu> wrote:

            

  
  
Message-ID: <CABcYAdLiqbfTJzZrDerjh2X18unwCf1fSYYdV01qguY91_X5zw@mail.gmail.com>
In-Reply-To: <MW4PR03MB63630F7F3EA776AB218EFD2AE2F49@MW4PR03MB6363.namprd03.prod.outlook.com>