Computations with Classes
Functions to find and manipulate class definitions.
isClass(Class, formal=TRUE, where)getClasses(where, inherits = missing(where))findClass(Class, where, unique = "")removeClass(Class, where, resolve.msg = getOption("removeClass.msg", default=TRUE))resetClass(Class, classDef, where)sealClass(Class, where)
- character string name for the class. The functions will
usually take a class definition instead of the string. To restrict
the class to those defined in a particular package, set the
packageSlotof the character string.
environmentin which to modify or remove the definition. Defaults to the top-level environment of the calling function (the global environment for ordinary computations, but the environment or namespace of a package in the source for a package).
When searching for class definitions,
wheredefines where to do the search, and the default is to search from the top-level environment or namespace of the caller to this function.
logicalindicating if a formal definition is required.
findClassexpects a unique location for the class,
uniqueis a character string explaining the purpose of the search (and is used in warning and error messages). By default, multiple locations are possible and the function always returns a list.
- in a call to
getClasses, should the value returned include all parent environments of
where, or that environment only? Defaults to
whereis omitted, and to
logicalindicating if R should
message()its decision if
Classis found in multiple namespaces and one is chosen.
resetClass, the optional class definition (but usually it's better for
Classto be the class definition, and to omit
These are the functions that test and manipulate formal class definitions. Brief documentation is provided below. See the references for an introduction and for more details.
Remove the definition of this class, from the environment
whereif this argument is supplied; if not,
removeClasswill search for a definition, starting in the top-level environment of the call to
removeClass, and remove the (first) definition found.
formalis for compatibility and is ignored.)
where. If called with no argument, all the classes visible from the calling function (if called from the top-level, all the classes in any of the environments on the search list). The
inheritsargument can be used to search a particular environment and all its parents, but usually the default setting is what you want.
Classis found. If
whereis supplied, this is an environment (or namespace) from which the search takes place; otherwise the top-level environment of the caller is used. If
uniqueis supplied as a character string,
findClassreturns a single environment or position. By default, it always returns a list. The calling function should select, say, the first element as a position or environment for functions such as
unique is supplied as a character string,
findClass will warn if there is more than one definition
visible (using the string to identify the purpose of the call),
and will generate an error if no definition can be found.
This function is called when aspects of the class definition are changed. You would need to call it explicitly if you changed the definition of a class that this class extends (but doing that in the middle of a session is living dangerously, since it may invalidate existing objects).
setClass, but sometimes further changes have to be made (e.g., by calls to
setIs). If so, call
sealClassafter all the relevant changes have been made.
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.)