Skip to contents

Context objects allow Callback objects to access and modify data. The following packages implement context subclasses:

Details

Context is an abstract base class. A subclass inherits from Context. Data is stored in public fields. Access to the data can be restricted with active bindings (see example).

Public fields

id

(character(1))
Identifier of the object. Used in tables, plot and text output.

label

(character(1))
Label for this object. Can be used in tables, plot and text output instead of the ID.

Methods


Method new()

Creates a new instance of this R6 class.

Usage

Context$new(id, label = NA_character_)

Arguments

id

(character(1))
Identifier for the new instance.

label

(character(1))
Label for the new instance.


Method format()

Format object as simple string.

Usage

Context$format(...)

Arguments

...

(ignored).


Method print()

Print object.

Usage

Context$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

Context$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(data.table)
library(R6)

# data table with column x an y
data = data.table(x = runif(10), y = sample(c("A", "B"), 10, replace = TRUE))

# context only allows to access column y
ContextExample = R6Class("ContextExample",
  inherit = Context,
  public = list(
    data = NULL,

    initialize = function(data) {
        self$data = data
    }
  ),

  active = list(
    y = function(rhs) {
      if (missing(rhs)) return(self$data$y)
      self$data$y = rhs
    }
  )
)

context = ContextExample$new(data)

# retrieve content of column y
context$y
#>  [1] "B" "A" "A" "A" "A" "B" "A" "A" "B" "B"

# change content of column y to "C"
context$y = "C"