[R] [External] Using the pipe, |>, syntax with "names<-"

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Jul 21 01:02:28 CEST 2024


I second Rich's excellent suggestion.

As with all elegant solutions, Iris's clicked on the wee light bulb in
my brain, and I realized that a slightly more verbose, but perhaps
more enlightening, alternative may be:

z |>  attr("names") |> _[2] <- "foo"

However, I would add this as an example *only with* Iris's solution.
Hers should be shown whether or not the above is.

Cheers,
Bert

On Sat, Jul 20, 2024 at 3:35 PM Richard M. Heiberger <rmh using temple.edu> wrote:
>
> I think Iris's solution should be added to the help file: ?|>
> there are no examples there now that show assignment or replacement using the "_"
>
> > On Jul 20, 2024, at 18:21, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> >
> > On 2024-07-20 6:02 p.m., Iris Simmons wrote:
> >> z <- data.frame(a = 1:3, b = letters[1:3])
> >> z |> names() |> _[2] <- "foo"
> >> z
> >
> > That's a great suggestion!
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list