The R Project SVN R

Rev

Rev 59039 | Rev 68948 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/methods/man/getClass.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
15357 jmc 6
\name{getClass}
56186 murdoch 7
\alias{getClass}
15357 jmc 8
\alias{getClassDef}
15852 jmc 9
\title{Get Class Definition }
15357 jmc 10
\description{
11
  Get the definition of a class.
12
}
13
\usage{
25351 jmc 14
getClass(Class, .Force = FALSE, where)
48218 jmc 15
getClassDef(Class, where, package, inherits = TRUE)
15357 jmc 16
}
17
\arguments{
48218 jmc 18
  \item{Class}{ the character-string name of the class, often with a
19
      \code{"package"} attribute as noted below under \code{package}.}
16559 jmc 20
  \item{.Force}{ if \code{TRUE}, return \code{NULL} if the class is
19029 hornik 21
    undefined; otherwise, an undefined class results in an error.}
25351 jmc 22
  \item{where}{ environment from which to begin the search for the definition; by default,
23
    start at the top-level (global) environment and proceed through
24
    the search list.}
25
  \item{package}{ the name of the package asserted to hold the
48218 jmc 26
      definition.  If it is a non-empty string it is used instead of
27
      \code{where}, as the first place to look for the class.
28
      Note that the package must be loaded but need not be attached.  By
29
      default, the package attribute of the \code{Class} argument is
30
      used, if any.  There will usually be a package attribute if
31
      \code{Class} comes from \code{class(x)} for some object.
32
    }
33
  \item{inherits}{ Should the class definition be retrieved from any
34
      enclosing environment and also from the cache?  If \code{FALSE}
35
      only a definition in the environment \code{where} will be returned.
36
    }
15357 jmc 37
}
38
\details{
48218 jmc 39
  Class definitions are stored in metadata objects in a package
40
  namespace or other environment where they are defined.  When
41
  packages are loaded, the class definitions in the package are cached in an internal
42
  table.  Therefore, most calls to \code{getClassDef} will find the
43
  class in the cache or fail to find it at all, unless \code{inherits}
44
  is \code{FALSE}, in which case only the environment(s) defined by
45
  \code{package} or \code{where} are searched.
15357 jmc 46
 
48218 jmc 47
  The class cache allows for multiple definitions of the
48
  same class name in separate environments, with of course the
49
  limitation that the package attribute or package name must be
61433 ripley 50
  provided in the call to
48218 jmc 51
 
15357 jmc 52
}
53
\value{
48218 jmc 54
  The object defining the class. If the class definition is not found,
55
  \code{getClassDef} returns \code{NULL}, while \code{getClass}, which
56
  calls \code{getClassDef}, either generates an error or, if
57
  \code{.Force} is \code{TRUE}, returns a simple definition for the
58
  class.  The latter case is used internally, but is not typically
59
  sensible in user code.
60
 
61
  The non-null returned value is an object of class
62
  \code{\linkS4class{classRepresentation}}.  For all reasonable
63
  purposes, use this object only to extract information, rather than trying
64
  to modify it: Use functions such as \code{\link{setClass}} and
65
  \code{\link{setIs}} to create or modify class definitions.
15357 jmc 66
}
67
\references{
46128 jmc 68
 Chambers, John M. (2008)
69
 \emph{Software for Data Analysis: Programming with R}
70
  Springer.  (For the R version.)
15357 jmc 71
 
46128 jmc 72
 Chambers, John M. (1998)
73
 \emph{Programming with Data}
74
 Springer (For the original S4 version.)
15357 jmc 75
}
19029 hornik 76
\seealso{
77
  \link{Classes},
78
  \code{\link{setClass}},
79
  \code{\link{isClass}}.
80
}
15357 jmc 81
\examples{
82
getClass("numeric") ## a built in class
83
 
33558 maechler 84
cld <- getClass("thisIsAnUndefinedClass", .Force = TRUE)
85
cld ## a NULL prototype
86
## If you are really curious:
41508 ripley 87
utils::str(cld)
33558 maechler 88
## Whereas these generate errors:
89
try(getClass("thisIsAnUndefinedClass"))
90
try(getClassDef("thisIsAnUndefinedClass"))
15357 jmc 91
}
92
\keyword{programming}
93
\keyword{classes}