findClass: Find Class Definitions

findClassR Documentation

Find Class Definitions


Functions to find classes: isClass tests for a class; findClass returns the name(s) of packages containing the class; getClasses returns the names of all the classes in an environment, typically a namespace. To examine the definition of a class, use getClass.


isClass(Class, formal=TRUE, where)

getClasses(where, inherits = missing(where))

findClass(Class, where, unique = "")

## The remaining functions are retained for compatibility
## but not generally recommended

removeClass(Class, where)

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 packageSlot of the character string.


the environment in which to search for the class definition. Defaults to the top-level environment of the calling function. When called from the command line, this has the effect of using all the package environments in the search list.

To restrict the search to classes in a particular package, use where = asNamespace(pkg) with pkg the package name; to restrict it to the exported classes, use where = "package:pkg" after the package is attached to the search list.


logical is a formal definition required? For S compatibility, and always treated as TRUE.


if findClass expects a unique location for the class, unique is 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 TRUE if where is omitted, and to FALSE otherwise.


For resetClass, the optional class definition.



Is this the name of a formally defined class?


The names of all the classes formally defined on 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 where argument is used to search only in a particular package.


The list of environments in which a class definition of Class is found. If where is supplied, a list is still returned, either empty or containing the environment corresponding to where. By default when called from the R session, the global environment and all the currently attached packages are searched.

If 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.

The remaining functions are retained for back-compatibility and internal use, but not generally recommended.


Remove the definition of this class. This can't be used if the class is in another package, and would rarely be needed in source code defining classes in a package.


Reset the internal definition of a class. Not legitimate for a class definition not in this package and rarely needed otherwise.


Seal the current definition of the specified class, to prevent further changes, by setting the corresponding slot in the class definition. This is rarely used, since classes in loaded packages are sealed by locking their namespace.


Chambers, John M. (2016) Extending R, Chapman & Hall. (Chapters 9 and 10.)

Chambers, John M. (2008) Software for Data Analysis: Programming with R Springer. (Chapter 9 has some details not in the later reference.)

See Also

getClass, Classes_Details, Methods_Details, makeClassRepresentation