The R Project SVN R

Rev

Rev 61168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/data.class.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
59039 ripley 3
% Copyright 1995-2007 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
2 r 6
\name{data.class}
56186 murdoch 7
\alias{data.class}
6310 maechler 8
\title{Object Classes}
7782 hornik 9
\description{
10
  Determine the class of an arbitrary \R object.
11
}
2 r 12
\usage{
13
data.class(x)
14
}
15
\arguments{
7782 hornik 16
  \item{x}{an \R object.}
2 r 17
}
18
\value{
42961 ripley 19
  character string giving the \emph{class} of \code{x}.
286 maechler 20
 
49567 ripley 21
  The class is the (first element) of the \code{\link{class}}
42961 ripley 22
  attribute if this is non-\code{NULL}, or inferred from the object's
23
  \code{dim} attribute if this is non-\code{NULL}, or \code{mode(x)}.
2 r 24
 
25
  Simply speaking, \code{data.class(x)} returns what is typically useful
18086 ripley 26
  for method dispatching.  (Or, what the basic creator functions already
2 r 27
  and maybe eventually all will attach as a class attribute.)
28
}
20401 maechler 29
\note{
30
  For compatibility reasons, there is one exception to the rule above:
31
  When \code{x} is \code{\link{integer}}, the result of
32
  \code{data.class(x)} is \code{"numeric"} even when \code{x} is classed.
33
}
2 r 34
\seealso{
49567 ripley 35
  \code{\link{class}}
2 r 36
}
37
\examples{
38
x <- LETTERS
39
data.class(factor(x))                 # has a class attribute
42961 ripley 40
data.class(matrix(x, ncol = 13))      # has a dim attribute
2 r 41
data.class(list(x))                   # the same as mode(x)
42
data.class(x)                         # the same as mode(x)
20401 maechler 43
 
61168 ripley 44
stopifnot(data.class(1:2) == "numeric") # compatibility "rule"
2 r 45
}
286 maechler 46
\keyword{classes}
47
\keyword{methods}