setRefClass: Fetch all necessary information to construct a reference...

Description Usage Arguments Details Value

Description

Fetch all necessary information to construct a reference class generator function.

Reference class objects are the closest approximation of the concepts of object-oriented programming available in R. While S3 and S4 classes serve the useful purpose of providing dispatching mechanisms on generic functions, reference classes allow for mutability of data on the underlying object regardless of calling convention (or nasty syntax like replace methods).

Usage

1
2
3
4
ref_class_information(Class, contains, fields, refMethods, where)

setRefClass(Class, fields = character(), contains = character(),
  methods = list(), where = topenv(parent.frame()), ...)

Arguments

refMethods

list. A named list of reference class methods.

Class

character. The name of the newly created reference class.

fields

character. The field for the reference class. Fields are equivalent to "members" in other languages, and can represent any data. In this particular case, the convention is something like list(id = "numeric", data = "data.frame") to specify two fields, id and data with required types numeric and data.frame. The default is character().

contains

character. The parent reference classes of this reference class. The default is character(). # TODO: (RK) Document this behavior better.

methods

list. The methods for instances of this reference class. In particular, the names of this list represent the names of the methods, and the values must be functions. For example, list(foo = function(x) print(x) would define a method foo that we could call with reference_class_object$foo(...). The default is to default is to define no methods (list()).

where

environment. Where to store the definition of the reference class. The default is topenv(parent.frame()).

...

additional arguments to the setClass function call that gets called under the hood. (Note that a reference class generator is an extension of a classGeneratorFunction in the S3 sense.)

Details

# TODO: (RK) More description here.

Value

the fully formed reference class object generator. For example, if we call x <- setRefClass(...), then we can call x$new(...) to invoke the constructor for the object x. The class of the reference class object generator is "refObjectGenerator". # TODO: (RK) More documentation and examples.


robertzk/refclass documentation built on May 27, 2019, 10:36 a.m.