Torsten Steuernagel wrote:

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.


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...

Uwe




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

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to