From roebuck at odin.mdacc.tmc.edu  Mon Jul 25 19:40:16 2005
From: roebuck at odin.mdacc.tmc.edu (Paul Roebuck)
Date: Mon, 25 Jul 2005 12:40:16 -0500 (CDT)
Subject: [Rd] Vector of S4 Objects
Message-ID: <Pine.OSF.4.58.0507251156430.492475@odin.mdacc.tmc.edu>

Can someone show me how to create a vector of S4 objects
or point me to an example?

Reading Green Book 7.1.5 to me implied I could simply add
"vector" to my object's representation. But it also implied
that would have no change to the implementation of my class,
but I did find a .Data slot defined afterwards (as though
I had used "structure" instead). But I possibly just
misunderstood that section.

Given the following example class:

require(methods)
setClass("Foo",
         representation(id = "character",
                        x = "integer",
                        y = "integer"))
Foo <- function(id = "", x, y) {
    new("Foo",
        id = id,
        x = as.integer(x),
        y = as.integer(y))
}

Would prefer to internalize such that "Foo" contained
a vector of its representation but something like this
would be a compromise if that's easier to implement.

foo.vec <- vector("Foo", 2)
foo.vec[1] <- Foo("first",1,2)
foo.vec[2] <- Foo("second",3,4)


TIA

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



[Rd] Vector of S4 Objects
Paul Roebuck