Why would you even want to mix these two paradigms?
I really love the design, simplicity and features of R6 classes. However, I also really like S4‘s method dispatching mechanism a lot: you can dispatch based on not just one, but multiple signature arguments.
Thus, sometimes you just want it all: use R6 instead of S4 classes, but they should also play nicely with/in S4 methods.
What do you need to do?
When you want to use instances of R6 classes as signature arguments of S4 methods, you need to create “formal S4 equivalents” for your R6 classes. Furthermore, you need to make sure that the S3 inheritance structure is correctly represented as well.
Let’s start out with some R6 class definitions:
require("R6") ClassA <- R6Class("ClassA", public = list(foo = function() "foo!")) ClassB <- R6Class("ClassB", inherit = ClassA, public = list(bar = function() "bar!"))
Continue reading “R6/S3 and S4: getting the best of both worlds”