[R] problems trying to extend a class

Laurent Faisnel laurent.faisnel at ariase.com
Mon Sep 29 12:46:32 CEST 2003


Hi all,

I have been using for quite a long time a script where a class extends 
another one (without trouble). But I now have problems of that kind 
while trying to run the script :

Error in insertMethod(methods, sig, args, def, TRUE) :
         inserting method corresponding to empty signature

I think this may be because the way I wrote the scripts could be 
deprecated. Indeed I recently upgraded to R-1.7.1 (I compiled it from 
source). I use R on a RedHat 8.0 system.

This is how my classes look like :

#-----------------------------------------------------
# CLASS    Person
#-----------------------------------------------------

setClass("Person",representation(name="character"));

# CONSTRUCTOR

setMethod("initialize","Person",
           function(.Object)
           {
               .Object at name <- "Unknown"; # default name
               return(.Object);
           }
);

#-----------------------------------------------------
# CLASS    Employee           (extends Person)
#-----------------------------------------------------

setClass("Employee",representation("Person", service="character", 
con="MySQLConnection"));

# con : connection to be established with MySQL database

# constructor
setMethod("initialize","Employee",
           function(.Object)
           {
               .Object <- callNextMethod();  # calls the superclass 
constructor
             .Object at con <- dbConnect("MySQL");
             .Object at service <- "unknown service";
             return(.Object);
           }
);

The script just creates a new Employee and the error occurs when it 
comes to callNextMethod() :

 > library(RMySQL)
 > new("Person")
An object of class "Person"
Slot "name":
[1] "Unknown"
 >
 > new("Employee")
Error in insertMethod(methods, sig, args, def, TRUE) :
         inserting method corresponding to empty signature

Any help would be greatly appreciated.
Laurent

PS : I've read there's something related to this in R-1.7.1's new 
features, but it does not seem to match the problem exactly ("problems 
that used to wait until new() is called to appear are now caught 
properly"). Is the initialize() function deprecated ? Should I use 
prototype instead ?




More information about the R-help mailing list