[Rd] Warning with new placeholder piped to data.frame extractors `[` and `[[`.

Gabriel Becker g@bembecker @end|ng |rom gm@||@com
Mon Jul 18 21:48:23 CEST 2022


It looks to me like the 'bug' here seems to be that

aggregate(y ~ f, df1, mean) |> `[`(x = _, 'y')


does not throw the same error as

aggregate(y ~ f, df1, mean) |> `[`('y')


Since the latter seems pretty clear that the intent is that `[` is
disallowed on the RHS of the pipe by design.

~G


On Mon, Jul 18, 2022 at 11:07 AM Toby Hocking <tdhock5 using gmail.com> wrote:

> Is the intent is to encourage the user to do something simpler like...
> aggregate(y ~ f, df1, mean)$y
> aggregate(y ~ f, df1, mean)["y"]
> aggregate(y ~ f, df1, mean)[["y"]]
> ??
>
> On Sat, Jul 16, 2022 at 8:27 AM Rui Barradas <ruipbarradas using sapo.pt> wrote:
>
> > Hello,
> >
> > When piping to any of `[.data.frame` or `[[.data.frame`, the placeholder
> > in mandatory.
> >
> >
> > df1 <- data.frame(y = 1:10, f = rep(c("a", "b"), each = 5))
> >
> > aggregate(y ~ f, df1, mean) |> `[`('y')
> > # Error: function '[' not supported in RHS call of a pipe
> >
> > aggregate(y ~ f, df1, mean) |> `[[`('y')
> > # Error: function '[' not supported in RHS call of a pipe
> >
> >
> >
> > But if used it throws a warning.
> >
> >
> >
> > aggregate(y ~ f, df1, mean) |> `[`(x = _, 'y')
> > #  Warning in `[.data.frame`(x = aggregate(y ~ f, df1, mean), "y"):
> > named arguments
> > #  other than 'drop' are discouraged
> > #    y
> > #  1 3
> > #  2 8
> >
> > aggregate(y ~ f, df1, mean) |> `[[`(x = _, 'y')
> > #  Warning in `[[.data.frame`(x = aggregate(y ~ f, df1, mean), "y"):
> named
> > #  arguments other than 'exact' are discouraged
> > #  [1] 3 8
> >
> >
> >
> > Hasn't this become inconsistent behavior?
> > More than merely right, the named argument is mandatory, it shouldn't
> > give warnings.
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list