[Rd] import of Namespaces

Roger Peng rpeng at jhsph.edu
Thu Dec 1 20:46:58 CET 2005


My understanding is of your questions is below:

Matthias Kohl wrote:
> Dear R devels,
> 
> let's say I have three packages "pkg1", "pkg2" and "pkg3" which all 
> contain new S4 classes and methods. Where "pkg3" depends on "pkg2" and 
> "pkg2" depends on "pkg1". Moreover, all three packages have namespaces.
> 
> 1) I use ".onLoad <- function(lib, pkg) require(methods)". Do I also 
> have to import the namespace of "methods" package?

No.

> 
> 2) If I use import("pkg1") in the namespace of "pkg2", does this also 
> (correctly) import the S4 classes and methods of "pkg1"? Or do I 
> explicitly have to use importClassesFrom resp. importMethodsFrom?

Importing an entire package namespace will import all of the exported 
classes/methods from "pkg1".

> 
> 3) If I import the Namespace of "pkg2" in "pkg3", where the namespace of 
> "pkg2" has import("pkg1") (or maybe importClassesFrom, 
> importMethodsFrom) and I also want to use S4 classes and methods of 
> "pkg1" in "pkg3". Is it sufficient to have import("pkg2") in the 
> Namespace of "pkg3" or do I need import("pkg1") and import("pkg2")?

I believe you need to import each separately since the S4 
classes/methods from "pkg1" will not be available to you simple because 
you imported "pgk2" (i.e. I don't think the chain rule applies here).

> 
> Many thanks for your help and advice
> Matthias
> 

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



More information about the R-devel mailing list