The R Project SVN R

Rev

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

Rev 39252 Rev 40086
Line 1... Line 1...
1
 
1
 
2
R version 2.5.0 Under development (unstable) (2006-09-11 r39251)
2
R version 2.5.0 Under development (unstable) (2006-11-30 r40078)
3
Copyright (C) 2006 The R Foundation for Statistical Computing
3
Copyright (C) 2006 The R Foundation for Statistical Computing
4
ISBN 3-900051-07-0
4
ISBN 3-900051-07-0
5
 
5
 
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
7
You are welcome to redistribute it under certain conditions.
7
You are welcome to redistribute it under certain conditions.
Line 18... Line 18...
18
> #### Testing  UseMethod() and even more NextMethod()
18
> #### Testing  UseMethod() and even more NextMethod()
19
> ####
19
> ####
20
> 
20
> 
21
> ###-- Group methods
21
> ###-- Group methods
22
> 
22
> 
-
 
23
> ## previous versions used print() and hit an auto-printing bug.
-
 
24
> 
23
> ### Arithmetic "Ops" :
25
> ### Arithmetic "Ops" :
24
> ">.bar" <- function(...) print(">.bar")
26
> ">.bar" <- function(...) {cat("using >.bar\n"); FALSE}
25
> ">.foo" <- function(...) print(">.foo")
27
> ">.foo" <- function(...) {cat("using >.foo\n"); TRUE}
26
> Ops.foo <- function(...) {
28
> Ops.foo <- function(...) {
27
+     print("Ops.foo")
29
+     cat("using Ops.foo\n")
28
+     NextMethod()
30
+     NextMethod()
29
+ }
31
+ }
30
> Ops.bar <- function(...)
32
> Ops.bar <- function(...) {
31
+     print("Ops.bar")
33
+     cat("using Ops.bar\n")
-
 
34
+     TRUE
-
 
35
+ }
32
> 
36
> 
33
> x <- 2:4 ; class(x) <- c("foo", "bar")
37
> x <- 2:4 ; class(x) <- c("foo", "bar")
34
> y <- 4:2 ; class(y) <- c("bar", "foo")
38
> y <- 4:2 ; class(y) <- c("bar", "foo")
35
> 
39
> 
36
> ## The next 4 give a warning each about incompatible methods:
40
> ## The next 4 give a warning each about incompatible methods:
Line 50... Line 54...
50
[1]  TRUE  TRUE FALSE
54
[1]  TRUE  TRUE FALSE
51
Warning message:
55
Warning message:
52
Incompatible methods ("Ops.foo", "Ops.bar") for "<=" 
56
Incompatible methods ("Ops.foo", "Ops.bar") for "<=" 
53
> 
57
> 
54
> x > 3 ##[1] ">.foo"
58
> x > 3 ##[1] ">.foo"
55
[1] ">.foo"
59
using >.foo
-
 
60
[1] TRUE
56
> 
61
> 
57
> rm(list=">.foo")
62
> rm(list=">.foo")
58
> x > 3 #-> "Ops.foo" and ">.bar"
63
> x > 3 #-> "Ops.foo" and ">.bar"
59
[1] "Ops.foo"
64
using Ops.foo
60
[1] ">.bar"
65
using >.bar
-
 
66
[1] FALSE
61
> 
67
> 
62
> 
68
> 
63
> 
69
> 
64
> ### ------------  was ./mode-methods.R till R ver. 1.0.x ----------------
70
> ### ------------  was ./mode-methods.R till R ver. 1.0.x ----------------
65
> 
71
>