The R Project SVN R

Rev

Rev 31672 | Rev 36334 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31672 Rev 32148
Line 24... Line 24...
24
\details{
24
\details{
25
  An \R \dQuote{object} is a data object which has a \code{class} attribute.
25
  An \R \dQuote{object} is a data object which has a \code{class} attribute.
26
  A class attribute is a character vector giving the names of
26
  A class attribute is a character vector giving the names of
27
  the classes which the object \dQuote{inherits} from.
27
  the classes which the object \dQuote{inherits} from.
28
  If the object does not have a class attribute, it has an implicit
28
  If the object does not have a class attribute, it has an implicit
29
  class, \code{"matrix"}, \code{"array"} or the result of
29
  class.  Matrices and arrays have class \code{"matrix"}
-
 
30
  or\code{"array"} followed by the class of the underlying vector.
30
  \code{\link{mode}(x)}.
31
  Most vectors have class the result of \code{\link{mode}(x)}, expect
-
 
32
  that integer vectors have class \code{c("integer", "numeric")} and
-
 
33
  real vectors have class \code{c("double", "numeric")}.
31
 
34
 
32
  When a generic
-
 
33
  function \code{fun} is applied to an object with class attribute
35
  When a generic function \code{fun} is applied to an object with class
34
  \code{c("first", "second")}, the system searches for a function called
36
  attribute \code{c("first", "second")}, the system searches for a
35
  \code{fun.first} and, if it finds it, applied it to the object.  If no
37
  function called \code{fun.first} and, if it finds it, applied it to
36
  such function is found a function called \code{fun.second} is tried.
38
  the object.  If no such function is found a function called
37
  If no class name produces a suitable function, the function
39
  \code{fun.second} is tried.  If no class name produces a suitable
-
 
40
  function, the function \code{fun.default} is used, if it exists, or an
38
  \code{fun.default} is used.
41
  error results.
-
 
42
  
39
 
43
 
40
  Function \code{\link{methods}} can be used to find out about the
44
  Function \code{\link{methods}} can be used to find out about the
41
  methods for a particular generic function or class.
45
  methods for a particular generic function or class.
42
 
46
 
43
  Now for some obscure details that need to appear somewhere.  These
47
  Now for some obscure details that need to appear somewhere.  These
Line 48... Line 52...
48
  statements after the call to \code{UseMethod} will not be evaluated as
52
  statements after the call to \code{UseMethod} will not be evaluated as
49
  \code{UseMethod} does not return.  \code{UseMethod} can be called with
53
  \code{UseMethod} does not return.  \code{UseMethod} can be called with
50
  more than two arguments: a warning will be given and additional
54
  more than two arguments: a warning will be given and additional
51
  arguments ignored. (They are not completely ignored in S.)  If it is
55
  arguments ignored. (They are not completely ignored in S.)  If it is
52
  called with just one argument, the class of the first argument of the
56
  called with just one argument, the class of the first argument of the
53
  enclosing function is used as \code{object}: unlike S this is the
57
  enclosing function is used as \code{object}: unlike S this is the first
54
  actual argument passed and not the current value of the object of that
58
  actual argument passed and not the current value of the object of that
55
  name.
59
  name.
56
 
60
 
57
  \code{NextMethod} invokes the next method (determined by the
61
  \code{NextMethod} invokes the next method (determined by the
58
  class).  It does this by creating a special call frame for that
62
  class).  It does this by creating a special call frame for that
Line 76... Line 80...
76
  environment in which the generic is defined (typically a name space).
80
  environment in which the generic is defined (typically a name space).
77
  So methods for a generic function need to either be available in the
81
  So methods for a generic function need to either be available in the
78
  environment of the call to the generic, or they must be registered.
82
  environment of the call to the generic, or they must be registered.
79
  It does not matter whether they are visible in the environment in
83
  It does not matter whether they are visible in the environment in
80
  which the generic is defined.
84
  which the generic is defined.
81
 
-
 
82
}
85
}
83
\note{
86
\note{
84
  This scheme is called \emph{S3} (S version 3).  For new projects,
87
  This scheme is called \emph{S3} (S version 3).  For new projects,
85
  it is recommended to use the more flexible and robust \emph{S4} scheme
88
  it is recommended to use the more flexible and robust \emph{S4} scheme
86
  provided in the \pkg{methods} package. 
89
  provided in the \pkg{methods} package.