The R Project SVN R

Rev

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

Rev 53645 Rev 53669
Line 229... Line 229...
229
  finalize = function() {
229
  finalize = function() {
230
    dev.off(viewerDevice)
230
    dev.off(viewerDevice)
231
    setMarkViewer("OFF")
231
    setMarkViewer("OFF")
232
  })
232
  })
233
 
233
 
234
ff = new("matrixViewer", data = xMat)
234
ff = mv$new( data = xMat)
235
stopifnot(identical(markViewer, "ON")) # check initialize
235
stopifnot(identical(markViewer, "ON")) # check initialize
236
ff$edit(2,2,0)
236
ff$edit(2,2,0)
237
ff$data
237
ff$data
238
ff$undo()
238
ff$undo()
239
stopifnot(all.equal(ff$data, xMat))
239
stopifnot(all.equal(ff$data, xMat))
240
rm(ff)
240
rm(ff)
241
gc()
241
gc()
242
stopifnot(identical(markViewer, "OFF")) #check finalize
242
stopifnot(identical(markViewer, "OFF")) #check finalize
243
 
243
 
-
 
244
## tests of copying
-
 
245
viewerPlus <- setRefClass("viewerPlus",
-
 
246
                   fields = list( text = "character",
-
 
247
                      viewer = "matrixViewer"))
-
 
248
ff <- mv$new( data = xMat)
-
 
249
v1 <- viewerPlus$new(text = letters, viewer = ff)
-
 
250
v2 <- v1$copy()
-
 
251
v3 <- v1$copy(TRUE)
-
 
252
v2$text <- "Hello, world"
-
 
253
v2$viewer$data <- t(xMat) # change a field in v2$viewer
-
 
254
v3$text <- LETTERS
-
 
255
v3$viewer <- mv$new( data = matrix(nrow=1,ncol=1))
-
 
256
## with a deep copy all is protected, with a shallow copy
-
 
257
## the environment of a copied field remains the same,
-
 
258
## but replacing the whole field should be local
-
 
259
stopifnot(identical(v1$text, letters),
-
 
260
          identical(v1$viewer, ff),
-
 
261
          identical(v2$text, "Hello, world"))
-
 
262
v3 <- v1$copy(TRUE)
-
 
263
v3$viewer$data <- t(xMat) # should modify v1$viewer as well
-
 
264
stopifnot(identical(v1$viewer$data, t(xMat)))
-
 
265
 
-
 
266
## the methods to extract class definition and generator
-
 
267
stopifnot(identical(v3$getRefClass(), mv),
-
 
268
          identical(v3$getClass(), getClass("viewerPlus")))
-
 
269
 
244
## deal correctly with inherited methods and overriding existing
270
## deal correctly with inherited methods and overriding existing
245
## methods from $methods(...)
271
## methods from $methods(...)
246
refClassA <- setRefClass("refClassA", methods=list(foo=function() "A"))
272
refClassA <- setRefClass("refClassA", methods=list(foo=function() "A"))
247
refClassB <- setRefClass("refClassB", contains="refClassA")
273
refClassB <- setRefClass("refClassB", contains="refClassA")
248
mnames <- objects(getClass("refClassB")@refMethods)
274
mnames <- objects(getClass("refClassB")@refMethods)