Description Usage Arguments Value Author(s) References See Also Examples
Takes a regular R6 class definition and does the following things with it:
Evaluate the class definition (main effect)
Extract and store S3 class graph (i.e. including inheritance structure) in
a special options
environment. This information can in
turn be processed by formalizeClasses
inside your
package's call to .onLoad
in order to produce S4
equivalents of your R6 classes
1 2 | withFormalClass(def, envir = parent.frame(), auto_assign = FALSE,
r6 = TRUE)
|
def |
Actual R6 class definition, i.e. a call to |
envir |
|
auto_assign |
|
r6 |
|
Return value of R6Class
.
Janko Thyson janko.thyson@gmail.com
http://github.com/rappster/r6x
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 58 59 60 61 62 63 64 | ##------------------------------------------------------------------------------
## Class without inheritance
##------------------------------------------------------------------------------
## Ensure clean initial state //
if (exists("Test")) {
rm("Test")
}
exists("Test")
getOption(".classes")
## Define R6 class //
Test <- withFormalClass(
R6Class(
classname = "Test",
portable = TRUE,
public = list(
foo = function() "hello world!"
)
)
)
## Investigate state after definition //
exists("Test")
Test
ls(getOption(".classes"))
getOption(".classes")$Test
## --> buffered S3 class information that is later used by `formalizeClasses()`
## Auto-assign //
rm(Test)
withFormalClass(
R6Class(
classname = "Test",
portable = TRUE,
public = list(
foo = function() "hello world!"
)
),
auto_assign = TRUE
)
## --> note that the class generator object is automaticall assigned to `Test`
exists("Test")
Test
##------------------------------------------------------------------------------
## Class with inheritance
##------------------------------------------------------------------------------
Test2 <- withFormalClass(
R6Class(
classname = "Test2",
portable = TRUE,
inherit = r6x::Test,
public = list(
bar = function() "hello world!"
)
)
)
## Inspect buffered S3 class information //
ls(getOption(".classes"))
getOption(".classes")$Test2
## --> S3 inheritance graph
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.