I don't have any experience with R reference classes but using the help of ?ReferenceClasses
you can read the following:
Initialization methods need some care in design, as they do for S4 classes. Therefore, your method should normally include ... as an argument, all other arguments should have defaults or check for missingness, and your method should pass all initialized values on via $callSuper() or $initFields() if you know that your superclasses have no initialization methods.
So I understand this by setting my initialization function in the parent class using ... and named parameters for all fields with a default values.
Template <- setRefClass('Template',
fields = list(params="list"),
methods = list(initialize =
function(...,params=list(1:5)){
callSuper(...,params=params)
validate_params()
},
validate_params = function(){
"everything okay"
}
)
)
For the sub-Class no need to initialize parameters since I am sure that super class will dot it.
PointsTemplate <- setRefClass('PointsTemplate',
contains = "Template",
methods = list(initialize =
function(...){
callSuper(...)
}
))
No testing the initialization:
## using default values
> PointsTemplate$new()
Reference class object of class "PointsTemplate"
Field "params":
[[1]]
[1] 1 2 3 4 5
## setting params
PointsTemplate$new(params=list(1:10))
Reference class object of class "PointsTemplate"
Field "params":
[[1]]
[1] 1 2 3 4 5 6 7 8 9 10