[Rd] Questions about imports to a namespace

Simon Knapp sleepingwell at gmail.com
Thu Jul 5 04:04:20 CEST 2012


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



More information about the R-devel mailing list