The R Project SVN R

Rev

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

Rev 24517 Rev 24536
Line 1... Line 1...
1
 
1
 
2
R : Copyright 2003, The R Development Core Team
2
R : Copyright 2003, The R Development Core Team
3
Version 1.7.0 Under development (unstable) (2003-02-01)
3
Version 1.8.0 Under development (unstable) (2003-05-30)
4
 
4
 
5
R is free software and comes with ABSOLUTELY NO WARRANTY.
5
R is free software and comes with ABSOLUTELY NO WARRANTY.
6
You are welcome to redistribute it under certain conditions.
6
You are welcome to redistribute it under certain conditions.
7
Type `license()' or `licence()' for distribution details.
7
Type `license()' or `licence()' for distribution details.
8
 
8
 
Line 63... Line 63...
63
> 
63
> 
64
> ###-- Using Method Dispatch on "mode" etc :
64
> ###-- Using Method Dispatch on "mode" etc :
65
> ## Tests S3 dispatch with the class attr forced to be data.class
65
> ## Tests S3 dispatch with the class attr forced to be data.class
66
> ## Not very relevant when S4 methods are around, but kept for historical interest
66
> ## Not very relevant when S4 methods are around, but kept for historical interest
67
> abc <- function(x, ...) {
67
> abc <- function(x, ...) {
68
+     if (is.null(oldClass(x))) oldClass(x) <- data.class(x)
68
+     cat("abc: Before dispatching; x has class `", class(x), "':", sep="")
69
+     cat("abc: Before dispatching; x="); str(x)
69
+     str(x)
70
+     UseMethod("abc", x) ## UseMethod("abc") (as in S) fails
70
+     UseMethod("abc", x) ## UseMethod("abc") (as in S) fails
71
+ }
71
+ }
72
> 
72
> 
73
> abc.default <- function(x, ...) sys.call()
73
> abc.default <- function(x, ...) sys.call()
74
> 
74
> 
Line 76... Line 76...
76
+     cat("'(' method of abc:", deparse(sys.call(sys.parent())),"\n")
76
+     cat("'(' method of abc:", deparse(sys.call(sys.parent())),"\n")
77
> abc.expression <- function(x)
77
> abc.expression <- function(x)
78
+     cat("'expression' method of abc:", deparse(sys.call(sys.parent())),"\n")
78
+     cat("'expression' method of abc:", deparse(sys.call(sys.parent())),"\n")
79
> 
79
> 
80
> abc(1)
80
> abc(1)
81
abc: Before dispatching; x=Class 'numeric'  num 1
81
abc: Before dispatching; x has class `numeric': num 1
82
abc.default(1)
82
abc.default(1)
83
> e0 <- expression((x))
83
> e0 <- expression((x))
84
> e1 <- expression(sin(x))
84
> e1 <- expression(sin(x))
85
> abc(e0)
85
> abc(e0)
86
abc: Before dispatching; x=Class 'expression'   expression((x))
86
abc: Before dispatching; x has class `expression':  expression((x))
87
'expression' method of abc: abc.expression(e0) 
87
'expression' method of abc: abc.expression(e0) 
88
> abc(e1)
88
> abc(e1)
89
abc: Before dispatching; x=Class 'expression'   expression(sin(x))
89
abc: Before dispatching; x has class `expression':  expression(sin(x))
90
'expression' method of abc: abc.expression(e1) 
90
'expression' method of abc: abc.expression(e1) 
91
> abc(e0[[1]])
91
> abc(e0[[1]])
92
abc: Before dispatching; x=Class '('  language, mode "(": ( x
92
abc: Before dispatching; x has class `(': language, mode "(": ( x
93
'(' method of abc: "abc.("(e0[[1]]) 
93
'(' method of abc: "abc.("(e0[[1]]) 
94
> abc(e1[[1]])
94
> abc(e1[[1]])
95
abc: Before dispatching; x=Class 'call'  language sin(x)
95
abc: Before dispatching; x has class `call': language sin(x)
96
abc.default(e1[[1]])
96
abc.default(e1[[1]])
97
> 
97
>