getClass               package:methods               R Documentation

_G_e_t _C_l_a_s_s _D_e_f_i_n_i_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Get the definition of a class.

_U_s_a_g_e:

     getClass(Class, .Force = FALSE, where)
     getClassDef(Class, where, package, inherits = TRUE)

_A_r_g_u_m_e_n_t_s:

   Class: the character-string name of the class, often with a
          '"package"' attribute as noted below under 'package'.

  .Force: if 'TRUE', return 'NULL' if the class is undefined;
          otherwise, an undefined class results in an error.

   where: environment from which to begin the search for the
          definition; by default, start at the top-level (global)
          environment and proceed through the search list.

 package: the name of the package asserted to hold the definition.  If
          it is a non-empty string it is used instead of 'where', as
          the first place to look for the class. Note that the package
          must be loaded but need not be attached.  By default, the
          package attribute of the 'Class' argument is used, if any. 
          There will usually be a package attribute if 'Class' comes
          from 'class(x)' for some object. 

inherits: Should the class definition be retrieved from any enclosing
          environment and also from the cache?  If 'FALSE' only a
          definition in the environment 'where' will be returned. 

_D_e_t_a_i_l_s:

     Class definitions are stored in metadata objects in a package
     namespace or other environment where they are defined.  When
     packages are loaded, the class definitions in the package are
     cached in an internal table.  Therefore, most calls to
     'getClassDef' will find the class in the cache or fail to find it
     at all, unless 'inherits' is 'FALSE', in which case only the
     environment(s) defined by 'package' or 'where' are searched.

     The class cache allows for multiple definitions of the same class
     name in separate environments, with of course the limitation that
     the package attribute or package name must be provided in the call
     to

_V_a_l_u_e:

     The object defining the class. If the class definition is not
     found, 'getClassDef' returns 'NULL', while 'getClass', which calls
     'getClassDef', either generates an error or, if '.Force' is
     'TRUE', returns a simple definition for the class.  The latter
     case is used internally, but is not typically sensible in user
     code.

     The non-null returned value is an object of class
     'classRepresentation'.  For all reasonable purposes, use this
     object only to extract information, rather than trying to modify
     it: Use functions such as 'setClass' and 'setIs' to create or
     modify class definitions.

_R_e_f_e_r_e_n_c_e_s:

     Chambers, John M. (2008) _Software for Data Analysis: Programming
     with R_ Springer.  (For the R version.)

     Chambers, John M. (1998) _Programming with Data_ Springer (For the
     original S4 version.)

_S_e_e _A_l_s_o:

     Classes, 'setClass', 'isClass'.

_E_x_a_m_p_l_e_s:

     getClass("numeric") ## a built in class

     cld <- getClass("thisIsAnUndefinedClass", .Force = TRUE)
     cld ## a NULL prototype
     ## If you are really curious:
     utils::str(cld)
     ## Whereas these generate errors:
     try(getClass("thisIsAnUndefinedClass"))
     try(getClassDef("thisIsAnUndefinedClass"))

