[Rd] Lost in S4 and S3 classes

From: Davide Rambaldi <davide.rambaldi_at_ieo.eu>
Date: Wed, 12 Dec 2012 14:51:33 +0100


Hi all, this is my first post in R devel… sorry if I lost some of the guidelines.

Anyway this is my problem:

Version:

R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

I want to make an S4 class that use the output object of the function of nls.lm as a slot:

setOldClass("nls.lm")

setClass (
  Class="TestClass",
  representation=representation(

      lmOutput = "nls.lm",
      anumeric = "numeric"

    )
  )

Now, if I want to call this class in a "constructor function" I can do something like this (correct?):

myConstructor <- function()
{
  return(new("TestClass"))
}

pippo <- myConstructor()

> pippo

An object of class "TestClass"
Slot "lmOutput":
<S4 Type Object>
attr(,".S3Class")
[1] "nls.lm"

Slot "anumeric":
numeric(0)

And the object "pippo" seems correctly initialized.

If I use this code instead I got an error:

myConstructor2 <- function()
{
  pippo <- new("TestClass", anumeric=1000)   return(pippo)
}

> pippo <- myConstructor2()

Error in validObject(.Object) :
  invalid class “TestClass” object: invalid object for slot "lmOutput" in class "TestClass": got class "S4", should be or extend class "nls.lm"

Seems that if I want to INIT in new some slots, this create problem with a S3 Class slot?

Any clue on how to avoid this problem?

Thanks



PLEASE NOTE MY NEW EMAIL ADDRESS


Davide Rambaldi, Bioinformatics PhD.

IEO ~ MolMed
[e] davide.rambaldi_at_ieo.eu
[e] davide.rambaldi_at_gmail.com

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 13 Dec 2012 - 11:32:26 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Thu 13 Dec 2012 - 14:32:48 GMT.

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

list of date sections of archive