Class("person",representation(age="numeric",weight="numeric")) [1] "person"> bob <- new("person",age=30) > is.null(bob at weight)[1] FALSE> bob at weightnumeric(0)> bob at weight == numeric(0)logical(0) How can i test to see if a s4 property is assigned? -- View this message in context: http://r.789695.n4.nabble.com/test-to-see-if-a-s4-property-is-assigned-tp2541044p2541044.html Sent from the R help mailing list archive at Nabble.com.
On 09/15/2010 12:03 PM, darckeen wrote:> > Class("person",representation(age="numeric",weight="numeric")) > [1] "person" >> bob <- new("person",age=30) >> is.null(bob at weight) > [1] FALSE >> bob at weight > numeric(0) >> bob at weight == numeric(0) > logical(0)Hi darckeen -- use the prototype argument to setClass to assign a default value, and test for that. Martin> > How can i test to see if a s4 property is assigned? >
>setClass("person",representation(age="numeric",weight="numeric"),prototype(age=NULL,weight=NULL)) [1] "person"> bob <- new("person",age=30)Error in validObject(.Object) : invalid class "person" object: invalid object for slot "weight" in class "person": got class "NULL", should be or extend class "numeric" So I guess I can only protoype a property to NULL if its defined as ANY? I though there might be a way to test if a propery was assigned to get around this. Really kinda turns me off from S4 classes :\ -- View this message in context: http://r.789695.n4.nabble.com/test-to-see-if-a-s4-property-is-assigned-tp2541044p2542958.html Sent from the R help mailing list archive at Nabble.com.