The R Project SVN R

Rev

Rev 26000 | Rev 31085 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26000 Rev 26365
Line 10... Line 10...
10
\description{
10
\description{
11
  Functions to create (\code{setClass}) and manipulate class definitions.
11
  Functions to create (\code{setClass}) and manipulate class definitions.
12
}
12
}
13
\usage{
13
\usage{
14
setClass(Class, representation, prototype, contains=character(),
14
setClass(Class, representation, prototype, contains=character(),
15
         validity, access, where=1, version=FALSE, sealed, package)
15
         validity, access, where, version, sealed, package)
16
 
16
 
17
removeClass(Class, where)
17
removeClass(Class, where)
18
 
18
 
19
isClass(Class, formal=TRUE, where)
19
isClass(Class, formal=TRUE, where)
20
 
20
 
Line 38... Line 38...
38
    data for the slots specified in the representation. }
38
    data for the slots specified in the representation. }
39
  \item{contains}{ what classes does this class extend?  (These are
39
  \item{contains}{ what classes does this class extend?  (These are
40
    called \emph{superclasses} in some languages.)  When these classes
40
    called \emph{superclasses} in some languages.)  When these classes
41
    have slots, all their slots will be contained in the new class as
41
    have slots, all their slots will be contained in the new class as
42
    well. }
42
    well. }
43
  \item{where}{ For \code{setClass}, what environment to use to store or remove the
43
  \item{where}{ For \code{setClass} and \code{removeClass}, the
-
 
44
    environment in which to store or remove the
44
    definition (as metadata).  Defaults to the top-level environment,
45
    definition.  Defaults to the top-level environment of the calling function
45
    the global environment for ordinary computations, but the
46
    (the global environment for ordinary computations, but the
46
    environment or namespace of a package when loading that package.
47
    environment or namespace of a package when loading that package).
47
 
48
 
48
    For other functions, \code{where} defines where to do the search
49
    For other functions, \code{where} defines where to do the search
49
    for the class definition, and the default is to search the visible
50
    for the class definition, and the default is to search from the top-level
50
    environments or namespace.
51
    environment or namespace of the caller to this function.
51
    }
52
    }
52
  \item{unique}{if \code{findClass} expects a unique location for the
53
  \item{unique}{if \code{findClass} expects a unique location for the
53
    class, \code{unique} is a character string explaining the purpose
54
    class, \code{unique} is a character string explaining the purpose
54
    of the search (and is used in warning and error messages).  By
55
    of the search (and is used in warning and error messages).  By
55
    default, multiple locations are possible and the function always
56
    default, multiple locations are possible and the function always
Line 58... Line 59...
58
  \item{inherits}{in a call to \code{getClasses}, should the value
59
  \item{inherits}{in a call to \code{getClasses}, should the value
59
    returned include all parent environments of \code{where}, or that
60
    returned include all parent environments of \code{where}, or that
60
    environment only?  Defaults to \code{TRUE} if \code{where} is
61
    environment only?  Defaults to \code{TRUE} if \code{where} is
61
    omitted, and to \code{FALSE} otherwise.
62
    omitted, and to \code{FALSE} otherwise.
62
    }
63
    }
63
  \item{validity, access, version}{ Control arguments included for
64
  \item{validity}{ if supplied, should be a validity-checking method
-
 
65
  for objects from this class (a function that returns \code{TRUE} if
-
 
66
  its argument is a valid object of this class and one or more strings
-
 
67
  describing the failures otherwise).  See \code{\link{validObject}}
-
 
68
  for details.  }
-
 
69
\item{access}{Access list for the class.  Saved in the definition, but
-
 
70
  not currently used.}
-
 
71
\item{version}{A version indicator for this definition. Saved in the
64
    compatibility with the S-Plus API, but not currently used.  }
72
    definition, but not currently used.}
65
  \item{sealed}{ If \code{TRUE}, the class definition will be sealed,
73
  \item{sealed}{ If \code{TRUE}, the class definition will be sealed,
66
    so that another call to \code{setClass} will fail on this class name.
74
    so that another call to \code{setClass} will fail on this class name.
67
    }
75
    }
68
  \item{package}{ An optional package name for the class.  By default
76
  \item{package}{ An optional package name for the class.  By default
69
  (and usually) the package where the class definition is assigned
77
  (and usually) the package where the class definition is assigned
Line 95... Line 103...
95
      slots), and methods may be defined including the class name in the
103
      slots), and methods may be defined including the class name in the
96
      signature (see \code{\link{setMethod}}).
104
      signature (see \code{\link{setMethod}}).
97
    }
105
    }
98
 
106
 
99
    \item{\code{removeClass}:}{ 
107
    \item{\code{removeClass}:}{ 
100
      Remove the definition of this class.  Calling this \emph{always}
108
      Remove the definition of this class, from the environment
101
      resets the version of the class cached for the session.  If
109
      \code{where} if this argument is supplied; if not,
102
      \code{where=0}, that's all it does.  Otherwise, it removes the
110
      \code{removeClass} will search for a definition, starting in the
103
      version from the specified environment or database (from the global
111
      top-level environment of the call to \code{removeClass}, and
104
      environment by default).
112
      remove the (first) definition found.
105
    }
113
    }
106
  
114
  
107
    \item{\code{isClass}:}{ 
115
    \item{\code{isClass}:}{ 
108
      Is this a the name of a formally defined class? (Argument
116
      Is this a the name of a formally defined class? (Argument
109
      \code{formal} is for compatibility and is ignored.)  Argument
117
      \code{formal} is for compatibility and is ignored.)
110
      \code{where} is the environment from which to start the search
-
 
111
      for the class definition.  By default, start at the global
-
 
112
      environment and search through the search list.
-
 
113
    }
118
    }
114
 
119
 
115
 
120
 
116
    \item{\code{getClasses}:}{
121
    \item{\code{getClasses}:}{
117
      The names of all the classes formally defined on \code{where}.  If
122
      The names of all the classes formally defined on \code{where}.  If
Line 125... Line 130...
125
    \item{\code{findClass}:}{
130
    \item{\code{findClass}:}{
126
        The list of environments or positions on the search list in
131
        The list of environments or positions on the search list in
127
        which a class definition of \code{Class} is found.  If
132
        which a class definition of \code{Class} is found.  If
128
        \code{where} is supplied, this is an environment (or
133
        \code{where} is supplied, this is an environment (or
129
        namespace) from which the search takes place; otherwise the
134
        namespace) from which the search takes place; otherwise the
130
        top-level environment is used.  If \code{unique} is supplied
135
        top-level environment of the caller is used.  If \code{unique} is supplied
131
        as a character string, \code{findClass} returns a single
136
        as a character string, \code{findClass} returns a single
132
        environment or position.  By default, it always returns a
137
        environment or position.  By default, it always returns a
133
        list.
-
 
134
 
-
 
135
        In the second case, the calling function should select, say, the first element
138
        list.  The calling function should select, say, the first element
136
        as a position or environment for functions such as
139
        as a position or environment for functions such as
-
 
140
        \code{\link{get}}.
-
 
141
 
137
        \code{\link{get}}. In the first case, \code{findClass} will
142
        If \code{unique} is supplied as a character string, \code{findClass} will
138
        warn if there is more than one definition visible (using the
143
        warn if there is more than one definition visible (using the
139
        string supplied as \code{unique} to identify the purpose of
144
        string to identify the purpose of
140
        the call), and will generate an error if no definition can be found.
145
        the call), and will generate an error if no definition can be found.
141
 
146
 
142
    }
147
    }
143
 
-
 
144
    \item{\code{unclass}:}{
-
 
145
      Returns the object containing the values of all the slots in this
-
 
146
      object's class definition (specifically, if the returned object
-
 
147
      has attributes corresponding to each slot), in the case that the
-
 
148
      object's class is formally defined with slots.  For classes that
-
 
149
      extend a single other class (e.g., a basic class such as
-
 
150
      \code{"numeric"}) the result is an object of that class.
-
 
151
    }
-
 
152
    
148
    
153
    \item{\code{resetClass}:}{
149
    \item{\code{resetClass}:}{
154
      Reset the internal definition of a class.  Causes the complete
150
      Reset the internal definition of a class.  Causes the complete
155
      definition of the class to be re-computed, from the
151
      definition of the class to be re-computed, from the
156
      representation and superclasses specified in the original
152
      representation and superclasses specified in the original