Create a new ggproto object

ggproto is inspired by the proto package, but it has some important differences. Notably, it cleanly supports cross-package inheritance, and has faster performance.

ggproto(`_class` = NULL, `_inherit` = NULL, ...)
ggproto_parent(parent, self)
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.
ggproto object to inherit from. If NULL, don't inherit from any object.
A list of members in the ggproto object.
parent, self
Access parent class parent of object self.
Calling ggproto methods

ggproto 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 (i.e. it doesn't use any fields). Imagine you have a ggproto object Adder, which has a method addx = function(self, n) n + self$x. Then, to call this function, you would use Adder$addx(10) -- the self is passed in automatically by the wrapper function. self be located anywhere in the function signature, although customarily it comes first.

Calling methods in a parent

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

  • ggproto
  • ggproto_parent
Documentation reproduced from package ggplot2, version 2.1.0, License: GPL-2

Community examples

Looks like there are no examples yet.