class_prototype: Prototype: a class to define prototypes of R objects

Description Usage Arguments Value Slots The Prototype class Using the class See Also

Description

A formal class to rigorously define prototypes of any R objects.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'missing,missing,missing'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,missing,missing'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,character,missing'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,environment,missing'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,character,character'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,environment,character'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,missing,call'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,character,call'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'ANY,environment,call'
Prototype(archetype, enclosure, constructor, ...)

## S4 method for signature 'Prototype'
show(object)

Arguments

archetype

any R object to be prototyped.

enclosure

an environment or a character naming a package.

constructor

a call or a character naming a function that can be used to generate a new archetype. If both enclosure and constructor are passed to Prototype(), it is implied that constructor is defined in enclosure.

...

further arguments used to construct a suitable call if constructor is a character. Else, it is unused.

object

a Prototype object.

Value

The constructor Prototype() returns an object of class Prototype.

The show() method returns NULL invisibly. It is used for its-effect.

Slots

archetype

any R object. A representation of the prototype that conveys the object's class.

enclosure

an environment in which the object's class is defined or NULL.

constructor

a call that can be used to generate an object of the same class as archetype or NULL.

The Prototype class

Class Prototype holds consistent prototypes of any R object. A consistent prototype theoretically has three components:

  1. a representation in R (here called an archetype);

  2. an enclosure (the environment holding the arechetype's class definition);

  3. a constructor function that generates the archetype.

The third component is needed because two different functions defined in the same enclosure can theoretically return two objects of the same class based on two different class definitions. In practice, this never happens, because it breaks R usual method dispatching mechanisms.

Using the class

The API is intentionally kept minimal, since the class is mostly intended to be used within class Schema.

See Also

Other Prototype: Prototype-accessors, Prototype-validators, is_prototype()


jeanmathieupotvin/cargo documentation built on Oct. 27, 2020, 5:22 p.m.