Rev 12778 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{class}\title{Object Classes}\usage{class(x)class(x) <- namesunclass(x)inherits(x, what, which = FALSE)}\alias{class}\alias{class<-}\alias{unclass}\alias{inherits}\description{\R possesses a simple generic function mechanism which can be used foran object-oriented style of programming. Method despatch takes placebased on the class of the first argument to the generic function.}\details{An \R ``object'' is a data object which has a \code{class} attribute.A class attribute is a character vector giving the names ofthe classes which the object ``inherits'' from. When a genericfunction \code{fun} is applied to an object with class attribute\code{c("first", "second")}, the system searches for a function called\code{fun.first} and, if it finds it, applies it to the object. If nosuch function is found, a function called \code{fun.second} is tried.If no class name produces a suitable function, the function\code{fun.default} is used.The function \code{class} prints the vector of names of classes anobject inherits from. Correspondingly, \code{class<-} sets theclasses an object inherits from.\code{unclass} returns (a copy of) its argument with its classinformation removed.\code{inherits} indicates whether its first argument inherits from anyof the classes specified in the \code{what} argument. If \code{which}is \code{TRUE} then an integer vector of the same length as\code{what} is returned. Each element indicates the position in the\code{class(x)} matched by the element of \code{what}; zero indicatesno match. If \code{which} is \code{FALSE} then \code{TRUE} isreturned by \code{inherits} if any of the names in \code{what} matchwith any \code{class}.}\seealso{\code{\link{UseMethod}}, \code{\link{NextMethod}}.}\examples{x<-10inherits(x,"a") #FALSEclass(x)<-c("a","b")inherits(x,"a") #TRUEinherits(x,"a",T) # 1inherits(x,c("a","b","c"),T) # 1 2 0}\keyword{methods}\keyword{classes}