Class Attribute of an Object

DESCRIPTION:
Return or change the class attribute of an object.

USAGE:
class(x)
class(x) <- value
unclass(x)

REQUIRED ARGUMENTS:
x:
an S-PLUS object.

OPTIONAL ARGUMENTS:
value:
character vector giving the new class of x.

VALUE:
class returns a character vector which is the "class" attribute of x.

unclass returns x, with all of its original attributes except its class, if any.


SIDE EFFECTS:
the class of x is created or changed when an assignment is made to class(x). The elements of the class are not forced to be unique, but duplicate values are discouraged, as they can cause odd behavior in applying methods.

WARNING:
Assigning the class of an object to a known class may cause strange behavior when a generic function is used on the object. Use this assignment statement with discretion.

DETAILS:
The "class" attribute of an object is used to decide which method of a generic function is to be used in a given instance.

Functions may use unclass in order to deal with an object in raw form without any assistance from methods that may be available to process that class.

Assigning a class to an object is a primitive operation. Assigning class "matrix" to object x, for example, does not cause x to be coerced to have all the attributes of a matrix object: if you wanted that to happen, use as.matrix(x). Similarly, class is not a generic function and methods cannot be written for it.


SEE ALSO:
inherits , UseMethod , Methods , data.class .

EXAMPLES:
foo <-  list(a= letters[1:10], b= LETTERS[1:10])
class(foo) <- "example"
unclass(foo)  #prints foo without attribute "class"

class(diag(3)) # returns NULL data.class(diag(3)) # returns "matrix"