Skip to contents

Keeps only the top-level children whose names match names (in tree order), reindexing the remaining leaves so they map to contiguous positions in a flat list.

Usage

tree_filter_by_names(tree, names)

Arguments

tree

(RTree)
A named list tree as returned by build_tree().

names

(character())
Names of children to keep.

Value

A RTree containing only the selected children.

Examples

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