3

With regard to R Reference Classes, if we override the default $initialize() constructor, which is considered better practice to initialize fields: $initFields() or $callSuper()?

I've considered a few pros/cons:

  • If the default behaviour of $initialize() is changed/extended in some future version of R, $callSuper() will reflect those changes without having to add/rewrite code

  • There's nothing stopping you from calling $callSuper() twice in a single $initialize(). Is it officially documented/well-defined what happens in such a scenario?

mchen
  • 9,808
  • 17
  • 72
  • 125
  • Could you provide a simple example? – qed Aug 13 '14 at 15:21
  • It's a good question and it would be good to see it developed further. [tag:reference-class] subject is important but there is not much on it when compared to other R topics. Help in ?completeSubclasses` could be much more elaborate... – Konrad Dec 14 '18 at 14:00

0 Answers0