Matthias Kohl
2005-Dec-06 12:36 UTC
[Rd] problems with initialize-method, difference between Win XP & Linux
Dear R devels, I have some questions concerning the use of "initialize". Situation: There are two packages "S4pkg1" and "S4pkg2" which include S4 classes and methods where the first one contains a new S4 class "S4pkg1Class". Then, in "S4pkg2" there is a new S4 class "S4pkg2Class" which has a slot of class "S4pkg1Class". Both packages have a namespace where I use exportClasses("S4pkg1Class") in the namespace of "S4pkg1" and import("S4pkg1") in the namespace of "S4pkg2". ############# 1. Solution: I provide a prototype argument in the definition of "S4pkg1Class" and use new("S4pkg1Class") in the prototype of "S4pkg2Class". Then, everything works fine under Windows XP and (Suse 9.3) Linux using R 2.2.0 and R 2.3.0 devel; i.e., calling "new("S4pkg2Class")" returns an object of class "S4pkg2Class" and the slot of class "S4pkg1Class" is filled with the corresponding prototype. ############# 2. Solution: I don't provide a prototype argument in the definition of "S4pkg1Class". Instead, I define an "initialize"-method for class "S4pkg1Class" with default arguments for the slots of "S4pkg1Class" and again I use "new("S4pkg1Class")" in the prototype of class "S4pkg2Class". Moreover, I use exportMethods("initialize") in the namespace of package "S4pkg1". Then, everything seems to work fine (at least on my PC) under Windows XP using R 2.2.0 and R 2.3.0 devel; i.e., calling "new("S4pkg2Class")" returns an object of class "S4pkg2Class" where the slot of class "S4pkg1Class" now is filled with the default object generated by the initialize-method of class "S4pkg1Class". However, under (Suse 9.3) Linux using R 2.2.0 and R 2.3.0 devel "new("S4pkg2Class")" returns an object of class "S4pkg2Class" where the slot of class "S4pkg1Class" is not filled with the default object generated by the initialize-method of class "S4pkg1Class" but with a "default-protoype" (slots are filled with "numeric(0)", "character(0)", ...). Can someone confirm this behavior? The sources of two sample packages can be found under: http://www.stamats.de/S4pkg1_0.1-1.tar.gz and http://www.stamats.de/S4pkg2_0.1-1.tar.gz After installation please try: require(S4pkg1) new("S4pkg1Class") # o.k., default values of initialize are used require(S4pkg2) new("S4pkg2Class") # is slot "pkg1" filled with the output of new("S4pkg1Class") given above??? Why does this work under Windows XP but not under (Suse 9.3) Linux? Am I doing something wrong - or is this a bug? Many thanks for any help! Matthias -- StaMatS - Statistik + Mathematik Service Dipl.Math.(Univ.) Matthias Kohl www.stamats.de
Reasonably Related Threads
- after package reorganization: version 1.6 of package "distr" available; new packages "distrEx", "distrSim", "distrTEst", "RandVar"
- after package reorganization: version 1.6 of package "distr" available; new packages "distrEx", "distrSim", "distrTEst", "RandVar"
- import of Namespaces
- Robust Asymptotic Statistics (RobASt)
- \S4method in combination with "[" and "[<-"