[Rd] Vector of S4 Objects

Paul Roebuck roebuck at odin.mdacc.tmc.edu
Mon Jul 25 19:40:16 CEST 2005

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:

         representation(id = "character",
                        x = "integer",
                        y = "integer"))
Foo <- function(id = "", x, y) {
        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)


SIGSIG -- signature too long (core dumped)

More information about the R-devel mailing list