[Rd] as.missing

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Oct 24 23:12:10 CEST 2006


"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...)



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-devel mailing list