Description Usage Arguments Details Value Recommendation Author(s) References See Also Examples
Takes the S3 class information buffered in getOption(".classes")
and
uses it accordingly for calls to setOldClass
.
1 2 3 | formalizeClasses(where = eval(substitute(as.environment(NAME), list(NAME =
sprintf("package:%s", as.list(read.dcf("DESCRIPTION")[1, ])[["Package"]])))),
overwrite = TRUE, clean_up = TRUE)
|
where |
|
overwrite |
|
clean_up |
|
The S4 equivalents are assigned to the package's namespace if it is available
(i.e. as.environment("package:<package-name>")
). This is definitely
the case at the stage when .onLoad
is calles, hence the
call to this function should happen there.
Return value of R6Class
.
It seems to be a good advice to set overwrite = TRUE
as this ensures
that previously defined S4 equivalents are removed prior to the respective
calls to setOldClass
. Not doing so seems to have the
undesired side effect that
getClasses(where = as.environment("package:<package-name>"))
returns
character()
for subsequent package loads via
load_all
(and thus subsequent calls of
.onLoad
).
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 | ##------------------------------------------------------------------------------
## Stand-alone call
##------------------------------------------------------------------------------
##########
## NOTE ##
##########
## This example only serves the purpose of illustrating what's going on.
## In order for this function to be actually useful when developing own
## packages, it should be called inside `.onLoad()` (see example below)
## Preliminaries //
## Run example of `?withFormalClass`
## Buffered S3 class information //
clss <- getOption(".classes")
ls(clss)
lapply(ls(clss), function(ii) clss[[ii]])
## Note //
## Currently, there are no formal S4 equivalents for our R6 classes yet:
isClass("Test")
isClass("Test2")
try(getClass("Test"))
try(getClass("Test2"))
## Formalize classes //
formalizeClasses()
## Note //
## 1) Formal S4 equivalents have been created:
isClass("Test")
isClass("Test2")
try(getClass("Test"))
try(getClass("Test2"))
## --> note how the S3 inheritance information has been preserved
## 2) The buffered information has been deleted due to `clean_up = TRUE`:
getOption(".classes")
##------------------------------------------------------------------------------
## Call inside of `.onLoad()`
##------------------------------------------------------------------------------
##########
## NOTE ##
##########
## This function should be called in `.onLoad()` as at this stage the package
## has already been attached and thus a namespace environment has been created.
## This environment is the recommended value for the function's `envir`
## argument (automatically set, you don't need to provide it explicitly)
## So this is a template of how your `.onLoad()` function should look like
## when using this function. Just copy it to a file inside your `R` directory
## so it is picked up by `devtools::load_all()` or the like:
.onAttach <- function(libname, pkgname) {
formalizeClasses()
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.