[Rd] S4 class extending data.frame?
bolker at ufl.edu
Thu Dec 13 06:04:41 CET 2007
-----BEGIN PGP SIGNED MESSAGE-----
I would like to build an S4 class that extends
a data frame, but includes several more slots.
Here's an example using integer as the base
z1 = new("c1",55,comment="hello")
z1 at comment
-- in other words, it behaves exactly as an integer
for access and operations but happens to have another slot.
If I do this with a data frame instead, it doesn't seem to work
d = data.frame(1:3,2:4)
z2 = new("c2",d,comment="goodbye")
z2 ## data all gone!!
z2[,1] ## Error ... object is not subsettable
z2 at comment ## still there
I can achieve approximately the same effect by
adding attributes, but I was hoping for the structure
of S4 classes ...
Programming with Data and the R Language Definition
contain 2 references each to data frames, and neither of
them has allowed me to figure out this behavior.
(While I'm at it: it would be wonderful to have
a "rich data frame" that could include as a column
any object that had an appropriate length and
[ method ... has anyone done anything in this direction?
?data.frame says the allowable types are
"(numeric, logical, factor and character and so on)",
but I'm having trouble sorting out what the limitations
hoping for enlightenment (it would be lovely to be
shown how to make this work, but a definitive statement
that it is impossible would be useful too).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the R-devel