[Rd] [External] Re: New pipe operator

Gregory Warnes greg @end|ng |rom w@rne@@net
Mon Dec 7 18:03:16 CET 2020

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”,

DF <- "myfile.csv" %>%
    readLines() |>
    fun(x) gsub(r'{(c\(.*?\)|integer\(0\))}', r'{"\1"}', x) |>
    fun(x) read.csv(text = x)|>
              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.


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

> On Mon, Dec 7, 2020 at 10:11 AM <luke-tierney using 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 using 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]]

More information about the R-devel mailing list