I want to know the correct way to define class methods and a class variable in an R5 reference class.
Here is an example:
>
>
>
> XX <- setRefClass("XX",
+ fields = list(ma = "character"),
+ methods = list(
+ mfa = function() return(paste(ma, "*"))
+ ))
>
> XX
Generator object for class "XX":
Class fields:
Name: ma
Class: character
Class Methods:
"callSuper", "copy", "export", "field", "getClass", "getRefClass", "import", "initFields",
"mfa"
Reference Superclasses:
"envRefClass"
>
> x <- XX$new(ma="ma")
>
>
> x$mfa()
[1] "ma *"
>
>
> XX$cc <- "cc"
>
> ls(XX)
[1] "cc" "className" "def" "methods" "new"
>
> XX$methods(mfc = function() {
+ return(XX$cc)
+ })
>
> x$mfc()
[1] "cc"
XX$cc <- "cc"behaves as if it ccis a variable of class XX, but I'm not sure if this is the right way.
For example, XX $ def <- "hoge" can break a class XX generator.
So, I want to know if there is a standard way to define class variables and methods.
Thanks in advance.
source
share