Description Usage Arguments Calling dsproto methods Calling methods in a parent Examples
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
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, ...)
|
_class |
Class name to assign to the object. This is stored as the class
attribute of the object. If |
_inherit |
dsproto object to inherit from. If |
... |
A list of members in the dsproto object. |
parent, self |
Access parent class |
x |
A dsproto object to convert to a list. |
inherit |
If |
... |
Further arguments to pass to |
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.
To explicitly call a methods in a parent, use
dsproto_parent(Parent, self)
.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.