Skip to contents

Subsets a ListNode to keep only the children whose names match names, then reindexes the leaf nodes so they map to contiguous positions in a flat list. If all names are kept the original tree is returned unchanged.

Usage

filter_list_node(tree, names)

Arguments

tree

(ListNode)
A named list node as returned by build_tree().

names

(character)
Names of children to keep.

Value

A ListNode containing only the selected children with reindexed leaves.

Examples

x <- list(a = 1, b = 2, c = 3)
tree <- build_tree(x)
sub <- filter_list_node(tree, c("a", "c"))
tree_size(sub)
#> [1] 2

unflatten(sub, x[c("a", "c")])
#> $a
#> [1] 1
#> 
#> $c
#> [1] 3
#>