My question is when the object argument of NexthMethod be used?
In the following example, weather object argument is used will not
affects the result.
###
foo=function(x) {UseMethod("foo")}
foo.cls1=function(x)
{
x=x+1;class(x)<-"ncls"
NextMethod()
}
foo.ncls=function(x)
{
cat("ncls\n")
}
foo.cls2=function(x)
{
cat("cls2\n");print(x)
}
a=1;class(a)=c("cls1","cls2")
> foo(a)
cls2
[1] 2
attr(,"class")
[1] "ncls"
###
> foo=function(x) {UseMethod("foo")}
>
> foo.cls1=function(x)
+ {
+ x=x+1;class(x)<-"ncls"
+ NextMethod(,x)
+ }
>
> foo.ncls=function(x)
+ {
+ cat("ncls\n")
+ }
>
> foo.cls2=function(x)
+ {
+ cat("cls2\n");print(x)
+ }
>
> a=1;class(a)=c("cls1","cls2")
>
> foo(a)
cls2
[1] 2
attr(,"class")
[1] "ncls"
Thank you very much.
--
黄荣贵
Deparment of Sociology
Fudan University
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html