R cannot declare setClass with inheritance -


removeclass("a") setclass('a',representation=representation(a="numeric"))  setmethod('initialize','a', function(.object,...,a){  .object@a=a .object }) 

ok here

removeclass("b")  setclass('b',representation=representation(b="numeric"),contains="a") 

this code fails on definition of class "b" , without had chance add initialize method "b", , without create object

error in .local(.object, ...) : argument "a" missing, no default

it not fail if add default value parameter in initialize.a method

can explain why ?

"why" tricky question, answer being "because" it's implemented way. if you're asking needs done avoid this, answer either (a) provide default value argument a in constructor or (b) avoid using initialize method. there discussion here. implicit contract new("a") succeeds,


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -