pproto: Create a new pproto object

Description Usage Arguments Examples

Description

Construct a new object with pproto. This object system is inspired from the ggproto system used in the ggplot2 package.

Usage

1
pproto(`_class` = NULL, `_inherit` = NULL, ...)

Arguments

_class

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

_inherit

ggproto object to inherit from. If NULL, don"t inherit from any object.

...

A list of members in the pproto object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
Adder <- pproto("Adder",
  x = 0,
  add = function(self, n) {
    self$x <- self$x + n
    self$x
  }
)

Adder$add(10)
Adder$add(10)

Abacus <- pproto("Abacus", Adder,
  subtract = function(self, n) {
    self$x <- self$x - n
    self$x
  }
)
Abacus$add(10)
Abacus$subtract(10)

prioritizr/prioritizrutils documentation built on May 25, 2019, 12:20 p.m.