| FindNode {data.tree} | R 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 |
name |
The name of the |
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
[Package data.tree version 1.1.0 Index]