Skip to content

Using a NAMESPACE or the Imports field in DESCRIPTION?

2 messages · Wolfgang Koller, Martin Morgan

#
Hello list,

I am writing a package which builds on a function ("foo") of another 
package. I only need that particular function. What is the state of 
the art to do this? Do I need a NAMESPACE file in my package? 
Currently I still don't have one. Or can I do this with the Imports 
field in my DESCRIPTION file? Reading chapter 1 of the "Writing R 
Extensions" manual I do not completely understand for what situations 
these two alternatives are intended for. The manual says that with 
the Imports field of DESCRIPTION I can "import the name space" of 
another package. What does that mean? What are the differences 
between the two alternatives? Are there consequences for how I can 
access function "foo" within the code of my package?

Thanks for some clarifications and recommendations!

Wolfgang Koller
#
Hi Wolfgang --
Wolfgang Koller wrote:
It sounds like you want to add Imports: OtherPackage to DESCRIPTION, and

importFrom(OtherPackage, foo)

in you NAMESPACE file, in addition perhaps to

export(foo)

if you'd like users of your package to access foo. Using a NAMESPACE can 
be very beneficial, especially as your software grows in complexity -- 
it ensures ready access to the symbols you want (foo, in this case) 
without relying on the structure of the user search path. I don't think 
adding Imports to DESCRIPTION and adding a NAMESPACE should really be 
viewed as 'alternatives' -- add a NAMESPACE, and many of the packages 
that you had previously listed in Depends: likely belong more 
appropriately in Imports.

Martin