Re: [R] Nested functions

From: John Wiedenhoeft <wiedenhoeft_at_gmx.net>
Date: Tue 18 Jul 2006 - 08:29:40 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 18 08:34:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 18 Jul 2006 - 10:22:55 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.