ref: Create a reference to R object

Description Usage Arguments Examples

Description

Create a ref as a wrapper of a given object. A ref is essentially a wrapper environment of the object.

Usage

1
ref(object = NULL, constraint = NULL)

Arguments

object

The object.

constraint

a function to validate the value in each update of the object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# create a NULL ref
ref()

# create a ref of an integer vector
x <- ref(1:10)
x[1]
x[5] <- 10L

# create a ref with constraint of an integer vector
x <- ref(1:10, is.integer)
x[1]
x[5] <- 10L
# x[5] <- "a" will corece 1:10 to character vector
# but violates is.integer contraint, leading to a stop.

renkun-ken/reflite documentation built on May 27, 2019, 5:50 a.m.