[R] NextMethod() example from S Programming by Venables and Ripley (page 78)
blue sky
bluesky315 at gmail.com
Sun Feb 14 06:52:34 CET 2010
S Programming by Venables and Ripley (page 78) has the example listed
at the end of this email. However, I get the following error when I
try the example. I don't understand the descriptions of NextMethod on
its help page. Could somebody let me know how to fix the error of this
example?
> test(x)
c1
c2
Error in NextMethod() : no method to invoke
Calls: test -> test.c1 -> NextMethod -> test.c2 -> NextMethod
Execution halted
####
test=function(x) UseMethod('test')
test.c1=function(x) {
cat('c1\n')
NextMethod()
x
}
test.c2=function(x) {
cat('c2\n')
NextMethod()
x
}
test.c3=function(x) {
cat('c3\n')
x
}
x=1
class(x)=c('c1','c2')
test(x)
More information about the R-help
mailing list