2

(first post to Stack Overflow so maybe I didn't post where/how I should, sorry)

TL;DR : How do I make this specific inheritance scheme in R6 :

             MOTHER                       (MOTHER is a virtual class)
            /  |  \   
           /   |   \  
          /    |    \  
         /     |     \
Daughter1     Son     Daughter2           (Son is a virtual class)
    \         / \         /
     \       /   \       /
      \     /     \     /
       \   /       \   /
       Incest1     Incest2                (Incestuous but no diamond issues)

The same scheme is available is S4, I did it and I'm actually trying to convert my S4 classes to references R6 ones. But the documentations on R6 classes is not that big, and I can't find how to do it.

If that's not possible, I'm going to have to duplicate a lot of code, i.e. all methods from "Son", and I don't want to do that.

I've called the last 2 classes Incest to joke, but I'm serious : I got no diamond issue here, the methods provided by the Daughter's and the Son are not the same at all.

If you think about an other scheme that could work to replace this one, I'd love to hear it : The MOTHER and Son Classes are VIRTUAL ( which is not really doable in R6 right? but I don't care), so maybe I'm not thinking the inheritance issue as it should be.

Thx for the help.

** EDIT : **

Ok I've found a solution. Since Incest's are fully functional Son's and Daughter's (since they ARE sons and daughters), when not just re-build the multiple inheritance mechanism in them ? That is :

1° For every function that Son's don't have and need to inherit, build a wrapper method with the same name in son where you call a generic coercice() method.

2° The coercise method just does what R6 should do : it initialize a "Son" element and a "Daughter" element, and check for both of them is the method that we passed as argument exist. If it does for only one, let's go they call it with this coercised Incest that's now a Son or a daughter. If both implement it, it yells at me (but it could do something else !)

It's very ugly, but it work and does what I wanted to do.

Actually, it's not that ugly, it's just implementing something that should be. Do you think this could have been done a better way?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
lrnv
  • 1,038
  • 8
  • 19
  • I think the multiple inheritance isn't possible in R6 classes. So there might be no way to get the incest :-) working. But there might be people with more background on this then I (and I am talking about inheritance in `R6`) – drmariod Aug 08 '17 at 06:07
  • Yeah i'm talking about inheritance in R6 too. But i think there's maybe a way using multiple inheritance from S3/S4 classes and the fact that R6classes define automaticaly S3classes too. So any member of a R6 class is a member of the coresponding S3 class, and S3 inheritances can be setted up by **setoldclass** command. I didnt test it yet, i didnt made it work, but maybe there is a way. – lrnv Aug 08 '17 at 18:03

0 Answers0