[R] if ( expr )

Gregory Wall gdwall at ucdavis.edu
Tue Nov 20 10:03:53 CET 2007


Hello,

I've searched the list but haven't found anything really applicable to my
question. Any advice would be super.

I'm working on a snippet of R code and I have a function with a prototype
like this:

foo <- function( x, ... ){
     if( is.na(x)[1] ) {etc...}
}

Where x is typically a vector of bools. 

At times, however, x can be NA, and yet at other super rare times x can be
the result of this type of comparison:

 c(4,5,13,2,3,4,5,7) == numeric(0) 

which produces logical(0). When this is the case, if( is.na(x)[1] ) isn't
happy. 

I'm trying to create a condition to my "if" statement inside foo that only
is true when x is NA but that doesn't die when its a logical(0). 

Any suggestions on how best to approach this? 

As always, thanks a bunch,

Greg



More information about the R-help mailing list