Toby Hocking
2022-Jul-18 18:06 UTC
[Rd] Warning with new placeholder piped to data.frame extractors `[` and `[[`.
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 at 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 at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Gabriel Becker
2022-Jul-18 19:48 UTC
[Rd] Warning with new placeholder piped to data.frame extractors `[` and `[[`.
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 at 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 at
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 at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
[[alternative HTML version deleted]]
Rui Barradas
2022-Jul-18 19:51 UTC
[Rd] Warning with new placeholder piped to data.frame extractors `[` and `[[`.
Hello,
In the OP I had forgotten the sessionInfo().
Thanks for the feed back but I don't think this answers to the question,
after all the pipe operator was introduced in R 4.2.0 not because it
should be used discouraged.
What it seems to me is that its introduction is causing a problem in
other functions, the data.frame extractors. And only in two of them `[`
and `[[`. They both have arguments x, i, j and it's these arguments that
are not meant to be named.
But *after* the pipe argument x *must* be named. The warning is
inconsistent with the new obligation.
The other extractor, `$.data.frame`, is not indexed and the pipe runs
without a warning. Once again, it is not obvious that a warning message like
named arguments other than 'drop/exact' are discouraged
doesn't include x. As a matter of fact, `$`'s first argument would be
implicitly included in the messages were they thrown, which is not the
case. (This last sentence is confusing but its intent clear?)
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) |> `$`(x = _, 'y')
# [1] 3 8
sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8 LC_CTYPE=Portuguese_Portugal.utf8
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Portugal.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.1
Hope this helps,
Rui Barradas
?s 19:06 de 18/07/2022, Toby Hocking escreveu:> 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 at
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 at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
Martin Maechler
2022-Jul-28 15:16 UTC
[Rd] Warning with new placeholder piped to data.frame extractors `[` and `[[`.
>>>>> Toby Hocking >>>>> on Mon, 18 Jul 2022 11:06:46 -0700 writes: >>>>> Toby Hocking >>>>> on Mon, 18 Jul 2022 11:06:46 -0700 writes:> 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"]] > ?? Well, yes I'd hope so !! Just because there is a pipe operator does not mean you should no longer use reasonable R syntax ! Martin > On Sat, Jul 16, 2022 at 8:27 AM Rui Barradas <ruipbarradas at 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 at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> > [[alternative HTML version deleted]] > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel