On 12/4/20 3:05 PM, Duncan Murdoch wrote:> ... > > It's tempting to suggest it should allow something like > > ? mtcars |> subset(cyl == 4) |> lm(mpg ~ disp, data = .) > > which would be expanded to something equivalent to the other versions: > but that makes it quite a bit more complicated.? (Maybe _ or \. should > be used instead of ., since those are not legal variable names.)I support the idea of using an underscore (_) as the placeholder symbol. Syntactic sugars work the the best if 1) they require less keystrokes and/or 2) are easier to read compared to the "normal" syntax, and 3) can not lead to unexpected bugs (which is a major problem with the magrittr pipe). Using '_' fulfills all of these criteria since '_' can not clash with any variable in the environment. Denes
iuke-tier@ey m@iii@g oii uiow@@edu
2020-Dec-04 19:26 UTC
[Rd] [External] Re: New pipe operator
On Fri, 4 Dec 2020, D?nes T?th wrote:> > On 12/4/20 3:05 PM, Duncan Murdoch wrote: >> ... >> >> It's tempting to suggest it should allow something like >> >> ? mtcars |> subset(cyl == 4) |> lm(mpg ~ disp, data = .) >> >> which would be expanded to something equivalent to the other versions: but >> that makes it quite a bit more complicated.? (Maybe _ or \. should be used >> instead of ., since those are not legal variable names.) > > I support the idea of using an underscore (_) as the placeholder symbol.I strongly oppose adding a placeholder. Allowing for an optional placeholder significantly complicates both implementing and explaining the semantics. For a simple syntax transformation to be viable it would also require some restrictions, such as only allowing a placeholder as a top level argument and only once. Checking that these restrictions are met, and accurately signaling when they are not with reasonable error messages, is essentially an unsolvable problem given R's semantics. The case where the LHS is to be passed as something other than the first argument is unusual. For me, having that case stand out by using a function expression makes it much easier to see and so makes the code easier to understand. As a wearer of progressive bifocals and someone whose screen is not always free of small dust particles, having to spot the non-standard pipe stages by seeing a placeholder, especially a . placeholder, is be a bug, not a feature. Best, luke> Syntactic sugars work the the best if 1) they require less keystrokes and/or > 2) are easier to read compared to the "normal" syntax, and 3) can not lead to > unexpected bugs (which is a major problem with the magrittr pipe). Using '_' > fulfills all of these criteria since '_' can not clash with any variable in > the environment. > > Denes > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Luke Tierney Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu