MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #9426] R windows crash #3015

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

From: robert.denham@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::> Full_Name: Robert Denham Version: R-2.4.1 OS: Windows Xp Submission from: (NULL) (61.88.57.1)

R gui exits without warning when I run a function which has an argument with a default that is not found.

This was a result of an error in a function I wrote, but I thought that it should exit more gracefully than it does. Here is an example:

testfun <- function(aa=aa) { aa <- lm(∼x,data=aa) return(aa) }

testfun() #R then exits.

Note that

testfun <- function(aa=bb) { aa <- lm(∼x,data=aa) return(aa) }

works as it should, giving "object bb not found".


METADATA

MichaelChirico commented 4 years ago

From: Peter Dalgaard <P.Dalgaard@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::>> Luke Tierney wrote:

On Thu, 21 Dec 2006, P.Dalgaard@<::CENSORED -- SEE ORIGINAL ON BUGZILLA::> 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 <CENSORING FROM DETECTED PHONE NUMBER ONWARDS; SEE BUGZILLA>


METADATA