The R Project SVN R

Rev

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

Rev 56985 Rev 57183
Line 100... Line 100...
100
          all.equal(f2$b2, 2:4+0))
100
          all.equal(f2$b2, 2:4+0))
101
f2$addBoth(-1)
101
f2$addBoth(-1)
102
stopifnot(all.equal(f2$bar, -4), all.equal(f2$b2, 1:3+0))
102
stopifnot(all.equal(f2$bar, -4), all.equal(f2$b2, 1:3+0))
103
 
103
 
104
## test callSuper()
104
## test callSuper()
105
setRefClass("foo3", fields = list(flag2 = "ratedChar"),
105
foo3 <- setRefClass("foo3", fields = list(flag2 = "ratedChar"),
106
            contains = "foo2",
106
            contains = "foo2",
107
	    methods = list(addBoth = function(incr) {
107
	    methods = list(addBoth = function(incr) {
108
		callSuper(incr)
108
		callSuper(incr)
109
		flag2 <<- as(paste(flag, paste(incr, collapse = ", "),
109
		flag2 <<- as(paste(flag, paste(incr, collapse = ", "),
110
				   sep = "; "),
110
				   sep = "; "),
111
                             "ratedChar")
111
                             "ratedChar")
112
                incr
112
                incr
113
            }))
113
            }))
114
 
114
 
115
f2 <- foo2$new(bar = -3, flag = as("ANY", "ratedChar"), b2 =  1:3)
115
f2 <- foo2$new(bar = -3, flag = as("ANY", "ratedChar"), b2 =  1:3)
116
f3 <- new("foo3")
116
f3 <- foo3$new()
117
f3$import(f2)
117
f3$import(f2)
118
stopifnot(all.equal(f3$b2, f2$b2), all.equal(f3$bar, f2$bar),
118
stopifnot(all.equal(f3$b2, f2$b2), all.equal(f3$bar, f2$bar),
119
          all.equal(f3$flag, f2$flag))
119
          all.equal(f3$flag, f2$flag))
120
f3$addBoth(1)
120
f3$addBoth(1)
121
stopifnot(all.equal(f3$bar, -2), all.equal(f3$b2, 2:4+0),
121
stopifnot(all.equal(f3$bar, -2), all.equal(f3$b2, 2:4+0),
Line 124... Line 124...
124
## but the import should have used up the one write for $flag
124
## but the import should have used up the one write for $flag
125
stopifnot(is(tryCatch(f3$flag <- "Try again",
125
stopifnot(is(tryCatch(f3$flag <- "Try again",
126
         error = function(e)e), "error"))
126
         error = function(e)e), "error"))
127
str(f3)
127
str(f3)
128
 
128
 
-
 
129
## similar to $import() but using superclass object in the $new() call
-
 
130
## The explicitly supplied flag= should override and be allowed
-
 
131
## by the default $initialize() 
-
 
132
f3b <- foo3$new(f2, flag = as("Other", "ratedChar"),
-
 
133
                flag2 = as("More", "ratedChar"))
-
 
134
## check that inherited and direct field assignments worked
-
 
135
stopifnot(identical(f3b$tag, f2$tag),
-
 
136
          identical(f3b$flag, as("Other", "ratedChar")),
-
 
137
          identical(f3b$flag2, as("More", "ratedChar")))
-
 
138
 
129
## a class with an initialize method, and an extra slot
139
## a class with an initialize method, and an extra slot
130
setOldClass(c("simple.list", "list"))
140
setOldClass(c("simple.list", "list"))
131
fg4 <- setRefClass("foo4",
141
fg4 <- setRefClass("foo4",
132
            contains = "foo2",
142
            contains = "foo2",
133
            methods = list(
143
            methods = list(