The issue seems to arise from the fact that the function only checks the root node once before starting to work recursively from leaves to root:
function delete_nodes!
...
if filtered
node = delete_node!(node)
# Don't go further if all == false
!all && return
end
delete_nodes!_(node, scale, symbol, link, all, filter_fun, child_link_fun)
...
Changing the function to continue working from root to leaves until the node does not need to be deleted:
function delete_nodes!(
node;
scale=nothing,
symbol=nothing,
link=nothing,
all::Bool=true, # like continue in the R package, but actually the opposite
filter_fun=nothing,
child_link_fun=new_child_link
)
# Check the filters once, and then compute the descendants recursively using `descendants_`
check_filters(node, scale=scale, symbol=symbol, link=link)
filtered = is_filtered(node, scale, symbol, link, filter_fun)
while filtered
node = delete_node!(node)
filtered = is_filtered(node, scale, symbol, link, filter_fun)
# Don't go further if all == false
!all && return
end
delete_nodes!_(node, scale, symbol, link, all, filter_fun, child_link_fun)
return node
end
The function
delete_nodes!
seems to have an issue when deleting the root node as well as one or more nodes that would become its successor root node:The issue seems to arise from the fact that the function only checks the root node once before starting to work recursively from leaves to root:
Changing the function to continue working from root to leaves until the node does not need to be deleted:
fixes the issue for this example: