[R] Inheriting from factors + co.
ligges at statistik.uni-dortmund.de
Wed Feb 25 10:00:24 CET 2004
Torsten Steuernagel wrote:
> On 24 Feb 2004 at 21:38, Uwe Ligges wrote:
>>>setClass("myclass", representation("ANY", x = "numeric", y
>>>new("myclass", 1:10) # works
>>>new("myclass", "Test") # works
>>>new("myclass", factor(1:10)) # fails
>>Why do you think it fails?
> I was typing faster than thinking. It doesn't actually fail but what I get is
> a numeric vector with a levels attribute. If I specify a factor as .Data
> part I expect that the created object IS a factor and
> is.factor(new("myclass", factor(1:10))) returns TRUE.
So you are going to handle/mix the S4 class like/with S3 classes?
Hmm. It can be either of class "myclass" or of class "factor".
I'd define a separate explicit slot for such a class:
setClass("myclass", representation(mainSlot = "ANY",
x = "numeric", y = "numeric"))
John Chambers might want to correct me...
>>It works perfectly for me with R-1.8.1 for Windows.
>>You haven't told anything about your R version, I suspect your are
>>using an outdated one.
> Sorry, forgot that one. I'm also using R 1.8.1 on Windows.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help