[R] Nested functions

John Wiedenhoeft wiedenhoeft at gmx.net
Tue Jul 18 10:25:49 CEST 2006

Am Montag, den 17.07.2006, 19:42 -0400 schrieb jim holtman:
> You were down at least 5300 levels in subroutine calls.  Here is the
> first couple of lines from 'traceback()':
> 5363: vavb(a, b, n, v, x)
> 5316: vavb(a, b, n, v, x) 

> The other thing is that there is no 'x' defined in the function;
> antiphonar <- function(v)
> {
>        a <- 1;
>        b <- 2;
>        n <- length(v);
>        alessn(a, b, n, v, x);
> }
> and this is the initial call to the rest of the functions.

Ooops... normally I don't program THAT bad ... ;-)

> What is the problem you are trying to solve? 

I'm analyzing a 16th century music manuscript. There is no rhythm
notated there, but I can to a certain degree restore it by finding
self-similarities in the melodic structure. The vector v is an ordered
list of intervals. I could find them by hand, but this takes time and
things are easily missed. Besides, for a 200 pages manuscript coding the
vectors takes long, but finding similarities by hand takes
endless... :-(

The problem remains. I'm not sure I did completely understand the way R
works. My plan was to jump out of one function to another. I think what
R does is assigning a function's return value to an internal variable
and tries to evaluate another function WITHIN a calling function, which
of course leads to deep nesting and a bunch of internal variables. Too
bad there is no "goto" statement in R... Isn't there a way to make R
"forget" that it just evaluated e.g. alessn the moment it calles vavb?
That algorithm itself isn't that hard. In the end it's just a decision
diagram of the form "if THIS, goto THIS knot, otherwise goto THAT knot".
Each knot has only one arrow pointing away from it, but sometimes more
than one pointing toward it. I could send the diagram as an attachement, if you like.


P.S.: Please keep messages on the list. Thank you!

More information about the R-help mailing list