[R] Nested functions

John Wiedenhoeft wiedenhoeft at gmx.net
Tue Jul 18 00:29:40 CEST 2006


Thanks for your response!

Am Montag, den 17.07.2006, 17:36 -0400 schrieb jim holtman:
> It would help if you could provide the calling script and the data
> that you are using.  

The code I sent is included in .Rprofile. One of my data vectors would
be v = c(1, 1, 1, 5, 6, 1, 1, 1, 1, 6, 1, 1, 6, 6, 6, 6, 2, 6, 6, 1, 5,
5, 2, 1, 1, 1, 5, 6, 1, 2, 1, 1, 6, 5, 1, 1, 6, 6, 6, 6, 1, 6, 1, 2, 6,
6, 1, 5, 1, 2, 1, 6, 1, 1, 5, 6, 6, 1, 1, 6, 5, 1, 6, 6, 1, 5, 4, 1, 6,
6, 4, 6, 5, 1, 5, 4, 6, 5, 1, 5, 6, 1, 1, 1, 5, 6, 1, 1, 6) for example.
After defining it, I call antiphonar(v). This returns 53 entries, but as
I said, this is quite too few, as the program breaks before a=3.

> It sounds like your algorithm is not correct because it is recursing
> so deep.  You have recursive calls, so you are not terminating your
> search correctly.

Wouldn't it terminate on some call of alessn for a>=n?

> Your functions are not returning values.  

Should they? They just perform tests on v. As I said, I'm not an expert
programmer. I think in C++ there was something like a void type for
functions, i.e. functions that only perform operations on variables
without having a value for themselves.

> Put some debug print statements to see what is happening in your code.
> debug(antiphonar)
> antiphonar(v)
debugging in: antiphonar(v)
debug: {
    a <- 1
    b <- 2
    n <- length(v)
    alessn(a, b, n, v, x)
}
Browse[1]> n
debug: a <- 1
Browse[1]> n
debug: b <- 2
Browse[1]> n
debug: n <- length(v)
Browse[1]> n
debug: alessn(a, b, n, v, x)
Browse[1]> n
Fehler: Auswertung zu tief verschachtelt: unendliche Rekursion /
options(expressions=)?

Not very helpful :-(

Cheers,
John



More information about the R-help mailing list