[R] is.na for S4 object

Martin Morgan mtmorgan at fredhutch.org
Thu Jun 4 19:33:37 CEST 2015


On 06/04/2015 10:08 AM, cgenolin wrote:
> Hi the list,
>
> I have a variable y that is either NA or some S4 object. I would like to
> know in which case I am, but it seems taht is.na does not work with S4
> object, I get a warnings:
>
> --- 8< ------------
> setClass("myClass",slots=c(x="numeric"))
> if(runif(1)>0.5){a <- new("myClass")}else{a <- NA}
> is.na(a)
> --- 8< ------------
>
> Any solution?

getGeneric("is.na")

shows that it's an S4 generic, so implement a method

setMethod("is.na", "myClass", function(x) FALSE)

Martin

> Thanks
>
> Christophe
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/is-na-for-S4-object-tp4708201.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>


-- 
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the R-help mailing list