Skip to content
Prev 59428 / 63430 Next

brief update on the pipe operator in R-devel

Gabor,

Although it might be nice if all imagined cases worked, there are many ways to work around and get the results you want. 

You may want to consider that it is easier to recognize the symbol you use (x in the examples) if it is alone and used only exactly once and it the list of function arguments.  If you want the x used multiple times, you can make a function that accepts the x once and then invokes another function and reuses the x as often as needed. Similarly for 1+x. 

I do not know if the above choice was made to make it easier and faster to apply the above, or to avoid possible bad edge cases. Have you tested other ideas like:

	3 |> x => f(x=5)
Or
	3 |> x => f(x, y=x)

I mean ones where a default is supplied, not that it makes much sense here?

I am thinking of the concept of substitution as is often done for text or symbols. Often the substitution is done for the first instance found unless you specify you want a global change. In your examples, if only the first use of x would be replaced, the second naked x being left alone would be an error. If all instances were changed, what anomalies might happen? Giving a vector of length 1 containing the number 3 seems harmless enough to duplicate. But the pipeline can send all kinds of interesting data structures through including data.frames and arbitrary objects. 


-----Original Message-----
From: R-devel <r-devel-bounces at r-project.org> On Behalf Of Gabor Grothendieck
Sent: Friday, January 15, 2021 7:28 AM
To: Tierney, Luke <luke-tierney at uiowa.edu>
Cc: R-devel at r-project.org
Subject: Re: [Rd] brief update on the pipe operator in R-devel

These are documented but still seem like serious deficiencies:
Error in f(x, x) : pipe placeholder may only appear once
Error in f(1 + x, 1) :
  pipe placeholder must only appear as a top-level argument in the RHS call

Also note:

 ?"=>"
No documentation for ?=>? in specified packages and libraries:
you could try ???=>?
On Tue, Dec 22, 2020 at 5:28 PM <luke-tierney at uiowa.edu> wrote:
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel