Re: [Rd] New S3 methods for optional package

From: Jon Olav Skoien <jon.skoien_at_jrc.ec.europa.eu>
Date: Thu, 24 May 2012 15:00:48 +0200

Dear Prof. Ripley,
Thanks a lot for your answers!
See inline comments below.

On 24-May-12 12:01, Prof Brian Ripley wrote:
> On 24/05/2012 10:38, Jon Olav Skoien wrote:
>> I have listed A
>> under Suggests, and have a .onLoad function in B with
>> if (require(A)) registerS3methods(newMethodsMatrix, package = A, env =
>> environment(B))
>
> You are not supposed to be calling registerS3methods .... it is only
> visible because of the nature of the base namespace and its
> documentation says
>
> 'Not intended to be called directly.'
>
> And require() is the wrong thing here; you want to register methods on
> a namespace. The logic seems to be that you should do that only if
> A's namespace is already loaded, but you could load it pre-emptively
> with requireNamespace().

Replacing require with requireNamespace does not seem to work for this case, it fails with the error:
Error: object 'estimateParameters' not found whilst loading namespace 'intamap'
This comes from registerS3methods which cannot find the generic estimateParameters from parent.env of B (rtop). Is this because loadNamespace does not attach the namespace to the search path?

>
>
>> List A under Enhances of B.
>> This seems to be the right thing, as the R extensions manual says: "the
>> 'Enhances' field lists packages "enhanced" by the package at hand, e.g.,
>> by providing methods for classes from these packages".
>> However, although it seems I can install and load package B when I
>> conditionally import package A in the NAMESPACE, R CMD check stops with
>> the error: Namespace dependency not required: A
>> If I remove the import, R CMD check is happier, but I cannot load the
>> package after installing.
>>
>> I have read about the use of "Suggest", "Enhances" etc in "Writing R
>> Extensions", but could not figure out the right way to do this. I am
>> sure there is something I am missing here.
>>
>> If anyone wants to check possible solutions, package A is "intamap",
>> available from CRAN, whereas B is "rtop", available from Rforge:
>> **|install.packages("rtop", repos="http://R-Forge.R-project.org")|**
>
> I guess the problem is that you are trying to do too much with package
> rtop. I would consider creating a separate package depending on
> intamap (and most likely rtop) which adds the S3 methods for intamap.

I really hoped that would not be necessary, but you are probably right that it is the only solution if I want to get rid of the note. The disadvantage is then that I have to clutter the package repository of CRAN with one more package, which only purpose is to load two other packages. For me that does not appear as a better solution than having a package with a note and use of a function that is not intended. But then I am also not sure how much extra work my current solution would give the CRAN-maintainers, so if you think an extra package is better I will follow your advice.

Thanks,
Jon

-- 
Jon Olav Sk°ien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien_at_jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 24 May 2012 - 13:03:44 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 May 2012 - 14:01:52 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive