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

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sat Jul 16 17:25:44 CEST 2022


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



More information about the R-devel mailing list