Pruning refers to removing entire subtrees. This function has side-effects, it modifies your data.tree structure!

Prune(node, pruneFun)

Arguments

node

The root of the sub-tree to be pruned

pruneFun

allows providing a prune criteria, i.e. a function taking a Node as an input, and returning TRUE or FALSE. If the pruneFun returns FALSE for a Node, then the Node and its entire sub-tree will not be considered.

Value

the number of nodes removed

See also

Examples

data(acme)
acme$Do(function(x) x$cost <- Aggregate(x, "cost", sum))
Prune(acme, function(x) x$cost > 700000)
#> [1] 5
print(acme, "cost")
#>                  levelName    cost
#> 1 Acme Inc.                4950000
#> 2  ¦--Accounting           1500000
#> 3  ¦   °--New Software     1000000
#> 4  °--Research             2750000
#> 5      ¦--New Product Line 2000000
#> 6      °--New Labs          750000