From P.Dalgaard at biostat.ku.dk  Wed Mar 26 17:28:58 2008
From: P.Dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Wed, 26 Mar 2008 17:28:58 +0100
Subject: [Rd] S4 slot with NA default
In-Reply-To: <00025495-F390-4A46-885E-5FAD2B4B66A7@noc.soton.ac.uk>
References: <00025495-F390-4A46-885E-5FAD2B4B66A7@noc.soton.ac.uk>
Message-ID: <47EA79CA.1030208@biostat.ku.dk>

Robin Hankin wrote:
> Hi
>
> How do I specify an S4 class with a slot that is potentially numeric,  
> but NA
> by default?  I   want the slot to be NA until I calculate its value
>   (an expensive operation, not needed for all applications).   When  
> its value is
> known, I  will create a new object with the correct value inserted in  
> the slot.
>
> I want "NA" to signify "not known".
>
> My attempt fails because NA is not numeric:
>
>  >  
> setClass 
> ("foo",representation=representation(x="numeric"),prototype=list(x=NA))
> Error in makePrototypeFromClassDef(properties, ClassDef, immediate,  
> where) :
>    in making the prototype for class "foo" elements of the prototype  
> failed to match the corresponding slot class: x (class ?numeric? )
>  >
>
> (the real application has other slots too).   I can
> use "NaN", which is numeric:
>
>  >  
> setClass 
> ("foo",representation=representation(x="numeric"),prototype=list(x=NaN))
> [1] "foo"
>  >
>
> But this is not the correct sense: to me "NaN" means "not a number"  
> and I want
> the sense to be "not available".
>
>
>
> Any advice?
>
>
>
>   
How about NA_real_ or NA_integer_?


-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] S4 slot with NA default
Peter Dalgaard