Skip to content
Prev 396588 / 398502 Next

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

This
- is non-destructive (does not change z)
- passes the renamed z onto further pipe legs
- does not use \(x)...

It works by boxing z, operating on the boxed version and then unboxing it.

  z <- data.frame(a = 1:3, b = letters[1:3])
  z |> list(x = _) |> within(names(x)[2] <- "foo") |> _$x
  ##   a foo
  ## 1 1   a
  ## 2 2   b
  ## 3 3   c
On Sat, Jul 20, 2024 at 4:07?PM Bert Gunter <bgunter.4567 at gmail.com> wrote: