Hi,
This works fine.
>setClass("a",representation(b="list",c="list"))
>new("a",b=list(7))
>An object of class "a"
Slot "b":
[[1]]
[1] 7
Slot "c":
list()
But, now suppose you want a slot to accept an object of class formula...
>setClass("a",representation(b="list",c="formula"))
>new("a",b=list(7))
>Error in validObject(.Object) : invalid class "a" object: invalid object
for slot "c" in class "a": got class "NULL", should be or extend class
"formula"
Why can't new handle this? Why must the slot be defined?
If I call new without any named arguments, it works fine
> new("a")
An object of class "a"
Slot "b":
list()
Slot "c":
NULL
If I call new with only a formula, it works fine.
> new("a",c=formula(x~y))
An object of class "a"
Slot "b":
list()
Slot "c":
x ~ y
How can I get R to do this?
>setClass("a",representation(b="list",c="formula"))
>new("a",b=list(7))
An object of class "a"
Slot "b":
[[1]]
[1] 7
Slot "c":
NULL
Thanks,
Steve
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 1.1
year 2005
month 06
day 20
language R
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html