Skip to content
Prev 59223 / 63424 Next

[External] Re: New pipe operator

Dear Luke,

In the meantime I checked the R-syntax branch and the docs; they are 
very helpful. I would also like to thank you for putting effort into 
this feature. Keeping it at the syntax level is also a very smart 
decision. However, the current API might not exploit the full power of 
the basic idea.

1) Requiring either an anonymous function or a function call, but not 
allowing for symbols which point to functions is inconsistent and will 
be misleading for non-experts.

foo <- function(x) x
identical(foo, function(x) x)

mtcars |> foo               #bang!
mtcars |> function(x) x     #fine?

You stated in :
"
Another variation supported by the implementation is that a symbol on
the RHS is interpreted as the name of a function to call with the LHS
as argument:

```r
 > quote(x |> f)
f(x)
```
"

So clearly this is not an implementation issue but a design decision.

As a remedy, two different pipe operators could be introduced:

LHS |> RHS    -> RHS is treated as a function call
LHS |>> RHS   -> RHS is treated as a function

If |>> is used, it would not matter which notation is used for the RHS 
expression; the parser would assume it evaluates to a function.

2) Simplified lambda expression:
IMHO in the vast majority of use cases, this is used for single-argument 
functions, so parenthesis would not be required. Hence, both forms would 
be valid and equivalent:

\x x + 1
\(x) x + 1


3) Function composition:
Allowing for concise composition of functions would be a great feature. 
E.g., instead of

foo <- function(x) print(mean(sqrt(x), na.rm = TRUE), digits = 2)

or

foo <- \x {x |> sqrt() |> mean(na.rm = TRUE) |> print(digits = 2)}

one could write

foo <- \x |> sqrt() |> mean(na.rm = TRUE) |> print(digits = 2)

So basically if the lambda argument is followed by a pipe operator, the 
pipe chain is transformed to a function body where the first lambda 
argument is inserted into the first position of the pipeline.


Best,
Denes
On 12/5/20 7:10 PM, luke-tierney at uiowa.edu wrote:

Thread (78 messages)

Duncan Murdoch New pipe operator Dec 4 Hiroaki Yutani New pipe operator Dec 4 Duncan Murdoch New pipe operator Dec 4 Dénes Tóth New pipe operator Dec 4 Sebastian Meyer New pipe operator Dec 4 Deepayan Sarkar New pipe operator Dec 4 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 4 Duncan Murdoch New pipe operator Dec 4 Duncan Murdoch New pipe operator Dec 4 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 4 Avi Gross New pipe operator Dec 4 Ivan Krylov New pipe operator Dec 4 Duncan Murdoch New pipe operator Dec 5 Hugh Parsonage New pipe operator Dec 5 Gabor Grothendieck New pipe operator Dec 5 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 5 John Mount New pipe operator Dec 5 Abby Spurdle New pipe operator Dec 5 Gregory R. Warnes New pipe operator Dec 5 Hiroaki Yutani New pipe operator Dec 5 Rui Barradas New pipe operator Dec 5 Jan Gorecki New pipe operator Dec 6 Dénes Tóth New pipe operator Dec 6 Avi Gross New pipe operator Dec 6 Duncan Murdoch New pipe operator Dec 6 Dénes Tóth New pipe operator Dec 6 Duncan Murdoch New pipe operator Dec 6 Gabor Grothendieck New pipe operator Dec 6 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 6 Gabor Grothendieck New pipe operator Dec 6 Avi Gross New pipe operator Dec 6 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 6 Gabriel Becker New pipe operator Dec 6 Dénes Tóth New pipe operator Dec 6 Gabor Grothendieck New pipe operator Dec 6 Gabriel Becker New pipe operator Dec 6 Gabor Grothendieck New pipe operator Dec 6 Bravington, Mark (Data61, Hobart) New pipe operator Dec 6 Gabriel Becker New pipe operator Dec 6 Gabor Grothendieck New pipe operator Dec 6 Duncan Murdoch New pipe operator Dec 7 Duncan Murdoch New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 7 Deepayan Sarkar New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 Deepayan Sarkar New pipe operator Dec 7 Peter Dalgaard New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 Duncan Murdoch New pipe operator Dec 7 Gregory R. Warnes New pipe operator Dec 7 Peter Dalgaard New pipe operator Dec 7 Duncan Murdoch New pipe operator Dec 7 Duncan Murdoch New pipe operator Dec 7 iuke-tier@ey m@iii@g oii uiow@@edu New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 Kevin Ushey New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 7 Gabriel Becker New pipe operator Dec 7 Gabriel Becker New pipe operator Dec 7 Dénes Tóth New pipe operator Dec 7 Gabriel Becker New pipe operator Dec 7 Gabor Grothendieck New pipe operator Dec 8 Hadley Wickham New pipe operator Dec 8 Gabor Grothendieck New pipe operator Dec 8 Bravington, Mark (Data61, Hobart) New pipe operator Dec 8 Duncan Murdoch New pipe operator Dec 8 Bravington, Mark (Data61, Hobart) New pipe operator Dec 8 Jan van der Laan New pipe operator Dec 9 Duncan Murdoch New pipe operator Dec 9 Duncan Murdoch New pipe operator Dec 9 Jan van der Laan New pipe operator Dec 9 Duncan Murdoch New pipe operator Dec 9 Gabor Grothendieck New pipe operator Dec 9 Gabriel Becker New pipe operator Dec 9 Gabor Grothendieck New pipe operator Dec 9 Peter Dalgaard New pipe operator Dec 9