xRefClass-class: Extended Reference Class

Description Details Fields Methods Author(s) See Also Examples

Description

The Extended Reference Class (xRefClass) inherits directly from envRefClass. Listed are some of its key features:

Details

Extended Reference Class

Fields

.index

named_numeric indexes of args

.default

named_list default values of args

.meta

named_list additional args (meta information)

.envir

environment. Default: as.environment(.self)

.tmp.list

list for temporary storage

.out.list

list for outputting

Methods

copy2(shallow = FALSE)

Modified version of ‘copy’ to allow ‘activeBindingFunction’ as fields.

update(x)

Modify method definition without re-create the class instance. x: character, methods to be updated.

Author(s)

Xiaobei Zhao

See Also

methods::ReferenceClasses

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## Not run: 
MyClass <-
  setRefClass(
    "MyClass",
    list(
      x="numeric",
      y="numeric",
      z=function(){x+y}
      ),
    contains="xRefClass",
    methods=list(
      initialize=function(...){
        .idx <- c(x=1,y=2)
        callSuper(...,.index=.idx)
      },
      printme=function(){
        cat('Hello World!','\n')
      }
      )
    )

## Method initialize - pass by position
obj <- MyClass$new(1,2)
obj$x
obj$y

## Method initialize - pass by name
obj <- MyClass$new(y=2)
obj$x
obj$y

## Method copy
## obj <- MyClass$new(1,2)
## obk <- obj$copy()    # Fail!
## ## Error in (function ()  : unused argument (quote("myclass"))

## Method copy2
obj <- MyClass$new(1,2) # No such error!
obk <- obj$copy2()
obk$z

## Method update
obj <- MyClass$new()
obj$printme()
MyClass <- # To modify one of the original functions
  setRefClass(
    "MyClass",
    list(
      x="numeric",
      y="numeric",
      z=function(){x+y}
      ),
    contains="xRefClass",
    methods=list(
      initialize=function(...){
        .idx <- c(x=1,y=2)
        callSuper(...,.index=.idx)
      },
      printme=function(){ # This function is modified
        cat('Hello R!','\n')
      }
      )
    )
obj$printme() # The function is yet not modified
## Hello World!
obj$update("printme") # update the function
obj$printme() # The function is modified
## Hello R!

## End(Not run)

Xmisc documentation built on May 2, 2019, 8:23 a.m.