I'm trying to set the params
field and validate it in the Template class, so I can do TemplateClass$new(params)
and it automatically validates, but I get an error:
Template <- setRefClass('Template',
fields = c(
"params"
),
methods = list(
initialize = function(params){
params <<- params
validate_params()
},
validate_params = function(){
"everything okay"
}
)
)
PointsTemplate <- setRefClass('PointsTemplate',
contains = "Template",
methods = list(
initialize = function(params){
callSuper(params)
}
)
)
Error in .Object$initialize(...) :
argument "params" is missing, with no default
EDIT: I seemed to have solved it by changing the initialize
method in the Template
class to initialize = function(params = NULL){}
. But I don't understand why this is needed.
Also, I've seen other people use callSuper()
when the class doesn't contain any super classes. What is the reason for this?