[Rd] as.missing

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 27 03:30:07 CEST 2006


This is what I get:

> as.missing <- force
> f <- function(y, x=1) {cat(missing(x)) ; x}
> g <- function(x=as.missing()) f(3,x)
> g()
FALSEError in as.missing() : argument "x" is missing, with no default
> traceback()
3: as.missing()
2: f(3, x)
1: g()
> traceback()
3: as.missing()
2: f(3, x)
1: g()

so g did in fact pass the missing to f and it was only f that blew up,
not g.  If that's not what you want please explain.


On 10/26/06, Paul Gilbert <pgilbert at bank-banque-canada.ca> wrote:
> I don't see how this solves the problem.
>
>  > as.missing <- force
>  >  f <- function(y, x=1) {cat(missing(x)) ; x}
>  > g <- function(x) f(3,x)
>  > g(1)
> FALSE[1] 1
>  > g()
> TRUEError in f(3, x) : argument "x" is missing, with no default
>
> I think I still have to put all the logic in g() to figure out if the
> argument is missing, rather than the nice clean solution of just passing
> the argument along to the function it calls. How does this differ from
> the problem I already have when I  specifying the argument as NULL and
> do all the checking in  g?
>
> Paul
>
> Gabor Grothendieck wrote:
>
> > You can do it like this:
> >
> >> as.missing <- force
> >> g <- function(x = as.missing()) missing(x)
> >> g(3)
> >
> > [1] FALSE
> >
> >> g()
> >
> > [1] TRUE
> >
> > On 10/24/06, Paul Gilbert <pgilbert at bank-banque-canada.ca> wrote:
> >
> >> (I'm not sure if this is a request for a feature, or another instance
> >> where a feature has eluded me for many years.)
> >>
> >> Often I have a function which calls other functions, and may often use
> >> the default arguments to those functions, but needs the capability to
> >> pass along non-default choices. I usually do this with some variation on
> >>
> >> foo <- function(x, foo2Args=NULL or a list(foo2defaults),
> >>                    foo3Args=NULL or a list(foo3defaults))
> >>
> >> and then have logic to check for NULL, or use the list in combination
> >> with do.call.  It is also possible to do this with ..., but it always
> >> seems a bit dangerous passing all the unnamed arguments along to all the
> >> functions being called, especially when I always seem to be calling
> >> functions that have similar arguments (maxit, eps, start, frequency,
> >> etc).
> >>
> >> It is a situation I have learned to live with, but one of my
> >> co-maintainers just pointed out to me that there should be a good way to
> >> do this in R.  Perhaps there is something else I have missed all these
> >> years?  Is there a way to do this cleanly? It would be nice to have
> >> something like
> >>
> >> foo <- function(x, foo2Args=as.missing(),  foo3Args=as.missing())
> >>
> >> then the call to foo2 and foo3 could specify  foo2Args and foo3Args, but
> >> these would get treated as if they were missing, unless they are given
> >> other values.
> >>
> >> Paul Gilbert
> >
> ====================================================================================
>
> La version française suit le texte anglais.
>
> ------------------------------------------------------------------------------------
>
> This email may contain privileged and/or confidential info...{{dropped}}




More information about the R-devel mailing list