Description Usage Arguments Author(s) References See Also Examples
Creates R6 class generator objects on the fly.
1 | createR6Class(input, name = ".DerivedInternal", lazy = FALSE)
|
input |
|
name |
|
lazy |
|
Janko Thyson janko.thyson@rappster.de
http://github.com/rappster/classr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | ##------------------------------------------------------------------------------
## Default input //
##------------------------------------------------------------------------------
## This is ideal for rapid prototyping. All list elements are mapped to
## publicly available fields.
inst <- createR6Class(input = list(x = 1, y = 2))
inst
##------------------------------------------------------------------------------
## Special input format //
##------------------------------------------------------------------------------
## For more fine control over the class structure.
input <- list(
public = list(x = 10, foo = function() private$bar()),
private = list(bar = function() "Hello World!"),
active = list(
x2 = function(value) {
if (missing(value)) return(self$x * 2) else self$x <- value/2
}
)
)
## To see what's actually going on:
(inst <- createR6Class(input))
(inst <- inst$new())
inst$x
inst$foo
inst$foo()
inst$x2
inst$x2 <- 100
inst$x
##------------------------------------------------------------------------------
## Return expression //
##------------------------------------------------------------------------------
## Useful for lazy evaluation
(inst <- createR6Class(input, lazy = TRUE))
(inst <- eval(inst))
(inst <- inst$new())
##------------------------------------------------------------------------------
## Explicit name //
##------------------------------------------------------------------------------
createR6Class(input, name = "TestClass")
##------------------------------------------------------------------------------
## Empty //
##------------------------------------------------------------------------------
createR6Class(lazy = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.