Skip to content
Prev 59243 / 63421 Next

New pipe operator

Seems like this *could* be a good thing, and thanks to R core for considering it. But, FWIW:

 - I agree with Gabor G that consistency of "syntax" should be paramount here. Enough problems have been caused by earlier superficially-convenient non-standard features in R.  In particular:

 -- there should not be any discrepancy between an in-place function-definition, and a predefined function attached to a symbol (as per Gabor's point). 
 
 -- Hence, the ability to say x |> foo  ie without parentheses, seems bound to lead to inconsistency, because x |> foo is allowed, x |> base::foo isn't allowed without tricks, but x |> function( y) foo( y) isn't... So, x |> foo is not worth keeping. Parentheses are a price well worth paying.
 
 -- it is still inconsistent and confusing to (apparently) invoke a function in some places--- normally--- via 'foo(x)', yet in others--- pipily--- via 'foo()'. Especially if 'foo' already has a default value for its first argument.

 - I don't see the problem with a placeholder--- doesn't it remove all ambiguity? Sure there needs to be a standard unclashable name and people can argue about what that should be, but the following seems clear and flexible... to me, anyway:
 
 thing |> 
   foo( _PIPE_) |>           # standard
   bah( arg1, _PIPE_) |>   # multi-arg function
   _ANON_({ x <- sum( _PIPE_); _PIPE_/x + x/_PIPE_ })   # anon function
  
where '_PIPE_' is the ordained name of the placeholder, and '_ANON_' constructs-and-calls a function with single argument '_PIPE_'. There is just one rule (I think...): each pipe-stage must be a *call* involving the argument '_PIPE_'.


 - The proposed anonymous-function syntax looks quite ugly to me, diminishing readability and inviting errors. The new pipe symbol |> already looks scarily like quantum mechanics; adding \( just puts fishbones into the symbolic soup.

 - IMO it's not worth going too far to try to lure magritter-etc fans to swap to the new; my experience is that many people keep using older inferior R syntax for years after better replacements become available (even if they are aware of replacements), for various reasons. Just provide a good framework, and let nature take its course.
 
 - Disclaimer: personally I'm not much of a pipehead anyway, so maybe I'm not the audience. But if I was to consider piping, I wouldn't be very tempted by the current proposal. OTOH, I might even be tempted to write--- and use!--- my own version of '%|>%' as above (maybe someone already has). And if R did it for me, that'd be great :)
 
[*] Definition of _ANON_ could be something like this--- almost certainly won't work as-is, this is just to point out that it could be done in standard R.

`_ANON_` <- function( expr) { 
  #1. Construct a function with arg '_PIPE_' and body 'expr'
  #2. Construct a call() to that function
  #3. Do the call

  f <- function( `_PIPE_`) NULL
  body( f) <- expr
  environment( f) <- parent.frame() # or something... yes these details are almost certainly wrong
  expr2 <- substitute( f( `_PIPE_`)) # or something...
  eval.parent( expr2) # or something... 
}

cheers
Mark

Mark Bravington
CSIRO Marine Lab
Hobart
Australia
Message-ID: <MEAPR01MB2407865F5622461515F409EDB4CE0@MEAPR01MB2407.ausprd01.prod.outlook.com>
In-Reply-To: <CAP01uRmTYna1nM+ugELHrCqLjfWuWwHSfE4cvqoaq2537sHpAw@mail.gmail.com>

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