Rev 46503 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/StructureClasses.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{StructureClasses}\title{Classes Corresponding to Basic Structures}\docType{class}%\alias{structure-class}\alias{matrix-class}\alias{array-class}\alias{ts-class}% Group Methods of these\alias{Math,structure-method}\alias{Ops,structure,vector-method}\alias{Ops,structure,structure-method}\alias{Ops,structure,array-method}\alias{Ops,vector,structure-method}\alias{Ops,array,structure-method}\alias{Ops,array,array-method}\alias{initialize,array-method}\alias{initialize,matrix-method}\alias{initialize,ts-method}\alias{initialize,mts-method}\alias{show,ts-method}%\description{The virtual class \code{structure} and classes thatextend it are formal classes analogous to S language structures suchas arrays and time-series.}\usage{## The following class names can appear in method signatures,## as the class in as() and is() expressions, and, except for## the classes commented as VIRTUAL, in calls to new()"matrix""array""ts""structure" ## VIRTUAL}\section{Objects from the Classes}{Objects can be created by calls of the form \code{new(Class, ...)},where \code{Class} is the quoted name of the specific class (e.g.,\code{"matrix"}), and the other arguments, if any, are interpreted asarguments to the corresponding function, e.g., to function\code{matrix()}. There is no particular advantage over calling thosefunctions directly, unless you are writing software designed to workfor multiple classes, perhaps with the class name and the argumentspassed in.Objects created from the classes \code{"matrix"} and \code{"array"} are unusual, to putit mildly, and have been for some time. Although they may appear tobe objects from these classes, they do not have the internalstructure of either an S3 or S4 class object. In particular, theyhave no \code{"class"} attribute and are not recognized as objectswith classes (that is, both \code{\link{is.object}} and\code{\link{isS4}} will return \code{FALSE} for such objects).That the objects still behave as if they came from the correspondingclass (most of the time, anyway) results from special coderecognizing such objects being built into the base code of \R.For most purposes, treating the classes in the usual way will work,fortunately. One consequence of the special treatment is that thesetwo classes\emph{may} be used as the data part of an S4 class; forexample, you can get away with \code{contains = "matrix"} in a callto \code{\link{setGeneric}} to create an S4 class that is a subclassof \code{"matrix"}. There is no guarantee that everything will workperfectly, but a number of classes have been written in this formsuccessfully.The class \code{"ts"} is basically an S3 classthat has been registered with S4, using the\code{\link{setOldClass}} mechanism. Versions of \R through 2.7.0treated this class as a pure S4 class, which was in principal a goodidea, but in practice did not allow subclasses to be defined and hadother intrinsic problems. (For example, setting the\code{"tsp"} parameters as a slot often fails because the built-inimplementation does not allow the slot to be temporarilyinconsistent with the length of the data. Also, the S4 classprevented the correct specification of the S3 inheritance for class\code{"mts"}.)The current behavior (beginning with version 2.8.0 of \R) registers\code{"ts"} as an S3 class, using an S4-style definition (see thedocumentation for \code{\link{setOldClass}} in the examples sectionfor an abbreviated listing of how this is done. The S3inheritance of \code{"mts"} in package \code{stats} is alsoregistered.These classes, as well as \code{"matrix"} and \code{"array"} shouldbe valid in most examples as superclasses for new S4 classdefinitions.}\section{Extends}{The specific classes all extend class \code{"structure"}, directly, andclass \code{"vector"}, by class \code{"structure"}.}\section{Methods}{\describe{\item{coerce}{Methods are defined to coerce arbitrary objects tothese classes, by calling the corresponding basic function, forexample, \code{as(x, "matrix")} calls \code{as.matrix(x)}.}\item{Ops, Math}{Group methods (see, e.g., \code{\link{S4groupGeneric}})are defined for combinations of structures and vectors (includingspecial cases for array and matrix), implementing the concept ofvector structures as in the reference.}}}\references{Chambers, John M. (2008)\emph{Software for Data Analysis: Programming with R}Springer. (For the R version.)Chambers, John M. (1998)\emph{Programming with Data}Springer (For the original S4 version.)Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole (for the original vector structures).}\examples{showClass("structure")## explore a bit :showClass("ts")(ts0 <- new("ts"))str(ts0)showMethods("Ops") # six methods from these classes, but maybe many more}\keyword{classes}