From p.dalgaard at biostat.ku.dk  Tue Oct 24 23:12:10 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 24 Oct 2006 23:12:10 +0200
Subject: [Rd] as.missing
In-Reply-To: <Pine.LNX.4.64.0610241355040.8001@tajo.ucsd.edu>
References: <453E462C.6050103@bank-banque-canada.ca>
	<453E5324.60103@stats.uwo.ca>
	<Pine.LNX.4.64.0610241355040.8001@tajo.ucsd.edu>
Message-ID: <x2wt6pe7v9.fsf@turmalin.kubism.ku.dk>

"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




[Rd] as.missing
Peter Dalgaard