Learn R Programming

listr (version 0.1.0)

list_flatten: Flatten nested lists.

Description

`list_flatten()` works recursively through an input list and puts all elements of nested list to the top level. If there are no nested lists then the input is returned unchanged.

Usage

list_flatten(in_list, max_depth = -1)

Value

A list without nested lists.

Arguments

in_list

The list to flatten

max_depth

Maximum depth to recurse into.

Details

Using `max_depth` you can control whether to flatten all nested lists. Negative values will cause all nested lists to be flattened, positive depths will limit the depth of the recursion.

Examples

Run this code
my_list <- list(a = list(1, 2, 3), b = list(4, 5, 6))
list_flatten(my_list)

Run the code above in your browser using DataLab