Re: [Rd] R windows crash (PR#9426)

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Thu 21 Dec 2006 - 14:37:18 GMT

Luke Tierney wrote:
> On Thu, 21 Dec 2006, P.Dalgaard@biostat.ku.dk wrote:
>
>
>> Prof Brian Ripley wrote:
>>
>>> On Thu, 21 Dec 2006, Peter Dalgaard wrote:
>>>
>>> [...]
>>>
>>>
>>>
>>>> This seems reproducible on Linux, except that it goes into an infinite
>>>> loop. The lm call seems to be the real culprit:
>>>>
>>>>
>>>>
>>>>> testfun <- function(aa=aa) return(aa)
>>>>> testfun()
>>>>>
>>>>>
>>>> Error in testfun() : recursive default argument reference
>>>>
>>>>
>>>>> testfun <- function(aa=aa) lm(x~y,data=aa)
>>>>> testfun()
>>>>>
>>>>>
>>>> (*poof*)
>>>>
>>>>
>>> The difference is in argument evaluation between closures and internal
>>> functions (c() in my example, return() in yours).
>>>
>>>
>> Er? I'd rather say that the issue is in the semantics of missing():
>>
>>
>>> f <- function(x) missing(x)
>>> testfun <- function(aa=aa) f(aa)
>>> testfun()
>>>
>> Error: segfault from C stack overflow
>>
>> which is a bit nasty. AFAICS the thing is that the logic for detection
>> of recursive arguments works by forcing promises (if you at some point
>> need the result of the same promise you are forcing, you know that
>> something is wrong), but missing() tries hard not to force promises. We
>> already have the following anomaly,
>>
>>
>>> g <- function(v) missing(v)
>>> f <- function(v) g(v)
>>> f()
>>>
>> [1] TRUE
>>
>>> f <- function(v=!h, h=!v) g(v)
>>> f()
>>>
>> [1] FALSE
>>
>>> f <- function(v=!h, h) g(v)
>>> f()
>>>
>> [1] FALSE
>>
>> so the fix could be to realize that we cannot detect missingness in a
>> perfectly reliable way and just pretend that arguments are always
>> non-missing when they have a default.
>>
>
> We could also mark the promise created for default arguments so it can
> be identified as such and use that info in missing(). Probably worth
> deciding what the intended semantics are here and then figuring out
> the implementation.
>
>
Yes, always a good idea...

Just to be precise: The current semantics seems to be that we stop and declare missingness to be FALSE if any sort of computation is involved in the default:

> f <- function(v=h,h=v) g(v)
> f()
Error: segfault from C stack overflow

but

> f <- function(v=(v)) g(v)
> f()

[1] FALSE

-- 
   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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Dec 22 12:41:52 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 Fri 22 Dec 2006 - 04:31:02 GMT.

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