Skip to contents

See new_constrained_variable for constructor function.

Value

Formatted characters

Self instance

Self

Current value

See RAVEVariableConstraints

TRUE if valid, otherwise returns the error message

A list of constraint data that can be passed into $restore method

RAVEVariable instance

Public fields

name

Description of the variable

Active bindings

constraints

instance of RAVEVariableConstraints, used to validate the input

isRAVEVariable

always true

type

constraint type

value

value of the variable

initialized

whether value is missing (value might not be valid)

generator

class definition

Methods


Method new()

Constructor function

Usage

RAVEVariable$new(name = "Unnamed", initial_value)

Arguments

name

description of the variable

initial_value

initial value; default is an empty list of class "key_missing"


Method format()

Format method

Usage

RAVEVariable$format(prefix = NULL, ...)

Arguments

prefix

prefix of the string

...

ignored


Method use_constraints()

Set variable validation

Usage

RAVEVariable$use_constraints(constraints, .i, ...)

Arguments

constraints

either a character(1) or a RAVEVariableConstraints instance. When constraints is a string, the value will be the type of the constraint ( see new_constraints)

.i, ...

used when constraints is a string, either .i is an expression, or list(.i,...) forms a list of control parameters; see assertions in new_constraints.


Method set_value()

Set value

Usage

RAVEVariable$set_value(
  x,
  env = parent.frame(),
  validate = TRUE,
  on_error = NULL
)

Arguments

x

value of the variable

env

environment in which the validations will be evaluated

validate

whether to validate if x is legit; if set to TRUE and x is invalid, then the values will not be set.

on_error

a function takes two arguments: the error instance and old value; the returned value will be used to re-validate. Default is NULL, which is identical to returning the old value and stop on error.


Method get_value()

Get value

Usage

RAVEVariable$get_value(...)

Arguments

...

ignored


Method validate()

Check if the value is valid

Usage

RAVEVariable$validate(
  env = parent.frame(),
  on_error = c("error", "warning", "message", "muffle")
)

Arguments

env, on_error

passed to RAVEVariableConstraints$assert.


Method check()

Check if the value is valid with no error raised

Usage

RAVEVariable$check(env = parent.frame())

Arguments

env

environment to evaluate validation expressions


Method store()

Convert constraint to atomic list, used for serializing

Usage

RAVEVariable$store(...)

Arguments

...

ignored


Method restore()

Restores from atomic list generated by $store()

Usage

RAVEVariable$restore(x, env = parent.frame(), ...)

Arguments

x

atomic list

env

environment where to query the class definitions

...

ignored


Method clone()

The objects of this class are cloneable with this method.

Usage

RAVEVariable$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.