2
removeClass("A") setClass('A',representation=representation(a="numeric")) setMethod('initialize','A', function(.Object,...,a){ .Object@a=a .Object }) 

ok up to here

removeClass("B") setClass('B',representation=representation(b="numeric"),contains="A") 

This code fails on the definition of class "B" , without I had any chance to add an initialize method for "B", and without I even create any object

Error in .local(.Object, ...) : argument "a" is missing, with no default

It does not fail if I add a default value for the a parameter in initialize.A method

Can anyone explain why ?

2
  • Isn't "It does not fail if I add a default value for the a parameter in initialize.A method" the solution? Maybe you want to have a look at: stackoverflow.com/questions/18197214/… Commented Aug 28, 2013 at 14:08
  • the strange thing is merely adding the line setClass... without even creating an object triggers the error. And suppose I am reusing code that I subclass, I am not going to modify it Commented Aug 28, 2013 at 14:32

1 Answer 1

1

"why" is a tricky question, with the answer being "because" it's implemented that way. If you're asking what needs to be done to avoid this, the answer is to either (a) provide a default value to the argument a in the constructor or (b) avoid using an initialize method. There is some discussion here. The implicit contract is that new("A") succeeds,

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Having read the discussion, looks like it's best to simply avoid initialize methods with inheritance

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.