R.oo (version 1.0.3)

DOLLAR< -.Class: Makes the fields and methods of an Class assignable via the $<- and the [[<- operator

Description

Makes the fields and methods of an Class assignable via the $<- operator. This method is never called explicitly, but through an indirect usage of the $<- operator, e.g. obj$name <- "foo".
  1. This method will first search for aset()method, e.g. if name has the value"age", asetAge()will be looked for. If such a method exists it will be called with the Class as the first argument andvalueas the second, e.g.setAge(this, value). Aget()is only looked for ifis not a private field. A private field is a namebeginningwith a.(period). The rational for this naming convention is to be consistent with howls()works, which will not list such members by default.
  2. If no such method exists it will assign thevalueto a (existing or a non-existing) field namedname.
Because any set() is called first, it is possible to encapsulate (hide away) fields with certain names or to put restrictions to what values can be assigned to them.

Usage

"$<-.Class"(this, name, value)
  "[[<-.Class"(this, name, value)

Arguments

name
The name of the code{set()} method or the name of the field to be assigned the new value.
value
The value to be assigned.
...
Not used.

Value

  • Returns itself, i.e. this, as all $<- methods must do.

See Also

For more information see Class.

Examples

Run this code
For a complete example see help(Class).

Run the code above in your browser using DataCamp Workspace