Create a new dsproto object

Share:

Description

dsproto draws from the prototype implementation in ggplot2, which in turn is inspired by the ggplot2's implementation, with improvements in inheritance and performance. The ggplot2 implementation is copyright by Hadley Wickham and Winston Chang, and released under GPLv2.

Convert a dsproto object to a list This will not include the object's super member.

Format a dsproto object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
dsproto(`_class` = NULL, `_inherit` = NULL, ...)

dsproto_parent(parent, self)

## S3 method for class 'dsproto'
print(x, ..., flat = TRUE)

## S3 method for class 'dsproto'
format(x, ..., flat = TRUE)

## S3 method for class 'dsproto_method'
print(x, ...)

## S3 method for class 'dsproto_method'
format(x, ...)

Arguments

_class

Class name to assign to the object. This is stored as the class attribute of the object. If NULL (the default), no class name will be added to the object.

_inherit

dsproto object to inherit from. If NULL, don't inherit from any object.

...

A list of members in the dsproto object.

parent, self

Access parent class parent of object self.

x

A dsproto object to convert to a list.

inherit

If TRUE (the default), flatten all inherited items into

...

Further arguments to pass to as.list.environment.

Calling dsproto methods

dsproto methods can take an optional self argument: if it is present, it is a regular method; if it's absent, it's a "static" method.

Calling methods in a parent

To explicitly call a methods in a parent, use dsproto_parent(Parent, self).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#Create a class called "dog"
doggy <- dsproto(`_class` = "dog", `_inherit` = NULL)
#Add children to the parent class "dog". Then add members.
GS <- dsproto(`_class` = "German Shephard", `_inherit` = doggy,
        name = "Pedro",
        color = "Brown",
        personality = "Friendly",
        age = 1,
        parents = list("Spot", "Alfred"),
        birthday = function(self) self$age = self$age + 1)
#Call those members
GS$color
GS$age
#Call a function member
GS$birthday()
#Happy Birthday to Pedro! Your dog is now 2! Let's see what the age returns
GS$age

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.