[Bioc-devel] NAMESPACE questions
sfalcon at fhcrc.org
Mon Nov 21 16:21:40 CET 2005
On 21 Nov 2005, ddiez at iib.uam.es wrote:
>> If in package A we wanted to call function baz from package B then
>> we could:
>> - use B::baz()
>> - import baz from B in the NAMESPACE file and just call baz()
> This is only possible if package B has a NAMESPACE, isn't it?
Yes, that is correct. You cannot use the import directive in a
NAMESPACE file for a package that does not have its own NAMESPACE
file. In such a case you can:
a) write the the package maintainer and ask them to add a name space?
b) Add the package to the Depends field in DESCRIPTION and live
without the protection a name space provides.
> And what if package A and B have either function foo() and B call
> also function foo() from package A. I defined a function log2 to
> manage log2 for some type of data and inside uses log2 from base
> package. But instead of that it tries to use log2 from my package.
> This is because my log2 if first in the search path. I could solve
> this using base::log2 in case log2 has a NAMESPACE but I prefer to
> rename my function. But developers deal normally in this situations?
Yes, both are good solutions. In general, one should think carefully
before creating a function with the same name as a basic math function
in base. There are times when this may be reasonable, but realize
that an end user who loads up your package (even with NAMESPACE) will
have a strange experience with log2.
> Another question is that I have some S4 classes and methods. I make
> the corresponding entry in the NAMESPACE file but the documentation
> tell something about .onLoad call that must be present. I see that
> in package Biobase is in file zzz.R in R directory but I don't known
> how to call it in my case. In fact it is not actually and my package
> compiles and works without warning.
First, you don't call .onLoad yourself. All you do is define it. The
.onLoad function is a "hook" function. When your package is loaded, R
will look for a .onLoad function in your package. If found, it will
As to whether or not you need one, I'm not sure. It is true that the
Extension Manual says to include a .onLoad function that does
require(methods) if your package has S4 classes and a NAMESPACE.
However, I *suspect* this is no longer needed as long as you have
methods in Depends.
> By the way I think it really clarifies things. I have solved the
> issues with my package and now has a working NAMESPACE file (maeby
> with some bugs?)
Excellent. Thanks for asking some good questions. I hope others will
find the discussion useful as well.
More information about the Bioc-devel