xpluck: Get one or more elements deep within a nested data structure

View source: R/xpluck.R

xpluckR Documentation

Get one or more elements deep within a nested data structure

Description

xpluck() provides an alternative to purrr::pluck(). Unlike purrr::pluck(), xpluck() allows you to extract multiple indices at each nesting level.

Usage

xpluck(.x, ..., .default = NULL)

Arguments

.x

A list or vector

...

A list of accessors for indexing into the object. Can be positive integers, negative integers (to index from the right), strings (to index into names) or missing (to keep all elements at a given level).

Unlike purrr::pluck(), each accessor may be a vector to extract multiple elements.

.default

Value to use if target is NULL or absent.

Value

A list or vector.

Examples

obj1 <- list("a", list(1, elt = "foo"))
obj2 <- list("b", list(2, elt = "bar"))
x <- list(obj1, obj2)

xpluck(x, 1:2, 2)
xpluck(x, , 2)

xpluck(x, , 2, 1)
xpluck(x, , 2, 2)
xpluck(x, , 2, 1:2)

crossmap documentation built on Jan. 13, 2023, 1:13 a.m.