The R Project SVN R

Rev

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

Rev 56186 Rev 56211
Line 1... Line 1...
1
% File src/library/methods/man/NextMethod.Rd
1
% File src/library/methods/man/NextMethod.Rd
2
% Part of the R package, http://www.R-project.org
2
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2007 R Core Development Team
3
% Copyright 1995-2011 R Core Development Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{callNextMethod}
6
\name{callNextMethod}
7
\alias{callNextMethod}
7
\alias{callNextMethod}
8
\title{Call an Inherited Method}
8
\title{Call an Inherited Method}
Line 79... Line 79...
79
 \emph{Software for Data Analysis: Programming with R}
79
 \emph{Software for Data Analysis: Programming with R}
80
  Springer.  (For the R version.)
80
  Springer.  (For the R version.)
81
 
81
 
82
 Chambers, John M. (1998)
82
 Chambers, John M. (1998)
83
 \emph{Programming with Data}
83
 \emph{Programming with Data}
84
 Springer (For the original S4 version.) 
84
 Springer (For the original S4 version.)
-
 
85
}
-
 
86
\seealso{\code{\link{callGeneric}} to call the generic function with the
-
 
87
 current dispatch rules (typically for a group generic function);
-
 
88
 \link{Methods} for the general behavior of method dispatch.
85
}
89
}
86
\seealso{\code{\link{callGeneric}} to call the generic function with the current
-
 
87
  dispatch rules (typically for a group generic function); \link{Methods} for the general behavior of method dispatch}
-
 
88
 
90
 
89
\examples{
91
\examples{
90
 
92
 
91
## some class definitions with simple inheritance
93
## some class definitions with simple inheritance
92
setClass("B0" , representation(b0 = "numeric"))
94
setClass("B0" , representation(b0 = "numeric"))
Line 111... Line 113...
111
stopifnot(identical(f(b2), c(b2@b2, paste(b2@b1,":"), b2@b0^2, "B2")))
113
stopifnot(identical(f(b2), c(b2@b2, paste(b2@b1,":"), b2@b0^2, "B2")))
112
 
114
 
113
f(b1)
115
f(b1)
114
 
116
 
115
## a sneakier method: the *changed* x is used:
117
## a sneakier method: the *changed* x is used:
-
 
118
setMethod("f", "B2",
116
setMethod("f", "B2", function(x) {x@b0 <- 111; c(x@b2, callNextMethod())})
119
          function(x) {x@b0 <- 111; c(x@b2, callNextMethod())})
117
f(b2)
120
f(b2)
118
stopifnot(identical(f(b2), c(b2@b2, paste(b2@b1,":"), 111^2, "B2")))
121
stopifnot(identical(f(b2), c(b2@b2, paste(b2@b1,":"), 111^2, "B2")))
119
 
122
 
120
\dontshow{
123
\dontshow{
121
## a version of the example with 1 more layer of nesting
124
## a version of the example with 1 more layer of nesting
Line 153... Line 156...
153
 
156
 
154
stopifnot(identical(mm2[,2], 4:6))
157
stopifnot(identical(mm2[,2], 4:6))
155
 
158
 
156
setClass("m3", representation(rowtags = "character"),contains = "m2")
159
setClass("m3", representation(rowtags = "character"),contains = "m2")
157
 
160
 
158
setMethod("[", signature(x="m3", i = "character", j = "missing", drop = "missing"),
161
setMethod("[", signature(x="m3", i = "character", j = "missing",
-
 
162
                         drop = "missing"),
159
          function(x, i,j, ..., drop) {
163
          function(x, i,j, ..., drop) {
160
              xx <- callNextMethod(x, match(i, x@rowtags),)
164
              xx <- callNextMethod(x, match(i, x@rowtags),)
161
              x@.Data <- xx
165
              x@.Data <- xx
162
              x@rowtags <- x@rowtags[match(i, x@rowtags)]
166
              x@rowtags <- x@rowtags[match(i, x@rowtags)]
163
              x})
167
              x})
164
 
168
 
165
tm = matrix(1:12, 4, 3)
169
tm <- matrix(1:12, 4, 3)
166
 
170
 
167
mm3 = new("m3", tm, rowtags = letters[1:4])
171
mm3 <- new("m3", tm, rowtags = letters[1:4])
168
 
172
 
169
mmm = mm3[c("b", "d")]
173
mmm <- mm3[c("b", "d")]
170
 
174
 
-
 
175
stopifnot(identical(mmm,
171
stopifnot(identical(mmm, new("m3", tm[c(2, 4),], rowtags = c("b", "d"))))
176
      new("m3", tm[c(2, 4),], rowtags = c("b", "d"))))
172
 
177
 
173
removeClass("m3")
178
removeClass("m3")
174
removeClass("m2")
179
removeClass("m2")
175
removeClass("m1")
180
removeClass("m1")
176
 
181
 
177
removeMethods("[")
182
removeMethods("[")
178
 
-
 
179
}
183
}
180
 
184
 
181
}
185
}
182
\keyword{programming}
186
\keyword{programming}
183
\keyword{classes}
187
\keyword{classes}