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

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -