[Rd] Imports/exports of S4 methods

Roger D. Peng rpeng at jhsph.edu
Thu May 3 23:13:49 CEST 2007


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?

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?

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".

If you've made it this far I'm already grateful!  Any help with this would be 
appreciated.

-roger
-- 
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/



More information about the R-devel mailing list