[Rd] Some more help on S4 mechanism

Renard Didier didier.renard at mines-paristech.fr
Mon Mar 22 13:31:02 CET 2010


Hello to the list

Some days ago, I placed a question on this maling-list and received an 
answer from Martin
that I tried to follow. Unfortunately, I am still puzzled by the next step.
I spent the whole Week-end in gathering information from the net.
Some of them are almost contridtcory and I lack a good document to help me.
So my first question would beL Is there a convenient document which tells
a standard user, who laready developped a package with S3, on how to migrate
to the S4 mechanism.

Secondly, this is my problem:
According to Martin, now I use a NAMESPACE (as follows):

import (methods)
exportPattern("^[^0]*$")
exportMethods(
        "[","[<-","$","$<-",
        "plot","print"
)
exportClasses(
        "anam","db","model","rule","vardir","vario","tokens","thresh"
)
useDynLib("RGeoS")
importFrom(graphics,plot)

More over, in the R directory, I have a zzz.lib with the following 
contents (.onLoad) :

".onLoad" <-
function(...)
{

        # Define the Classes #
        All0.Classes()

        # Define the environment variables #
        environ.load()
}

The file All0.Classes (which will not be exported ... see exportPattern) 
contains
all the class definitions (setClass functions)

Finally, I have some other functions, such as db.plot, which contain the 
following statement
(at the end of the file):

setMethod("plot", signature(x="db"), function(x,y,...) db.plot(x,...))

My questions:
- Should the setMethods be regrouped in a single file (as I read from 
the net).
- What are the differences between "R CMD check" and "R CMD INSTALL" as 
far as the steps are involved.

As a matter of fact:
- R CMD check finds that everything is OK
- R CMD INSTALL gives me a set of warnings of the following type:

Warning in matchSignature(signature, fdef, where) :
  in the method signature for function "[<-" no definition for class: "db"
I did not use the Collate option (that Martin suggested) as I am not 
sure of its syntax and where I should add these statements.

The package works fine anyhow but I would like to correct these warnings.

By the way, as I belong to an institute where we use Fedora Core 8, I am 
stuck with R 2.8.0.

An ultimate problem: I develop two packages P1 and P2 where P2 requires P1.
So I used the same architecture for both with NAMESPACE and .onLoad 
functions (in the zzz.lib files).

For P2, I mention that it depends upon P1 in the DESCRIPTION file. This 
information seems redundant with the NAMESPACE where I can add 
"import(P1)". Finally when, as a user, I load both by library() (first 
P1 then P2), I receive a message about function .onLoad being loaded twice.

How can I avoid this.

As you can see, I encountered several problems when converting my S3 
into S4. I would appreciate if someone could give me a complete 
information and a godd reference.

Thanks in advance.

-- 
Didier RENARD
Centre de Geosciences / Geostatistique
Ecole des Mines de Paris
35 Rue St Honore
77300 Fontainebleau

Tel: (1) 64 69 47 80
Fax: (1) 64 69 47 05



More information about the R-devel mailing list