| Line 69... |
Line 69... |
| 69 |
refMethods = list(addBoth = function(incr) {
|
69 |
refMethods = list(addBoth = function(incr) {
|
| 70 |
addToBar(incr) #uses inherited class method
|
70 |
addToBar(incr) #uses inherited class method
|
| 71 |
setB2(getB2() + incr)
|
71 |
setB2(getB2() + incr)
|
| 72 |
})),
|
72 |
})),
|
| 73 |
error = function(e)e), "error"))
|
73 |
error = function(e)e), "error"))
|
| 74 |
## but with flag as a subclass of "character", should work
|
74 |
## but with flag as a subclass of "characters", should work
|
| 75 |
## Also subclasses "tag" which had class "ANY before
|
75 |
## Also subclasses "tag" which had class "ANY before
|
| 76 |
setClass("ratedChar", contains = "character",
|
76 |
setClass("ratedChar", contains = "character",
|
| 77 |
representation(score = "numeric"))
|
77 |
representation(score = "numeric"))
|
| 78 |
foo2 <- setRefClass("foo2", list(b2 = "numeric", flag = "ratedChar",
|
78 |
foo2 <- setRefClass("foo2", list(b2 = "numeric", flag = "ratedChar",
|
| 79 |
tag = "numeric"),
|
79 |
tag = "numeric"),
|
| Line 129... |
Line 129... |
| 129 |
## but the import should have used up the one write for $flag
|
129 |
## but the import should have used up the one write for $flag
|
| 130 |
stopifnot(is(tryCatch(f3$flag <- "Try again",
|
130 |
stopifnot(is(tryCatch(f3$flag <- "Try again",
|
| 131 |
error = function(e)e), "error"))
|
131 |
error = function(e)e), "error"))
|
| 132 |
str(f3)
|
132 |
str(f3)
|
| 133 |
|
133 |
|
| - |
|
134 |
## importing the same class (not very useful but documented to work)
|
| - |
|
135 |
f3 <- foo3$new()
|
| - |
|
136 |
f4 <- foo3$new(bar = -3, flag = as("More", "ratedChar"), b2 = 1:3, flag2 = f2$flag)
|
| - |
|
137 |
f3$import(f4)
|
| - |
|
138 |
stopifnot(identical(f3$bar, f4$bar),
|
| - |
|
139 |
identical(f3$flag, f4$flag),
|
| - |
|
140 |
identical(f3$b2, f4$b2),
|
| - |
|
141 |
identical(f3$flag2, f4$flag2))
|
| - |
|
142 |
|
| 134 |
## similar to $import() but using superclass object in the $new() call
|
143 |
## similar to $import() but using superclass object in the $new() call
|
| 135 |
## The explicitly supplied flag= should override and be allowed
|
144 |
## The explicitly supplied flag= should override and be allowed
|
| 136 |
## by the default $initialize()
|
145 |
## by the default $initialize()
|
| 137 |
f3b <- foo3$new(f2, flag = as("Other", "ratedChar"),
|
146 |
f3b <- foo3$new(f2, flag = as("Other", "ratedChar"),
|
| 138 |
flag2 = as("More", "ratedChar"))
|
147 |
flag2 = as("More", "ratedChar"))
|