[R] S4 Classes, nested objects and references

Joris Meys jorismeys at gmail.com
Thu Dec 3 15:49:35 CET 2009


Hi all,

I'm currently programming my first complete package in S4. (thanks to
Christophe Genolini for the nice introduction he wrote). I have an
object "Data" with a number of slots. One of those slots is "meteo".
Now "Meteo" is on itself a class with again a number of slots (like
rainfall, temperature,..., you get the picture).

I defined the slot "meteo" currently as a character slot, and the
values refer to the names of the Meteo-objects related to that
Data-object. The cleaner way would be to define the slot "meteo" as a
slot of class "Meteo", but I'm not sure how that works internally.

Thing is, I have multiple Data objects that refer to the same Meteo
object. I am a bit afraid that when I define the slot meteo as a slot
of the corresponding class, each Data object will contain a complete
copy of the Meteo object it relates to. This would mean that in the
memory I will end up with multiple copies of exactly the same data.
Although it is cleaner, it is definitely not more efficient.

My question : Am I wrong in my assumption that I will have multiple
copies in the memories? If yes, is it possible to use references in a
more formal way than I do now? Or is there an obvious solution I am
missing here?

Thank you in advance
Cheers
Joris




More information about the R-help mailing list