list_flatten: Flatten a list

list_flattenR Documentation

Flatten a list

Description

Flattening a list removes a single layer of internal hierarchy, i.e. it inlines elements that are lists leaving non-lists alone.

Usage

list_flatten(
  x,
  is_node,
  name_spec = "{outer}_{inner}",
  name_repair = c("minimal", "unique", "check_unique", "universal")
)

Arguments

x

A list.

is_node

A predicate function that determines whether an element is a node (by returning TRUE) or a leaf (by returning FALSE). The default value, NULL, treats simple lists as nodes and everything else (including richer objects like data frames and linear models) as leaves, using vctrs::obj_is_list(). To recurse into all objects built on lists use is.list().

name_spec

If both inner and outer names are present, control how they are combined. Should be a glue specification that uses variables inner and outer.

name_repair

One of "minimal", "unique", "universal", or "check_unique". See vctrs::vec_as_names() for the meaning of these options.

Value

A list of the same type as x. The list might be shorter if x contains empty lists, the same length if it contains lists of length 1 or no sub-lists, or longer if it contains lists of length > 1.


salim-b/pal documentation built on June 9, 2025, 12:39 a.m.