R6Object: Class: R6Object

Description Usage Format Methods Examples

Description

Base layer class for inheritance providing a number of methods that are often required in the context of using R6 classes.

Usage

1

Format

An R6Class generator object

Methods

.getComponentNames():

List the names of all components (regardless if field or method)

.getComponentClasses():

List the classes of all components (regardless if field or method)

.getFieldNames()

Returns the names of all fields that are not functions (i.e. methods)

.getMethodNames()

Returns the names of all methods

.getField(name, check, strict)

Internal getter method with validation (field name) with different strictness levels (argument strict).

.setField(name, value, check, strict)

Internal getter method with validation (field name and value class) with different strictness levels (argument strict).

.message(msg, id)

Signals the information in msg as a message. Argument id can be used to include more precise information in the message prefix

.warning(msg, id)

Signals the information in msg as a warning. Argument id can be used to include more precise information in the message prefix

.error(msg, id)

Signals the information in msg as an error as produced by stop. Argument id can be used to include more precise information in the message prefix

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
## Define example class that inherits from `R6Object` //
require(R6)
Test <- R6Class(
  classname = "Test",
  inherit = R6Object,
  public = list(
    field_1 = letters,
    field_2 = TRUE,
    field_3 = list(a = 1, b = 2),
    field_4 = data.frame(a = 1:3, b = 1:3),
    field_5 = 1.5,
    field_6 = as.integer(1),
    field_7 = NULL,
    field_8 = NA,
    foo = function() {
      super$.message("My message", id = "foo")
      "hello"
    },
    bar = function() {
      super$.warning("My warning", id = "bar")
      "world!"
    }
  )
)

## Instantiate //
inst <- Test$new()

## Inherited methods //
inst$.getComponentNames()
inst$.getComponentClasses()

inst$.getFieldNames()
inst$.getMethodNames()

inst$.message("Hello world!")
inst$.message("Hello world!", id = "abc")
inst$.warning("Hello world!")
inst$.warning("Hello world!", id = "abc")
inst$.error("Hello world!")
inst$.error("Hello world!", id = "abc")

inst$.getField("field_1")
inst$.getField("field_xyz")
inst$.getField("field_xyz", strict = 1)
inst$.getField("field_xyz", strict = 2)
inst$.getField("field_xyz", strict = 3)

inst$.setField("field_1", value = NA, strict = 3)
inst$.setField("field_1", value = NA, strict = 2)
## --> setting NOT blocked, so it went through with a warning:
inst$.getField("field_1")
inst$.setField("field_1", value = letters, strict = 1)

rappster/r6x documentation built on May 26, 2019, 11:55 p.m.