From sleepingwell at gmail.com  Thu Jul  5 04:04:20 2012
From: sleepingwell at gmail.com (Simon Knapp)
Date: Thu, 5 Jul 2012 12:04:20 +1000
Subject: [Rd] Questions about imports to a namespace
In-Reply-To: <4FF2CC69.9040209@gmail.com>
References: <CAA+5f=3wxx+A3yXuuTYD_6YkfPZBuaPiW1mCKfU3hQAJD=B2GA@mail.gmail.com>
	<4FF2CC69.9040209@gmail.com>
Message-ID: <CAA+5f=3mfe+DmRfDHhRz=nbLXb9MN4GL2H=Wf64tDrQkpnSOEw@mail.gmail.com>

Thanks Duncan.

wrt question 4,  I see your point about passing arguments. Maybe R
could do with a value "MISSING" or "DEFAULT" for this and other
similar purposes. The test for is.na can be frustrating when the
argument (when not NA) has length greater than 1 as it produces a
warning. But in some situations NULL won't suffice. Consider this
contrived (and simplified) example to demonstrate the sort of
situation I mean (contrived in that test for NA is not required for
the case of setdiff).

mapply(function(x, y, z) {
    if(!is.na(y)) x <- setdiff(x, y)
    z[x]
}, x, c(NA, x[-length(x)]), MoreArgs = list(z), SIMPLIFY=F)

where x is a list (and z a vector). One should really make the test
"if(length(y) > 1 && !is.na(y))"... but is there a nicer way?

Thanks again,
Simion



On Tue, Jul 3, 2012 at 8:41 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 12-07-02 10:53 PM, Simon Knapp wrote:

<snip>

>> 4) Is it better to check for arguments that are missing, or use a
>> default value of, say, NA; i.e. is missing(arg) preferable to
>> is.na(arg)?
>
>
> That depends.  It's easier to set an argument to a special value in a call
> from another function than it is to conditionally set it to be missing, but
> there are only a couple of general purpose choices for "missing" values:  NA
> and NULL, and you might want a user to be able to specify those.  (You can
> also use negative values for counts, etc., in particular contexts.)

<snip>

> Duncan Murdoch



[Rd] Questions about imports to a namespace
Simon Knapp