[R] is.na behavior
Greg Snow
538280 at gmail.com
Thu Nov 19 16:56:55 CET 2015
Richard,
I think the reason that this gives the warning is for the rest of us
who don't think about asking about missing values in non-data objects.
I could imagine someone choosing a poor name for a variable and doing
something like:
mean <- mean(x)
is.na(mean)
which would then tell them whether the mean of x was missing (due to
missing in x). Later in a new session they may try something similar
but use a different variable name in the 1st line (e.g. Mean) but
accidentally still ask for is.na(mean). So, is.na would find the mean
function and report that it is not missing, but the warning would let
the user know that what was checked for missingness was not what they
had intended.
I could also imagine meaning to write something like:
is.na(mean(x))
but accidentially writing
is.na(mean)
instead and I would appreciate the warning that would send me back to
review my code and find the mistake.
On Wed, Nov 18, 2015 at 8:03 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
> David,
>
> Your answer begs the question.
> What is the problem with non-(list or vector) of type language.
> To my eye both expression(abcd) and call("mean") look like they have
> non-missing values, hence I anticipated that they are not NA, and therefore
> that is.na() would return FALSE without a warning.
>
> On the html email, I turned that off years ago. It looks like gmail
> (who handles
> my university's email accounts) turned it back on. I just turned it off again.
> I too find it very annoying to have to revisit setting changes that I
> didn't make.
> Thank you for letting me know.
>
> Rich
>
>
> On Wed, Nov 18, 2015 at 9:36 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>>
>>> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
>>>
>>> What is the rationale for the following warning in R-3.2.2?
>>>
>>>> is.na(expression(abcd))
>>> [1] FALSE
>>> Warning message:
>>> In is.na(expression(abcd)) :
>>> is.na() applied to non-(list or vector) of type ‘expression’
>>
>> Well, the R interpreter does think that this is not a list:
>>
>>> is.list(expression(abcd))
>> [1] FALSE
>>
>>
>>> methods(is.na)
>> [1] is.na,abIndex-method is.na,denseMatrix-method
>> [3] is.na,indMatrix-method is.na,nsparseMatrix-method
>> [5] is.na,nsparseVector-method is.na,sparseMatrix-method
>> [7] is.na,sparseVector-method is.na.coxph.penalty*
>> [9] is.na.data.frame is.na.numeric_version
>> [11] is.na.POSIXlt is.na.raster*
>> [13] is.na.ratetable* is.na.Surv
>>
>>
>> So the rationale is probably the same as the rationale for this warning:
>>
>>> is.na(call("mean", 1:4))
>> [1] FALSE FALSE
>> Warning message:
>> In is.na(call("mean", 1:4)) :
>> is.na() applied to non-(list or vector) of type ‘language'
>>
>>> [[alternative HTML version deleted]]
>>
>>
>> I’m somewhat puzzled at your use of HTML for an Rhelp posting. I thought you were a longtime R user?
>>
>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com
More information about the R-help
mailing list