Skip to content
Prev 60923 / 63421 Next

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

On Sat, 16 Jul 2022, Rui Barradas wrote:

            
The pipe syntax requirs that the placeolder be used as a named
argument.  If you do that, then the syntax is legal and parses
successfully.
Any R function can decide whether it wants to allow explicitly named
arguments.  Disallowing or discouraging using explicitly named
arguments requires some work and is usually not a good idea. In the
case of the data.frame mechods for [ and [[ the decision was made to
discourage using named arguments other than 'exact'. This seems to
have been to allow a more an expedient way to implement these
functions. This could be revisited, but I doubt is is worth the effort.

For me the main reason for using pipes is to make code more
readable. Using `[` and such constructs is not furthering that
cause. When I use pipes I am almost always using tidyverse
features, so I have dpyr::pull available, which is more readable,
to me at least. Arguably, base R could have a similar function,
but again I doubt this would be a good investment of time.

An option that we have experimented with is to allow the placeholder
at the head of an extraction chain. This is supported in the
experimental branch at
https://svn.r-project.org/R/branches/R-syntax. So for example:

     > mtcars |> _$cyl[1]
     [1] 6

This may make it into R-devel for the next release, but it still needs
more testing.

Best,

luke