EnumValue-class         package:RDCOMClient         R Documentation

_A _c_l_a_s_s _t_o _r_e_p_r_e_s_e_n_t _a _v_a_l_u_e _o_f _a_n _e_n_u_m_e_r_a_t_e_d _c_o_n_s_t_a_n_t

_D_e_s_c_r_i_p_t_i_o_n:

     This class is intended to be used to represent a value that
     originates from an enumerated constant.  The idea is that this
     value carries around the value and the symbolic name. 
     Additionally, if an object of a enumerated type is expected, an
     integer or character string could be supplied and its value
     compared to a definition of the enumeration in R.

     It is expected that users would create new classes derived from
     this one for each new enumeration type that is encountered.  The
     definition of the enumerated constant values would be identified
     from the class name of the new class. See 'EnumValue'.

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s:

     Objects can be created by calls of the form 'new("EnumValue",
     ...)' or via the function 'EnumValue' with an instance of the
     appropriate target class specified.

_S_l_o_t_s:


     '._D_a_t_a': Object of class '"integer"', giving the value. This must
          have the associated name which makes it the symbolic
          constant.


_E_x_t_e_n_d_s:

     Class '"integer"', from data part. Class '"vector"', by class
     '"integer"'. Class '"numeric"', by class '"integer"'.

_M_e_t_h_o_d_s:


     _s_h_o_w 'signature(object = "EnumValue")':  this takes care of
          displaying the value as a regular named integer giving the
          human-readable form and its value.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang (duncan@wald.ucdavis.edu)

_S_e_e _A_l_s_o:

     'EnumValue'

_E_x_a_m_p_l_e_s:

        # Define a new Enumeration class. 
      setClass("Color", contains = "EnumValue")
            # Define the enumeration definition table.
      ColorEnum = c(Red = 1, Green = 2, Blue = 3)
      storage.mode(ColorEnum) = "integer"

       # Set the coercion methods to take a number or a string 
       # to this class type.
      setAs("character", "Color",
              function(from)
                 EnumValue(from, new("Color")))

      setAs("numeric", "Color",
              function(from)
                 EnumValue(from, new("Color")))

        # Now we can use this class.
       as(1, "Color")
       as("Red", "Color")

       as("Blue", "Color")
      
         # These should give errors, so we enclose them in a call to try. 
       try(as("Orange", "Color"))
       try(as(20, "Color"))

