Stavros Macrakis
2009-Mar-09 19:13 UTC
[Rd] E`<`<rrors in recursive default argument references
Tested in: R version 2.8.1 (2008-12-22) / Windows Recursive default argument references normally give nice clear errors. In the first set of examples, you get the error: Error in ... : promise already under evaluation: recursive default argument reference or earlier problems? (function(a = a) a ) () (function(a = a) c(a) ) () (function(a = a) a[1] ) () (function(a = a) a[[1]] ) () (function(a = a) a$x ) () (function(a = a) mean(a) ) () (function(a = a) sort(a) ) () (function(a = a) as.list(a) ) () But in the following examples, R seems not to detect the 'promise already under evaluation' condition and instead gets a stack overflow, with the error message: Error: C stack usage is too close to the limit (function(a = a) (a) ) () (function(a = a) -a ) () (function(a = a) var(a) ) () (function(a = a) sum(a) ) () (function(a = a) is.vector(a) ) () (function(a = a) as.numeric(a) ) () I don't understand why the two sets of examples behave differently. -s
Wacek Kusnierczyk
2009-Mar-09 21:40 UTC
[Rd] E`<`<rrors in recursive default argument references
Stavros Macrakis wrote:> Tested in: R version 2.8.1 (2008-12-22) / Windows > > Recursive default argument references normally give nice clear errors. > In the first set of examples, you get the error: > > Error in ... : > promise already under evaluation: recursive default argument > reference or earlier problems? > > (function(a = a) a ) () > (function(a = a) c(a) ) () > (function(a = a) a[1] ) () > (function(a = a) a[[1]] ) () > (function(a = a) a$x ) () > (function(a = a) mean(a) ) () > (function(a = a) sort(a) ) () > (function(a = a) as.list(a) ) () > > But in the following examples, R seems not to detect the 'promise > already under evaluation' condition and instead gets a stack overflow, > with the error message: > > Error: C stack usage is too close to the limit >when i run these examples, the execution seems to get into an endless loop with no error messages whatsoever. how much time does it take before you get the error? (using r 2.8.0 and also the latest r-devel). vQ> (function(a = a) (a) ) () > (function(a = a) -a ) () >btw. ?'-' talks about '-' as a *binary* operator, but the only example given there which uses '-' uses it as a *unary* operator. since '-'() complains that '-' takes 1 or 2 arguments, it might be a good idea to acknowledge it in the man page.> (function(a = a) var(a) ) () > (function(a = a) sum(a) ) () > (function(a = a) is.vector(a) ) () > (function(a = a) as.numeric(a) ) () > > I don't understand why the two sets of examples behave differently. >a bug in excel? vQ
Stavros Macrakis
2009-Mar-09 22:31 UTC
[Rd] E`<`<rrors in recursive default argument references
On Mon, Mar 9, 2009 at 5:40 PM, Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:> Stavros Macrakis wrote: >> Tested in: R version 2.8.1 (2008-12-22) / Windows> when i run these examples, the execution seems to get into an endless > loop with no error messages whatsoever. ?how much time does it take > before you get the error? ?(using r 2.8.0 and also the latest r-devel).In 2.8.1/Windows (32 bit), they return immediately, though the stack-overflow case is about 13x slower.> system.time(for (i in 1:100) {trySilent((function(a=a)(a))())})user system elapsed 0.67 0.00 0.67> system.time(for (i in 1:100) {trySilent((function(a=a)as.POSIXct(a))())})user system elapsed 0.05 0.00 0.05 Are you running under 64 bits? How long does a vanilla infinite recursion take to fail on your machine? I get:> system.time(for (i in 1:100) trySilent({fff <- function()fff(); fff()}))user system elapsed 0.27 0.00 0.26 -s
Peter Dalgaard
2009-Mar-09 23:21 UTC
[Rd] E`<`<rrors in recursive default argument references
Stavros Macrakis wrote:> Tested in: R version 2.8.1 (2008-12-22) / Windows > > Recursive default argument references normally give nice clear errors. > In the first set of examples, you get the error: > > Error in ... : > promise already under evaluation: recursive default argument > reference or earlier problems? > > (function(a = a) a ) () > (function(a = a) c(a) ) () > (function(a = a) a[1] ) () > (function(a = a) a[[1]] ) () > (function(a = a) a$x ) () > (function(a = a) mean(a) ) () > (function(a = a) sort(a) ) () > (function(a = a) as.list(a) ) () > > But in the following examples, R seems not to detect the 'promise > already under evaluation' condition and instead gets a stack overflow, > with the error message: > > Error: C stack usage is too close to the limit > > (function(a = a) (a) ) () > (function(a = a) -a ) () > (function(a = a) var(a) ) () > (function(a = a) sum(a) ) () > (function(a = a) is.vector(a) ) () > (function(a = a) as.numeric(a) ) () > > I don't understand why the two sets of examples behave differently.Ouch!!! This shouldn't happen, I'm pretty sure. In particular not the apparently unstoppable loop under Linux. Thanks for pointing it out. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907