You probably want Luke Tierney for the full story, but what I gather from the deliberations (on the private R-core list), there are issues with how non-funcall syntax like lm(....) |> _$coef[2] should work. This, in turn, has to do with wanting to have the placeholder occur only as a toplevel substitution (i.e. "["("$"(_, coef), 2) is a no-go. And the reason for that has to do with the way the pipe works in the absense of placeholder, e.g. the parser gets confused by> x |> f(g(x=_))Error in f(x, g(x = "_")) : invalid use of pipe placeholder -pd> On 17 Apr 2022, at 01:04 , Benjamin Redelings <benjamin.redelings at gmail.com> wrote: > > Hi, > > I see that R 4.2 adds the underscore _ as a placeholder for the new forward pipe operator |> , but only for named arguments. The reason why placeholders for position arguments was NOT added isn't clear to me, so I've been looking for the discussion around the introduction of the placeholder. > > By searching subject lines in the r-devel mailing list archive, I've found > > https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html > > https://stat.ethz.ch/pipermail/r-devel/2021-January/080396.html > > https://stat.ethz.ch/pipermail/r-devel/2020-December/080173.html and following messages > > but not much else. > > 1. Am I looking in the wrong place? > > 2. What is the reasoning behind allowing _ as a placeholder only for named arguments? > > take care, > > -BenRI > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
I think usage of the placeholder in nested calls is another question. The placeholder requires a named argument to improve readability because it's a single character that is easy to miss. Best, Lionel On 4/19/22, peter dalgaard <pdalgd at gmail.com> wrote:> You probably want Luke Tierney for the full story, but what I gather from > the deliberations (on the private R-core list), there are issues with how > non-funcall syntax like lm(....) |> _$coef[2] should work. This, in turn, > has to do with wanting to have the placeholder occur only as a toplevel > substitution (i.e. "["("$"(_, coef), 2) is a no-go. And the reason for that > has to do with the way the pipe works in the absense of placeholder, e.g. > the parser gets confused by > >> x |> f(g(x=_)) > Error in f(x, g(x = "_")) : invalid use of pipe placeholder > > -pd > >> On 17 Apr 2022, at 01:04 , Benjamin Redelings >> <benjamin.redelings at gmail.com> wrote: >> >> Hi, >> >> I see that R 4.2 adds the underscore _ as a placeholder for the new >> forward pipe operator |> , but only for named arguments. The reason why >> placeholders for position arguments was NOT added isn't clear to me, so >> I've been looking for the discussion around the introduction of the >> placeholder. >> >> By searching subject lines in the r-devel mailing list archive, I've >> found >> >> https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html >> >> https://stat.ethz.ch/pipermail/r-devel/2021-January/080396.html >> >> https://stat.ethz.ch/pipermail/r-devel/2020-December/080173.html and >> following messages >> >> but not much else. >> >> 1. Am I looking in the wrong place? >> >> 2. What is the reasoning behind allowing _ as a placeholder only for named >> arguments? >> >> take care, >> >> -BenRI >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Office: A 4.23 > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Thanks to you and Lionel for the info!? I wasn't sure if there was a private core developers list, or if I was just looking in the wrong place. 1. Its good to know that the only reason not to allow _ in positional arguments is that its easy to miss.? Personally, I would like to be able to write f(x, _), but its not a big deal. Is the idea that when you see ??? x |> f(x, y, _, z, w) its hard for the eye to scan the RHS and find the _? Hmm.... I notice that a lot of languages (i.e. Haskell) use _ as a wildcard pattern, and I don't recall any complaints about it being hard to see. 2. I can see how there would be issues with placeholders that aren't at the top level... although I'm not sure precisely what they are.? Any hints? :-)? I did briefly look at the parser/grammar file... Thanks again for the info! -BenRI On 4/19/22 3:24 AM, peter dalgaard wrote:> You probably want Luke Tierney for the full story, but what I gather from the deliberations (on the private R-core list), there are issues with how non-funcall syntax like lm(....) |> _$coef[2] should work. This, in turn, has to do with wanting to have the placeholder occur only as a toplevel substitution (i.e. "["("$"(_, coef), 2) is a no-go. And the reason for that has to do with the way the pipe works in the absense of placeholder, e.g. the parser gets confused by > >> x |> f(g(x=_)) > Error in f(x, g(x = "_")) : invalid use of pipe placeholder > > -pd > >> On 17 Apr 2022, at 01:04 , Benjamin Redelings <benjamin.redelings at gmail.com> wrote: >> >> Hi, >> >> I see that R 4.2 adds the underscore _ as a placeholder for the new forward pipe operator |> , but only for named arguments. The reason why placeholders for position arguments was NOT added isn't clear to me, so I've been looking for the discussion around the introduction of the placeholder. >> >> By searching subject lines in the r-devel mailing list archive, I've found >> >> https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html >> >> https://stat.ethz.ch/pipermail/r-devel/2021-January/080396.html >> >> https://stat.ethz.ch/pipermail/r-devel/2020-December/080173.html and following messages >> >> but not much else. >> >> 1. Am I looking in the wrong place? >> >> 2. What is the reasoning behind allowing _ as a placeholder only for named arguments? >> >> take care, >> >> -BenRI >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel
iuke-tier@ey m@iii@g oii uiow@@edu
2022-Apr-21 15:57 UTC
[Rd] [External] Re: Pipe operator status, placeholders?
At some point there will probably be a blog post about the design of the forward pipe operator in base, but that is not something I will think about until after the current semester is over and my backlog of other things is cleared. Best, luke On Tue, 19 Apr 2022, peter dalgaard wrote:> You probably want Luke Tierney for the full story, but what I gather from the deliberations (on the private R-core list), there are issues with how non-funcall syntax like lm(....) |> _$coef[2] should work. This, in turn, has to do with wanting to have the placeholder occur only as a toplevel substitution (i.e. "["("$"(_, coef), 2) is a no-go. And the reason for that has to do with the way the pipe works in the absense of placeholder, e.g. the parser gets confused by > >> x |> f(g(x=_)) > Error in f(x, g(x = "_")) : invalid use of pipe placeholder > > -pd > >> On 17 Apr 2022, at 01:04 , Benjamin Redelings <benjamin.redelings at gmail.com> wrote: >> >> Hi, >> >> I see that R 4.2 adds the underscore _ as a placeholder for the new forward pipe operator |> , but only for named arguments. The reason why placeholders for position arguments was NOT added isn't clear to me, so I've been looking for the discussion around the introduction of the placeholder. >> >> By searching subject lines in the r-devel mailing list archive, I've found >> >> https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html >> >> https://stat.ethz.ch/pipermail/r-devel/2021-January/080396.html >> >> https://stat.ethz.ch/pipermail/r-devel/2020-December/080173.html and following messages >> >> but not much else. >> >> 1. Am I looking in the wrong place? >> >> 2. What is the reasoning behind allowing _ as a placeholder only for named arguments? >> >> take care, >> >> -BenRI >> >> ______________________________________________ >> 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