Skip to content
Prev 35114 / 63424 Next

group generics

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin Morgan wrote:
A different error this time, one that looks a lot like the report from
Stephen.Pope at ubs.com on 2007-12-24 concerning callNextMethod:, except
this is with
callGeneric.

HOWEVER, the problem is erratic; when I started from scratch and took
this code into a workspace and executed the commands, they worked as
expected.  I had various false starts and revisions, as well as the real
code on which the example is based, when the error occurred.  I tried
taking in the real code (which defines generics with Arith from my
actual classes, and which also fails as below), and the example still
worked.


My revised code:

setClass("A",
         representation=representation(xa="numeric")
         )

setMethod("Arith", signature(e1="numeric", e2="A"), function(e1, e2) {
  new("A", xa=callGeneric(e1, e2 at xa))
}
         )

setClass("B",
         representation=representation(xb="numeric"),
         contains=c("A")
         )

setMethod("Arith", signature(e1="numeric", e2="B"), function(e1, e2) {
  new("B", xb=e1*e2 at xb, callNextMethod())
}
)

Results:
Error in get(fname, envir = envir) : object '.nextMethod' not found

Enter a frame number, or 0 to exit

 1: 3 * tb
 2: 3 * tb
 3: test.R#16: new("B", xb = e1 * e2 at xb, callNextMethod())
 4: initialize(value, ...)
 5: initialize(value, ...)
 6: callNextMethod()
 7: .nextMethod(e1 = e1, e2 = e2)
 8: test.R#6: new("A", xa = callGeneric(e1, e2 at xa))
 9: initialize(value, ...)
10: initialize(value, ...)
11: callGeneric(e1, e2 at xa)
12: get(fname, envir = envir)

Selection: 0

The callGeneric in frame 11 is trying to get the primitive for
multiplying numeric times numeric.  Quoting from Pope's analysis:
[The primitive...]
I'm baffled, and hoping someone on the list has an idea.
I'm running R 2.10 under ESS (in particular, I use c-c c-l in the code
file to read in the code) on XP.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksUTcQACgkQTEwcvZWfjMgEdwCfYt/bmsXG76rq3BpbByBYNjLY
ubsAoKnBnBMbd+OlBL2YOg3vWslL35Zg
=D58x
-----END PGP SIGNATURE-----