R: Get Class Definition

getClass {methods} | R Documentation

## Get Class Definition

### Description

Get the definition of a class.

### Usage

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

### Arguments

`Class` | the character-string name of the class.
`.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. Supplied instead of `where`, with the distinction that the package need not be currently attached.

### Details

A call to `getClass` returns the complete definition of the class supplied as a string, including all slots, etc. in classes that this class extends. A call to `getClassDef` returns the definition of the class from the environment `where`, unadorned. It's usually `getClass` you want.

If you really want to know whether a class is formally defined, call `isClass`.

### Value

The object defining the class. This is an object of class `classRepresentation`. However, do not deal with the contents of the object directly unless you are very sure you know what you're doing. Even then, it is nearly always better practice to use functions such as `setClass` and `setIs`. Messing up a class object will cause great confusion.

### References

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

### See Also

Classes, `setClass`, `isClass`.

### Examples

    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"))

[Package methods version 2.8.1 Index]