R: Change the fields' (slots') values of the class assigning a value to some other field
- by Max Li
Assgning a value to one field, how can I make the other fields changing.
Consider the following R5 class
C<-setRefClass("C",
fields=list(a="numeric",b="numeric")
, methods=list(
seta = function(x){
a<<-x
b<<-x+10
cat("The change took place!")
}
) # end of the methods list
) # end of the class
Now create the instance of the class
c<-C$new()
This command
c$seta(10)
will result in that c$a is 10 and c$b is 20.
So it actually works, however, I want to achieve this result by the command
c$a<-10
(i.e. after that I want c$b to be equal to 20 as defined in the class in the logic of seta() function)
How can I do it?