Re: [Rd] Another problem with next method

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Thu 28 Oct 2004 - 11:02:04 EST

Gabor Grothendieck <ggrothendieck <at> myway.com> writes:

:
: I have another problem with NextMethod. Not sure if its related
: to the last problem.
:
: In this example, we have a generic called ff with methods
: for AsIs and test classes. We call the generic with an
: object of AsIs class. The corresponding method adds 1 to it
: and then changes the class to test followed by issuing a
: NextMethod. However, that results in this error (using R
: 2.0.0, 2004-10-04 Windows XP):
:
: Error in NextMethod("ff") : No method to invoke
:
: Why can't NextMethod find ff.test ?
:
: I also tried a number of variations of this including adding x = x
: to the NExtMethod argument list but none of these variations worked.
:
: ---
:
: ff <- function(x, ...) UseMethod("ff")
: ff.AsIs <- function(x, ...) {
: x <- x + 1
: class(x) <- "test"
: NextMethod("ff")
: }
: ff.test <- function(x, ...) cat(x, class(x), ..., "\n")
: ff(I(3))

Just in case there is some doubt the following example is almost identical to the one on page 74 of the Writing Extensions manual and gives the same error message cited above:

ff <- function(x) UseMethod("ff")
ff.data.frame <- function(x)
{

	x <- as.matrix(x)
	NextMethod("ff")

}
ff.matrix <- function(x) dim(x)
data(iris)
ff(iris)

R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Oct 28 11:08:23 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:26 EST