Skip to content
Prev 60920 / 63424 Next

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: