[Rd] aggregate.formula and pipes
Gabor Grothendieck
ggrothend|eck @end|ng |rom gm@||@com
Tue Feb 8 12:49:05 CET 2022
I noticed that the aggregate issue which I raised
has been fixed in the latest development version of R. Just
wanted to comment on key points that were missed in this discussion on
bugs.r-project.org.
1. Given that it has been known for years that
generics and methods should have consistent arguments yet
until now has remained unaddressed in the core of R I figured it would
stand a better chance of being adopted if the suggested change involved no
code changes, just an export.
I would have suggested that the formula method and generic of aggregate
be made compatible if I had thought anyone would be willing to implement that
but It looks like someone has been willing after all.
2. This is really part of a larger issue that pipes and lapply can expose and
perhaps if aggregate is fixed an effort could be made to find whether
other instances
of conflicting methods and generics in the core exist and make those
consistent too.
3. There is also a discussion there of the use of function(x)... or
\(x)... to avoid
limitations of pipes but this gives rise to a large number of parentheses
e.g. 0 |> (\(x) sin(x) + cos(x))()
I find this too ugly and unreadable to be a reasonable solution. In
such cases I would
either not use base pipes or if I did then define a function prior to the pipe:
e.g. this seems more readable
sincos <- function(x) sin(x) + cos(x)
0 |> sincos()
On Wed, Jan 26, 2022 at 9:48 AM Gabor Grothendieck
<ggrothendieck using gmail.com> wrote:
>
> Because aggregate.formula has a formula argument but the generic
> has an x argument neither of these work:
>
> mtcars |> aggregate(x = mpg ~ cyl, FUN = mean)
> mtcars |> aggregate(formula = mpg ~ cyl, FUN = mean)
>
> This does work:
>
> mtcars |> stats:::aggregate.formula(formula = mpg ~ cyl, FUN = mean)
>
> Suggest that aggregate.formula be exported.
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-devel
mailing list