r - How to define an S4 prototype for inherited slots -
i have base class (let's call "a") representation common many other classes.
therefore define other classes, such "b", contain class.
i set prototype of these other classes (b) include default values slots inherited a. thought natural:
setclass("a", representation(a="character")) setclass("b", contains="a", prototype(a = "hello")) but produces error:
error in representation[!slots] : object of type 's4' not subsettable not sure why happens. if omit prototype can do:
setclass("b", contains="a") and hack own generator function:
new_b <- function(...){ obj <- new("b", ...) obj@a = "hello" obj } and create object based on prototype new_b(), that's terribly crude , ugly compared using generic generator new("b") , having prototype...
you need name argument:
setclass("a", representation(a="character")) setclass("b", contains="a", prototype=prototype(a="hello"))
Comments
Post a Comment