FindNode: Find a node by name in the (sub-)tree

View source: R/node_methods.R

FindNodeR Documentation

Find a node by name in the (sub-)tree

Description

Scans the entire sub-tree spanned by node and returns the first Node having the name specified. This is mainly useful for trees whose name is unique. If AreNamesUnique is FALSE, i.e. if there is more than one Node called name in the tree, then it is undefined which one will be returned. Also note that this method is not particularly fast. See examples for a faster way to index large trees, if you need to do multiple searches. See Traverse if you need to find multiple Nodes.

Usage

FindNode(node, name)

Arguments

node

The root Node of the tree or sub-tree to search

name

The name of the Node to be returned

Value

The first Node whose name matches, or NULL if no such Node is found.

See Also

AreNamesUnique, Traverse

Examples

data(acme)
FindNode(acme, "Outsource")

#re-usable hashed index for multiple searches:
if(!AreNamesUnique(acme)) stop("Hashed index works for unique names only!")
trav <- Traverse(acme, "level")
names(trav) <- Get(trav, "name")
nameIndex <- as.environment(trav)
#you could also use hash from package hash instead!
#nameIndex <- hash(trav)
nameIndex$Outsource
nameIndex$IT



data.tree documentation built on Nov. 13, 2023, 1:08 a.m.