Bug 16107 - is.na throws warning for NULL
Summary: is.na throws warning for NULL
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-12-13 17:36 UTC by Ryan Grannell1
Modified: 2018-01-25 11:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Grannell1 2014-12-13 17:36:04 UTC
is.na works returns logical(0) for empty lists and empty typed vectors, as you would expect, but it throws also a warning for NULL values, stating it is a non-vector type. NULL is the empty pairlist, so it seems it should just return logical(0) without the warning.

> is.na(NULL)
logical(0)
Warning message:
In is.na(NULL) : is.na() applied to non-(list or vector) of type 'NULL'
> 

I know pairlists are deprecated from external use, but this behaviour is a bit inconsistant given that is.na works foine for non-empty pairlists. I would imagine it should either throw an error for both examples, or neither.

> is.na(pairlist(1, 2))
[1] FALSE FALSE
Comment 1 Martin Maechler 2018-01-23 21:48:06 UTC
(In reply to Ryan Grannell1 from comment #0)
> is.na works returns logical(0) for empty lists and empty typed vectors, as
> you would expect, but it throws also a warning for NULL values, stating it
> is a non-vector type. NULL is the empty pairlist, so it seems it should just
> return logical(0) without the warning.
> 
> > is.na(NULL)
> logical(0)
> Warning message:
> In is.na(NULL) : is.na() applied to non-(list or vector) of type 'NULL'
> > 
> 
> I know pairlists are deprecated from external use, but this behaviour is a
> bit inconsistant given that is.na works foine for non-empty pairlists. I
> would imagine it should either throw an error for both examples, or neither.
> 
> > is.na(pairlist(1, 2))
> [1] FALSE FALSE

Even more, this behaviour is not followed by similar functions such as  
is.nan(), is.finite(), ..  they return integer(0) without a warning.

Even though the current behavior is documented on the help page, it looks to me as a coding oversight, as e.g., is.nan() explicitly covers NULL.
I'm proposing to change this....  only for R-devel (as it is documented, it is not a "bad" bug but rather infelicitous).
Comment 2 Martin Maechler 2018-01-25 11:54:43 UTC
Ok, I've implemented my proposal -- for R-devel, in svn rev 74157