isS4                  package:base                  R Documentation

_T_e_s_t _f_o_r _a_n _S_4 _o_b_j_e_c_t

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

     Tests whether the object is an instance of an S4 class.

_U_s_a_g_e:

     isS4(object)

     asS4(object, flag = TRUE, complete = TRUE)

_A_r_g_u_m_e_n_t_s:

  object: Any R object. 

    flag: A single logical value; not 'NA', whether to turn the S4
          object flag on or off.

complete: How to complete the transformation to/from S4.  Only
          currently used when 'flag' is 'FALSE'.  If '1', the object
          must convert to a valid S3 object, or an error results.  If
          '2', a non-valid S3 object is left alone, silently.  If '0',
          no conversion is made other than setting the internal bit
          (used internally but not recommended, since it can result in
          an invalid object). 

_D_e_t_a_i_l_s:

     Note that 'isS4' does not rely on the 'methods' package, so in
     particular it can be used to detect the need to 'require' that
     package.  (But 'asS4' does depend on 'methods'.)

     Note that the S4 methods for primitive functions do not apply to
     S3 classes and that the methods for basic classes, such as the
     vector types, are sealed. To apply S4 methods reliably to an S3
     object, define an S4 class that extends the S3 class
     ('setOldClass').

     When 'asS4' is called with 'flag == FALSE', the value of
     'complete' controls whether an attempt is made to transform
     'object' into a valid object of the implied S3 class.  If so, then
     an object from an S4 class extending an S3 class will be
     transformed into an S3 object with the corresponding S3 class (see
     'S3Part').  This includes classes extending the pseudo-classes
     'array' and 'matrix': such objects will have their class attribute
     set to 'NULL'.

_V_a_l_u_e:

     'isS4' always returns 'TRUE' or 'FALSE' according to whether the
     internal flag marking an S4 object has been turned on for this
     object.

     'asS4' will turn this flag on or off, according to argument
     'flag', and in the latter case complete the conversion as
     described under argument 'complete'. Note that with 'flag FALSE',
     an S4 object will _not_ but turned into an S3 object unless there
     is a valid conversion; that is, an object of type other than
     '"S4"' for which the S4 object is an extension, unless argument
     'complete' is '0'.

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

     'is.object' for a more general test; Methods for general
     information on S4.

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

     isS4(pi) # FALSE
     isS4(getClass("MethodDefinition")) # TRUE

