[R] Collecting output from terminal nodes in a recursion tree
B Q
bald___eagle at hotmail.com
Fri Sep 26 22:10:24 CEST 2008
I have a recursive function. The recursion forms a tree with many
(millions) terminal nodes. The function must output a value (say, a
number or a vector) from each terminal node. At the end, when all
recursion is done, we want to collect all the output values. How can
that be done cleanly and efficiently?
A prototype example is a recursive function that generates all
permutations of a vector (or simply of 1:n). One permutation is
generated at each terminal node.
Terminal nodes occur at various depths in the tree. We don't need to
pass anything up the tree, just output from the terminal nodes.
Is there a way to create a global data structure and have a function
tack data onto that structure? sort of like the C++ pushback()?
One solution is to output values to a file, and at the end read the
file back.
This worked ok, but is there a better way?
_________________________________________________________________
Live.
More information about the R-help
mailing list