| Context | R Documentation |
Context objects allow Callback objects to access and modify data. The following packages implement context subclasses:
ContextOptimization in bbotk.
ContextEval in mlr3tuning.
ContextTorch in mlr3torch
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).
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.
new()Creates a new instance of this R6 class.
Context$new(id, label = NA_character_)
id(character(1))
Identifier for the new instance.
label(character(1))
Label for the new instance.
format()Format object as simple string.
Context$format(...)
...(ignored).
print()Print object.
Context$print()
clone()The objects of this class are cloneable with this method.
Context$clone(deep = FALSE)
deepWhether to make a deep clone.
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
# change content of column y to "C"
context$y = "C"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.