I have a reference class Child
which inherits from parents SuperA
and SuperB
. When in the initialize
method of Child
, I would like to invoke the initialize
methods of both SuperA
and SuperB
in turn.
Thus, for instance, I have:
SuperA <- setRefClass("SuperA",
fields = list(a = "ANY"),
methods = list(
initialize = function(a) {
print(a)
initFields(a = a)
}
)
)
SuperB <- setRefClass("SuperB",
fields = list(b = "ANY"),
methods = list(
initialize = function(b) {
print(b)
initFields(b = b)
}
)
)
Child <- setRefClass("Child",
contains = c("SuperA", "SuperB"),
methods = list(
initialize = function(a, b) {
# attempt to invoke parent constructors one by one:
SuperA$callSuper(a)
SuperB$callSuper(b)
}
)
)
Child(1, 2) # want values 1 and 2 to be printed during construction of superclasses
However all I get is:
Error in print(a) : argument "a" is missing, with no default
So does anyone have any ideas on how to invoke a method belonging to a particular parent?