Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 230
6.4.2 Important Methods and Attributes
ОглавлениеAll refclass object inherit from the same superclass envRefClass
, and so they get at creation some hidden fields and methods. For example, there is .self
. This variable refers to the object itself.
Other common methods for R5 objects that are always available (because they are inherited from envRefClass
) are the following, illustrated for an object of RC class named RC_obj
:
RC_obj$callSuper(): This method initializes the values defined in the super-class.
RC_obj$initFields(): This method initializes the values fields if the super-class has no initialization methods.
RC_obj$copy(): This method creates a copy of the current object. This is necessary because Reference Classes classes don't behave like most R objects, which are copied on assignment or modification.
RC_obj$field(): This method provides access to named fields, it is the equivalent to slots for S4. RC_obj$field(“xxx”) the same as RC_obj$xxx. RC_obj$field(“xxx”, 5), the same as assigning the value via RC_obj$xxx <- 5.
RC_obj$import(x): This method coerces x into this object, and RC_obj$export(Class) coerces a copy of RC_obj into that class.