Skip to contents

This function takes a named list as input and returns a data frame with two columns: the name of each list element (including parent element names), and its corresponding value. If the input is not a list, the function returns a data frame with a single row containing the value and its parent name (if provided).

Usage

flatten_named_list(lst, parent_name = "")

Arguments

lst

A named list to be flattened into a data frame.

parent_name

A character string indicating the name of the parent list element. This argument is optional and should only be provided if the input list is a child element of a larger parent list. By default, the parent name is set to an empty string.

Value

A data frame with two columns: the name of each list element (including parent element names), and its corresponding value.

Examples

test_list <- list(a = 1, b = list(c = 2, d = 3))
flatten_named_list(test_list)
#>   name value
#> 1    a     1
#> 2  b.c     2
#> 3  b.d     3