Learn R Programming

oops (version 0.2.0)

init: Initialize Class Instance

Description

Function called on oClass instance when it is created. Users create init methods to customize creation behavior for their Classes. All init methods should return the Instance. init_next calls the objects next init methods. init_next should only be used inside if init.

Usage

init(x, ...)

init_next(x, ...)

Arguments

x

environment of class "Instance"

...

named fields inherited by the class instance or passed to methods

Value

environment of class "Instance"

Functions

  • init_next: Initialize the inherited Class.

Examples

Run this code
# NOT RUN {
Animal <- oClass("Animal")

init.Animal <- function(self, x, y){
  self$x <- x
  self$y <- y
  self
}

turtle <- Animal(5, 10)
turtle$x == 5    # TRUE
turtle$y == 10   # TRUE


# }

Run the code above in your browser using DataLab