Re: [Rd] Imports/exports of S4 methods

From: Paul Gilbert <pgilbert_at_bank-banque-canada.ca>
Date: Fri, 04 May 2007 10:45:08 -0400

I'm wrestling with the same issues, so this is the blind leading the blind, but that usually prompts someone knowledgeable to say something useful.

Roger D. Peng wrote:

>I have a question about what to do in the following situation (please bear with
>the setup):
>
>Package A defines an S4 generic 'foo' and as well as S4 methods for 'foo' and has
>
>exportMethods("foo")
>
>in its NAMESPACE file.
>
>Package B defines another method for 'foo' for class "bar" and has
>
>importFrom(A, "foo")
>exportMethods("foo")
>exportClasses("bar")
>
>in its NAMESPACE file. Should Package B also have Package A in the 'Depends:'
>field of the DESCRIPTION file or is it correct to import Package A only?
>
>
I thought it should only be necessary to import A in NAMESPACE and list it in Imports in the DESCRPTION file, but I get warning messages if the code in B does not require("A") in the .onLoad function. This in turn means that A needs to be in the Depends line of DESCRIPTION.

>Finally, Package C has a single exported function named 'myfunc' which needs to
>use the method for 'foo' defined in Package B, so its NAMESPACE file has
>
>importFrom(A, "foo")
>importMethodsFrom(B, "foo")
>importClassesFrom(B, "bar")
>export("myfunc")
>
>Is this the correct thing to do?
>
>
I don't think you need the imports in this case, just the the export. You do need B (and thus implicitly A) in the Depends line of DESCRIPTION.

>The error I get under this setup is that 'myfunc' cannot find the method for
>'foo' defined in Package B when 'myfunc' calls 'foo' on an object of class "bar".
>
>
I'm not sure why, but the one problem I have had is that when the syntax of the NAMESPACE file is messed up, you only get warnings when to require the package, but then you get errors when you try to use the functions. Be sure to look back and see if you got warnings when you require("B").

>If you've made it this far I'm already grateful! Any help with this would be
>appreciated.
>
>
Thanks, you just saved me writing up the same questions.

>-roger
>
>


La version franšaise suit le texte anglais.


This email may contain privileged and/or confidential inform...{{dropped}}



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 04 May 2007 - 15:04:30 GMT

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 Fri 04 May 2007 - 15:33:17 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.