is
Inheritance Relationships Between Classes

Description

Tests inheritance relationships between an object and a class or between two classes, and explicitly creates such relationships between two classes.

Usage

is(object, class2)
extends(class1, class2, maybe = TRUE, fullInfo = FALSE)
setIs(class1, class2, test = NULL, coerce = NULL, replace = NULL, 
      by = character(), where = topenv(parent.frame()),
      classDef = getClass(class1, TRUE, where = where),
      extensionObject = NULL, doComplete = TRUE)

Arguments

object any object.
class1 a character string. The name of a class or a class representation object.
class2 a character string. The name of a class or a class representation object. If you omit this argument in extends or is, these functions return a character vector of all the known superclasses for which the extends or is relation holds.
maybe this argument is unimplemented. If given, it generates a warning.
fullInfo this argument is unimplemented. If given, it generates a warning.
test an optional function defining a conditional relationship between class1 and class2. If this is given, it should be a function with argument (object), and it will be called by the is function to test whether an object should be considered a member of class2.
coerce an optional function defining how to coerce an object with class class1 to class2. If this is given, it should be a function with arguments (from, strict), and it will be called by the as function to perform this coercion unless an explicit coerce method is defined.
replace an optional function defining how to replace parts of an object with class class1 with parts of an object with class class2. If given, it should be a function with arguments (from, to, value), and it will be called by the as<- function to perform this coercion unless an explicit coerce<- method is defined.
by this argument is unimplemented. If given, it generates a warning.
where the environment to store the class definition.
classDef this argument is unimplemented. If given, it generates a warning.
extensionObject this argument is unimplemented. If given, it generates a warning.
doComplete this argument is unimplemented. If given, it generates a warning.

Details

is tests whether an object has a given S4 or S3 class, or inherits from such a class. Other functions are useful for testing for specific behavior. For example: You can get a list of such functions by executing methods("is").
extends tests if the first class inherits from the second class.
setIs sets up an inheritance relation between two existing S4 classes, after they have been created with link{setClass}.
Value

isreturns TRUE if object has an is relation to class2. That is, if object has (or inherits from) class class2. Otherwise, it returns FALSE. If class2 is omitted, is returns a character vector of the known superclasses for which the relation holds.
extendsreturns TRUE if class1 extends class2. Otherwise, it returns FALSE. If class2 is omitted, extends returns a character vector of the known superclasses for which the relation holds.
setIsinvisibly returns the modified class definition of class1.
See Also
as, setClass
Examples
x <- runif(6)
class(x)         #  "numeric"
is(x, "double")  # FALSE -- because "double" is not a defined class
is.double(x)     # TRUE
is(x, "numeric") # TRUE 
is(x)            # list all classes a "numeric" object could inherit from.

x <- structure(1:9, dim=c(3L,3L), class="xyz") class(x) # "xyz" is(x, "matrix") # FALSE -- because x has class "xyz", not "matrix" is.matrix(x) # TRUE

is(letters) # list all the classes a "character" object could inherit from. extends("matrix", "array") # TRUE

# create two unrelated classes setClass("square", representation(x="numeric")) setClass("rectangle", representation(x="numeric", y="numeric")) n <- new("rectangle", x = 6, y = 7) m <- new("square", x = 5) # create "area" method for class "rectangle" setGeneric("area", function(object) standardGeneric("area")) setMethod("area", "rectangle", function(object) if(is.element("y", slotNames(class(object)))) { object@x * object@y } else { (object@x)^2 } ) # area(m) gives an error since "m" doesn't inherit from class "rectangle" yet area(n) # 42 area(m) # Error # Setup the relation that class "square" inherits from "rectangle". setIs("square", "rectangle") # now the methods for "rectangle" can be inherited by "square" area(n) # 42 area(m) # 25

Package methods version 6.0.0-69
Package Index