From pgilbert at bank-banque-canada.ca  Thu Oct 26 16:55:45 2006
From: pgilbert at bank-banque-canada.ca (Paul Gilbert)
Date: Thu, 26 Oct 2006 10:55:45 -0400
Subject: [Rd] as.missing
In-Reply-To: <971536df0610250928q615c2e4dl950e8f576c492789@mail.gmail.com>
References: <453E462C.6050103@bank-banque-canada.ca>
	<971536df0610250928q615c2e4dl950e8f576c492789@mail.gmail.com>
Message-ID: <4540CC71.1010108@bank-banque-canada.ca>

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 inform...{{dropped}}




[Rd] as.missing
Paul Gilbert