From pgilbert at bank-banque-canada.ca  Wed Oct 25 17:47:50 2006
From: pgilbert at bank-banque-canada.ca (Paul Gilbert)
Date: Wed, 25 Oct 2006 11:47:50 -0400
Subject: [Rd] as.missing
In-Reply-To: <x2wt6pe7v9.fsf@turmalin.kubism.ku.dk>
References: <453E462C.6050103@bank-banque-canada.ca>	<453E5324.60103@stats.uwo.ca>	<Pine.LNX.4.64.0610241355040.8001@tajo.ucsd.edu>
	<x2wt6pe7v9.fsf@turmalin.kubism.ku.dk>
Message-ID: <453F8726.6060409@bank-banque-canada.ca>



Peter Dalgaard wrote:

>"Charles C. Berry" <cberry at tajo.ucsd.edu> writes:
>
>  
>
>>On Tue, 24 Oct 2006, Duncan Murdoch wrote:
>>    
>>
>
>  
>
>>>with no defaults.  However, this little demo illustrates the point, I think:
>>>
>>>      
>>>
>>>>g <- function(gnodef, gdef=1) {
>>>>        
>>>>
>>>+    if (missing(gnodef)) cat('gnodef is missing\n')
>>>+    if (missing(gdef)) cat('gdef is missing\n')
>>>+    cat('gdef is ',gdef,'\n')
>>>+  }
>>>      
>>>
>>>> f <- function(fnodef, fdef) {
>>>>        
>>>>
>>>+    g(fnodef, fdef)
>>>+  }
>>>      
>>>
>>>> g()
>>>>        
>>>>
>>>gnodef is missing
>>>gdef is missing
>>>gdef is  1
>>>      
>>>
>>>> f()
>>>>        
>>>>
>>>gnodef is missing
>>>gdef is missing
>>>Error in cat("gdef is ", gdef, "\n") : argument "fdef" is missing, with
>>>no default
>>>
>>>
>>>What would be nice to be able to do is to have a simple way for f() to
>>>act just like g() does.
>>>      
>>>
>>Is this what you want?
>>
>>    
>>
>>>  f <- function(fnodef, fdef=NULL) {
>>>      
>>>
>>+ g()}
>>    
>>
>>>f()
>>>      
>>>
>>gnodef is missing
>>gdef is missing
>>gdef is  1
>>    
>>
>
>I think not. More like 
>
>  f <- function(fnodef, fdef) {
>    if(missing(fdef)) g(fnodef) else  g(fnodef, fdef) 
>  }
>
>(the generalization of which is obviously a pain...)
>
>  
>
Yes, both a pain and the resulting code can be unnecessarily difficult 
to read, compared with something like

  f <- function(fnodef, gArgs=as.missing()) {g(fnodef, gArgs) }

which would generalize cleanly.
====================================================================================

La version fran?aise suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential inform...{{dropped}}




[Rd] as.missing
Paul Gilbert