[R] Enumeration in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Jul 7 02:44:25 CEST 2004


Paul Roebuck <roebuck at odin.mdacc.tmc.edu> writes:

> I want the equivalent of this 'C' declaration.
>     enum StoplightColor {
>         green = 3,
>         yellow = 5,
>         red = 7
>     };
> 
> This mostly works except the validity checking doesn't
> seem to occur automatically. What didn't I do to enable
> it?

I think you *dis*abled it by specifying an initializer which doesn't
check the validity:

> initialize.stoplightColor <- function(.Object, value) {
>     .Object at value <- as.integer(value)
>     .Object
> }

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list