[R] Inheriting from factors + co.

Torsten Steuernagel Torsten.Steuernagel at gmx.de
Tue Feb 24 22:34:13 CET 2004


On 24 Feb 2004 at 21:38, Uwe Ligges wrote:

> > setClass("myclass", representation("ANY", x = "numeric", y
> > ="numeric"))
> > 
> > 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.
 
> 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.

Thanks,

Torsten




More information about the R-help mailing list