From bcarvalh at jhsph.edu  Sat Mar 17 00:35:08 2007
From: bcarvalh at jhsph.edu (Benilton Carvalho)
Date: Fri, 16 Mar 2007 19:35:08 -0400
Subject: [Rd] Problems with package containing S4 classes
In-Reply-To: <45FB21C3.1050205@aon.at>
References: <45FB045E.3090909@aon.at>
	<72DA1101-B6C5-4DB7-A9F8-2CC091D8AC7E@jhsph.edu>
	<45FB0E6D.3010803@aon.at>
	<D023A1FD-2388-40C3-AC7D-A20773326A62@jhsph.edu>
	<45FB1B9A.3040406@aon.at>
	<C92F4691-41B7-4881-B604-57E0BA978BE6@jhsph.edu>
	<45FB21C3.1050205@aon.at>
Message-ID: <0173F567-3E02-422B-BE69-28A058DD8BF5@jhsph.edu>

The Collate field gives the order that the files are going to be  
concatenated. If they're concatenated using the "wrong" order, your  
installation might fail (for example, the generic is defined after  
the method).

A recommended source is the  "Writing R Extensions"

http://cran.r-project.org/doc/manuals/R-exts.html

Session 1.1.1 - The Description File (Writing R Extensions)

says exactly what you shohuld know about the Collate field (and not  
only that).

b

On Mar 16, 2007, at 7:01 PM, cstrato wrote:

> I agree, but I hope that "AllGeneric.R" is not the only possibility.
> BTW, what is a collate field?
>
> Best regards
> Christian
>
> Benilton Carvalho wrote:
>> Well, my understanding is that if you "need" to define it (the  
>> generic) twice you're doing something wrong.
>>
>> Do you have a collate field in your description file? IMHO, the  
>> "AllGeneric.R"/"AllClasses.R" approach is the way to go... keeping  
>> your code organized is always a good thing, right?
>>
>> b
>>
>> On Mar 16, 2007, at 6:35 PM, cstrato wrote:
>>
>>> Dear Benilton
>>>
>>> Yes, but the error disappears only when I define it twice.
>>>
>>> For my package I create three files:
>>>
>>> 1. MyClasses.R:
>>> Here I define the classes only using
>>> setClass("baseClass")
>>> setClass("derivedClass")
>>>
>>> 2. methods.baseClass.R
>>> Here I define the methods for baseClass
>>> setGeneric("export", function(object,...) standardGeneric("export"))
>>> setMethod("export", "baseClass", export.baseClass);
>>>
>>> 3. methods.derivedClass.R
>>> Here I define the methods for derivedClass
>>> setGeneric("export", function(object,...) standardGeneric("export"))
>>> setMethod("export", "derivedClass", export.derivedClass);
>>>
>>> As you see, I need to define setGeneric twice, otherwise I get  
>>> the error.
>>> It is not clear to me, why this is the case?
>>>
>>> I know, that BioBase has a file AllGeneric.R, but I would like to  
>>> define
>>> the generics in the respective methods files.
>>>
>>> Best regards
>>> Christian
>>>
>>> Benilton Carvalho wrote:
>>>> do you have a generic for 'export'?
>>>>
>>>> On Mar 16, 2007, at 5:38 PM, cstrato wrote:
>>>>
>>>>> Dear Benilton
>>>>>
>>>>> Thank you, now my package works.
>>>>>
>>>>> Do you have an explanation for my second problem:
>>>>>
>>>>> * Installing *source* package 'mytest' ...
>>>>> ** R
>>>>> ** save image
>>>>> Error in setMethod("export", "derivedClass",  
>>>>> export.derivedClass) :
>>>>>        no existing definition for function "export"
>>>>> Error: unable to load R code in package 'mytest'
>>>>> Execution halted
>>>>>
>>>>> What may be the reason for this error?
>>>>>
>>>>> Best regards
>>>>> Christian
>>>>>
>>>>>
>>
>>



[Rd] Problems with package containing S4 classes
Benilton Carvalho