From murdoch at stats.uwo.ca  Wed Sep 30 22:44:14 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 30 Sep 2009 16:44:14 -0400
Subject: [Rd] buglet in is.na?
In-Reply-To: <1254342593.29386.1337432385@webmail.messagingengine.com>
References: <1254335346.8321.1337412857@webmail.messagingengine.com>
	<4AC3A644.4050507@stats.uwo.ca>
	<1254342593.29386.1337432385@webmail.messagingengine.com>
Message-ID: <4AC3C31E.8020706@stats.uwo.ca>

On 9/30/2009 4:29 PM, Nicholas Lewin-Koh wrote:
> Hmm, Well the error message is clear, perhaps in the docs:
> x  a array, matrix, list or data.frame

But that misses the usual case, where x is a vector.
> 
> I realize that this is minor, but is the warning necessary?
> f is a function not an NA, so FALSE, as would anything else
> that is not an NA.

I think the reason for the warning is that it usually indicates that the 
programmer is confused.  Why would you pass a function to something 
looking for missing values?

> Though this may just be bad programming practice on my part,
> I have a member of an object that can be an integer, a function
> returning an integer
> or NA, perhaps it would be better to specify it as an integer, a
> function or NULL.

Or you could use identical(x, NA) (but watch out for the different 
flavours of NA, which are not identical).  But aren't you going to be in 
trouble if someone passes in a vector of numbers, some of which are NA 
and some of which are not?

Duncan Murdoch

> 
> Nicholas
> 
> 
> On Wed, 30 Sep 2009 14:41 -0400, "Duncan Murdoch" <murdoch at stats.uwo.ca>
> wrote:
>> On 9/30/2009 2:29 PM, Nicholas Lewin-Koh wrote:
>> > Hi
>> > the following example I think demonstrates the inconsistency
>> >> f<-function(x) x
>> >> length(f)
>> > [1] 1
>> >> is.na(f)
>> > [1] FALSE
>> > Warning message:
>> > In is.na(f) : is.na() applied to non-(list or vector) of type 'closure'
>> 
>> As the error message says, closures aren't vectors.  However, they do 
>> have a length.
>> 
>> > The documentation states:
>> > Arguments
>> > x       an R object to be tested.
>> > value   a suitable index vector for use with x.
>> > 
>> > And nowhere in the details was it implied (to me anyway) that x could
>> > not be a function
>> > or anything else in R for that matter. Did I miss something?
>> 
>> This might be an omission from the docs, but it did say pretty clearly 
>> in the warning message that x needs to be a vector.  So it's not a bug.
>> 
>> The source for the docs is in
>> 
>> https://svn.r-project.org/R/trunk/src/library/base/man/NA.rd
>> 
>> If you can think of a way to make it clearer, and you think this is the 
>> sort of error someone would not understand given the warning message, 
>> please submit a patch.
>> 
>> Duncan Murdoch



[Rd] buglet in is.na?
Duncan Murdoch