[R] Dealing with an argument missing in ...

David Winsemius dwinsemius at comcast.net
Wed Mar 10 13:12:34 CET 2010


On Mar 10, 2010, at 5:43 AM, Achim Zeileis wrote:

> On Wed, 10 Mar 2010, Christophe Genolini wrote:
>
>> Hi the list
>>
>> I define a S3 function that can have a various number of argument  
>> using '...'
>> When some arguments are missing, I would like to give them some  
>> default value:
>>
>> func.numeric <- function(x,...){
>> if(missing(y)){y<-3}
>> }
>>
>> But it does not works...
>>
>> I precise that I can not put 'y' explicitly in the argument list  
>> since func is an S3 function, I cannot change its arguments.
>> Any suggestions?
>
> If the generic func() has arguments "x" and "...", then you can  
> easily define a method func.numeric(x, y, ...). Methods need to  
> implement all arguments of a generic (including ...) but may add  
> additional argument.
>

I am assuming that one could also use the default assignment to y in  
the argument list?

func.numeric(x, y=3, ...)

> hth,
> Z
>
>> Thanks
>> Christophe
>


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list