[R] the opposite of pluck() in purrr
r@turner @end|ng |rom @uck|@nd@@c@nz
Thu Nov 18 23:49:29 CET 2021
On Thu, 18 Nov 2021 16:40:14 -0500
"Christopher W. Ryan via R-help" <r-help using r-project.org> wrote:
> I've just learned about pluck() and chuck() in the purrr package. Very
> cool! As I understand it, they both will return one element of a
> list, either by name or by [] index, or even "first" or "last"
> I was hoping to find a way to return all *but* one specified element
> of a list. Speaking loosely, pluck(-1) or pluck(!1) or !pluck(1), but
> none of those of course work. Thinking of English language, I had
> hopes for chuck(1) as in "chuck element 1 away, leaving the rest"
> but that's now how it works.
> Any tidyverse-centric ways to return all except one specified element
> of a list?
Why (on earth!) hand-cuff yourself to someone else's prescription of
how things should be done? Why not just do it yourself, especially
given that it's so easy in this instance?
Use mung[] to get the first entry of a list named "mung".
Or mung of one if you want a *list* whose sole entry is the
first entry of mung.
Likewise mung[-1] will give you the "all but" results.
Fewer key strokes, even. Tell tidyverse/purrr to pluck off! :-)
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help