Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

extend.Object

Extends another class


Description

via a mechanism known as "parasitic inheritance". Simply speaking this method "extends another class". What is actually happening is that it creates an instance of class name ...className, by taking another Object instance and add ...className to the class list and also add all the named values in ... as fields to the new instance.

The method should be used by the constructor of a class and nowhere else.

Usage

## S3 method for class 'Object'
extend(this, ...className, ..., ...fields=NULL, ...envir=parent.frame(), ...finalize=NA)

Arguments

...className

The name of new class.

...

Named values representing the fields of the new instance.

...fields

An optional named list of fields. This makes it possible to specify a set of fields using a list object.

...envir

An environment.

...finalize

A logical controlling whether method *finalize() should be called on the Object when it is garbage collected or not. If TRUE, it will be called. If FALSE, it will not be called. If NA, it will be called according to argument finalize of the Object constructor.

Details

The reason for the strange name of argument "...className" is that if one tries to set a field with a name that is a prefix of the name of this arguments and one at the same time does not specify the name of this argument one would run into strange errors. For instance, try extend(Object(), "MyClass", ...c=0).

Value

Returns an Object of class className.

Field modifiers

It is possible to specify modifiers to some of the fields. Currently it is only the cached modifier that is recognized. A field that is cached will be assigned NULL when *clearCache() is called. To specify a modifier, append a comma separated list of modifiers followed by a colon, e.g. "cached:foo".

Author(s)

Henrik Bengtsson

See Also

For more information see Object.

Examples

## Not run: For a complete example see help(Object).

R.oo

R Object-Oriented Programming with or without References

v1.24.0
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.