Skip to contents

Traverse a nested list and return all paths whose element is identical to value.

Usage

list_find_value(x, value)

Arguments

x

A nested list to traverse.

Lists are traversed recursively. Non-list objects are treated as leaves. Data frames are not traversed and are treated as leaf values.

value

Value to find.

Value

A list of character vectors, or NULL if no match is found.

Examples

x <- list(
  a = 1,
  b = list(c = 2, d = list(e = 1)),
  list(1)
)

list_find_value(x, 1)
#> [[1]]
#> [1] "a"
#> 
#> [[2]]
#> [1] "b" "d" "e"
#> 
#> [[3]]
#> [1] "3" "1"
#>