The R Project SVN R

Rev

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

Rev 24536 Rev 40086
Line 1... Line 1...
1
#### Testing  UseMethod() and even more NextMethod()
1
#### Testing  UseMethod() and even more NextMethod()
2
####
2
####
3
 
3
 
4
###-- Group methods
4
###-- Group methods
5
 
5
 
-
 
6
## previous versions used print() and hit an auto-printing bug.
-
 
7
 
6
### Arithmetic "Ops" :
8
### Arithmetic "Ops" :
7
">.bar" <- function(...) print(">.bar")
9
">.bar" <- function(...) {cat("using >.bar\n"); FALSE}
8
">.foo" <- function(...) print(">.foo")
10
">.foo" <- function(...) {cat("using >.foo\n"); TRUE}
9
Ops.foo <- function(...) {
11
Ops.foo <- function(...) {
10
    print("Ops.foo")
12
    cat("using Ops.foo\n")
11
    NextMethod()
13
    NextMethod()
12
}
14
}
13
Ops.bar <- function(...)
15
Ops.bar <- function(...) {
14
    print("Ops.bar")
16
    cat("using Ops.bar\n")
-
 
17
    TRUE
-
 
18
}
15
 
19
 
16
x <- 2:4 ; class(x) <- c("foo", "bar")
20
x <- 2:4 ; class(x) <- c("foo", "bar")
17
y <- 4:2 ; class(y) <- c("bar", "foo")
21
y <- 4:2 ; class(y) <- c("bar", "foo")
18
 
22
 
19
## The next 4 give a warning each about incompatible methods:
23
## The next 4 give a warning each about incompatible methods: