Peter Dalgaard wrote:

>"Charles C. Berry" <[EMAIL PROTECTED]> 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}}

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to