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

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Jul 18 21:51:43 CEST 2022


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



More information about the R-devel mailing list