[R] S4 slot containing either aov or NULL

Thomas Kaliwe hamstersquats at web.de
Wed Nov 26 16:18:33 CET 2008


Dear listmembers,

I would like to define a class with a slot that takes either an object 
of class aov or NULL. I have been reading "S4 Classes in 15 pages more 
or less" and "Lecture: S4 classes and methods"

#First I tried with list and NULL
setClass(listOrNULL")
setIs("list", "listOrNULL")
setIs("NULL", "listOrNULL")
#doesn't work

#defining a union class it works with list and null
setClassUnion("listOrNULL", c("list", "NULL"))
setClass("c1", representation(value = "listOrNULL"))
y1 = new("c1", value = NULL)
y2 = new("c1", value = list(a = 10))

#but it won't work with aov or null
setClassUnion("aovOrNULL", c("aov", "NULL"))
setClass("c1", representation(value = "aovOrNULL"))
y1 = new("c1", value = NULL)

#trying to assign an aov object to the slot doesn't work
utils::data(npk, package="MASS")
npk.aov <- aov(yield ~ block + N*P*K, npk)
y2 = new("c1", value = npk.aov )

Any ideas?

Thank you

Thomas Kaliwe



More information about the R-help mailing list