From greg @end|ng |rom w@rne@@net  Mon Dec  7 18:03:16 2020
From: greg @end|ng |rom w@rne@@net (Gregory Warnes)
Date: Mon, 7 Dec 2020 12:03:16 -0500
Subject: [Rd] [External] Re: New pipe operator
In-Reply-To: <CAP01uRmP=1vtHUeqS6yAX1BeP1am_2auZCEFbgzm6kb_nafDzA@mail.gmail.com>
References: <e55c2093-0bb5-5f9b-5521-0ca8bdf35953@gmail.com>
 <CALyqOb8c1hHOSaMV+fqXTwpeOsP--KJ_t-oeqMYYafVXeNpqZg@mail.gmail.com>
 <7586e034-e287-0970-6480-f82d747b5445@gmail.com>
 <CADfFDC7bT58_+52uvmpHuMMQRNbbmqV3_7t_fc4sgJ_Esw=xag@mail.gmail.com>
 <CAJmOi+PO_8XDC23=rT=pQ76ENL=gx2V-41ax2fHSVs87xURcEA@mail.gmail.com>
 <alpine.DEB.2.21.2012051203250.3003@luke-Latitude-7480>
 <CAP01uRmd0tRM4xYnegK=YijJv6htqq+fuOwBMBns--0+2a7Opw@mail.gmail.com>
 <alpine.DEB.2.21.2012070908010.3377@luke-Latitude-7480>
 <CAP01uRmP=1vtHUeqS6yAX1BeP1am_2auZCEFbgzm6kb_nafDzA@mail.gmail.com>
Message-ID: <CAKorm_uh1pbJ8pOr0m7MYvE6kDCYETBXAQ1ogzc-g1nvy8d52A@mail.gmail.com>

My vote is for the consistency of function calls always having parentheses,
including in pipes.  Making them optional only saves two keystrokes, but
will add yet another inconsistency to confuse or trip folks up.

As for the new anonymous function syntax, I would prefer something more
human friendly, perhaps provide ?fun? as a shortcut for ?function?,
enabling:

DF <- "myfile.csv" %>%
    readLines() |>
    fun(x) gsub(r'{(c\(.*?\)|integer\(0\))}', r'{"\1"}', x) |>
    fun(x) read.csv(text = x)|>
   mutate(
        across(2:3,
              fun(col) lapply(col,
                   fun(x) eval(parse(text = x))
              )
        )
   )

which seems much easier to read and understand, at the cost of only a few
extra characters.

-G

On Mon, Dec 7, 2020 at 11:21 AM Gabor Grothendieck <ggrothendieck at gmail.com>
wrote:

> On Mon, Dec 7, 2020 at 10:11 AM <luke-tierney at uiowa.edu> wrote:
> > Or, keeping dplyr but with R-devel pipe and function shorthand:
> >
> > DF <- "myfile.csv" %>%
> >     readLines() |>
> >     \(.) gsub(r'{(c\(.*?\)|integer\(0\))}', r'{"\1"}', .) |>
> >     \(.) read.csv(text = .) |>
> >     mutate(across(2:3, \(col) lapply(col, \(x) eval(parse(text = x)))))
> >
> > Using named arguments to redirect to the implicit first does work,
> > also in magrittr, but for me at least it is the kind of thing I would
> > probably regret a month later when trying to figure out the code.
>
> The gsub issue suggests that if one were to start afresh
> that the arguments to gsub (and many other R functions)
> should be rearranged.  Of course, that is precisely what
> the tidyverse did.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
-- 
"Whereas true religion and good morals are the only solid foundations of
public liberty and happiness . . . it is hereby earnestly recommended to
the several States to take the most effectual measures for the
encouragement thereof." Continental Congress, 1778

	[[alternative HTML version deleted]]



[Rd] [External] Re: New pipe operator
Gregory Warnes