The R Project SVN R

Rev

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

Rev 56572 Rev 56985
Line 5... Line 5...
5
f1 <- fg$new(flag = "testing")
5
f1 <- fg$new(flag = "testing")
6
f1$bar <- 1
6
f1$bar <- 1
7
stopifnot(identical(f1$bar, 1))
7
stopifnot(identical(f1$bar, 1))
8
fg$methods(showAll = function() c(bar, flag))
8
fg$methods(showAll = function() c(bar, flag))
9
stopifnot(all.equal(f1$showAll(), c(1, "testing")))
9
stopifnot(all.equal(f1$showAll(), c(1, "testing")))
-
 
10
str(f1)
10
 
11
 
11
fg <- setRefClass("foo", list(bar = "numeric", flag = "character",
12
fg <- setRefClass("foo", list(bar = "numeric", flag = "character",
12
                              tag = "ANY"),
13
                              tag = "ANY"),
13
                  methods = list(addToBar = function(incr) {
14
                  methods = list(addToBar = function(incr) {
14
                      b <- bar + incr
15
                      b <- bar + incr
Line 27... Line 28...
27
stopifnot(identical(ff$bar, f2$bar), identical(ff$flag, f2$flag))
28
stopifnot(identical(ff$bar, f2$bar), identical(ff$flag, f2$flag))
28
 
29
 
29
f2$flag <- "standard flag"
30
f2$flag <- "standard flag"
30
stopifnot(identical(f2$flag, "standard flag"))
31
stopifnot(identical(f2$flag, "standard flag"))
31
 
32
 
-
 
33
str(f2)
-
 
34
 
32
## fg$lock("flag")
35
## fg$lock("flag")
33
## tryCatch(f2$flag <- "other", error = function(e)e)
36
## tryCatch(f2$flag <- "other", error = function(e)e)
34
 
37
 
35
 
38
 
36
## add some accessor methods
39
## add some accessor methods
Line 79... Line 82...
79
f2 <- foo2$new(bar = -3, flag = as("ANY", "ratedChar"),
82
f2 <- foo2$new(bar = -3, flag = as("ANY", "ratedChar"),
80
               b2 = ff$bar, tag = 1.5)
83
               b2 = ff$bar, tag = 1.5)
81
## but not a second one
84
## but not a second one
82
stopifnot(is(tryCatch(f2$flag <- "Try again",
85
stopifnot(is(tryCatch(f2$flag <- "Try again",
83
         error = function(e)e), "error"))
86
         error = function(e)e), "error"))
-
 
87
str(f2)
84
f22 <- foo2$new(bar = f2$bar)
88
f22 <- foo2$new(bar = f2$bar)
85
## same story if assignment follows the initialization
89
## same story if assignment follows the initialization
86
f22$flag <- f2$flag
90
f22$flag <- f2$flag
87
stopifnot(is(tryCatch(f22$flag <- "Try again",
91
stopifnot(is(tryCatch(f22$flag <- "Try again",
88
         error = function(e)e), "error"))
92
         error = function(e)e), "error"))
Line 118... Line 122...
118
          all.equal(f3$flag2, as("ANY; 1", "ratedChar")))
122
          all.equal(f3$flag2, as("ANY; 1", "ratedChar")))
119
 
123
 
120
## 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
121
stopifnot(is(tryCatch(f3$flag <- "Try again",
125
stopifnot(is(tryCatch(f3$flag <- "Try again",
122
         error = function(e)e), "error"))
126
         error = function(e)e), "error"))
-
 
127
str(f3)
123
 
128
 
124
## a class with an initialize method, and an extra slot
129
## a class with an initialize method, and an extra slot
125
setOldClass(c("simple.list", "list"))
130
setOldClass(c("simple.list", "list"))
126
fg4 <- setRefClass("foo4",
131
fg4 <- setRefClass("foo4",
127
            contains = "foo2",
132
            contains = "foo2",