[R] Dealing with an argument missing in ...
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Wed Mar 10 11:43:50 CET 2010
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.
hth,
Z
> Thanks
> Christophe
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list