Skip to content
Prev 396595 / 398502 Next

Using the pipe, |>, syntax with "names<-"

That was supposed to be

  z |> list(x = _) |> within(names(x) <- replace(names(x), 2, "foo")) |> _$x

but I really see no advantage over

  z |> list(x = _) |> within(names(x)[2] <- "foo") |> _$x

Regarding the z |> names() |> _[2] <- "foo" idiom, while it is clever,
and well illustrates
what is possible with base R pipes that might not be initially expected,
I think it should be discouraged as not in the spirit of pipes which is a more
functional approach to programming.  Such an approach ought to be
non-destructive and should pass on the result to the next
step in the pipeline.  These criteria are not satisfied by it.

On Sun, Jul 21, 2024 at 11:17?AM Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: