[R] S4 slot containing either aov or NULL

From: Thomas Kaliwe <hamstersquats_at_web.de>
Date: Wed, 26 Nov 2008 16:18:33 +0100

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

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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 26 Nov 2008 - 15:28:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Nov 2008 - 19:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive