flatten: Flatten a recursive list

View source: R/all_custom_functions.R

flattenR Documentation

Flatten a recursive list

Description

This function flattens a recursive list into a non-recursive list, keeping all the elements (which do not inherit class "list") in the leaves of the original list intact. Therefore, data frames remain for example unchanged which is a different behavior compared to unlist. The function was taken from the internet, see: https://stackoverflow.com/questions/47603578/flatten-recursive-list

Usage

flatten(x)

Arguments

x

An R object, intended to be a recursive list.

Value

Returns a non-recursive list, listing all elements in the leaves of x.

Examples

X <- list(a = list(b = pi, c = iris[1:3,]), d = 1:10)
flatten(X)

ryannick28/CustomFunctionsYrotha documentation built on June 1, 2025, 4:02 p.m.