From ligges at statistik.tu-dortmund.de  Sun Mar 18 14:57:03 2012
From: ligges at statistik.tu-dortmund.de (Uwe Ligges)
Date: Sun, 18 Mar 2012 14:57:03 +0100
Subject: [Rd] Namespace dependency not required
In-Reply-To: <4F65B73B.8010809@univ-fcomte.fr>
References: <4F65B73B.8010809@univ-fcomte.fr>
Message-ID: <4F65E9AF.5080609@statistik.tu-dortmund.de>



On 18.03.2012 11:21, Patrick Giraudoux wrote:
> Hi,
>
> I am working at adding namespace to my packages, carefully following the
> doc "Writing R extensions" and some threads on the web. However I cannot
> find clear explanation about how to best deal with the import or
> importFrom functions in the name space. To make it short:
>
> To declare dependencies in the description file either after Depends:
> (packages including functions that are called from a package function)
> or after Suggests: (packages that are called eg from the doucmentation
> examples), works well. In this case one does not need to declare import
> in the namespace file.
>
> However, declaring dependencies sometimes for using only one function in
> a given package looks a bit over the top, and I though I could use
> importFrom in the namespace to deal with that. So removing the
> corresponding declaration in Depends (description file) and declaring
> eg  importFrom(splancs, inout) in the namespace always led to:
>
> * checking package dependencies ... ERROR
> Namespace dependency not required: 'splancs'
>
> Same thing with import(sp). I have the same trouble if I do not remove
> the declarations in Depends.
>
> So, I can hardly follow the meaning of the "Writing R extension" doc:
>
> Packages implicitly import the base namespace. Variables exported from
> other packages with namespaces need to be imported explicitly using the
> directives |import| and |importFrom|. The |import| directive imports all
> exported variables from the specified package(s). Thus the directives
>
>        import(foo, bar)
>
> specifies that all exported variables in the packages *foo* and *bar*
> are to be imported. If only some of the exported variables from a
> package are needed, then they can be imported using |importFrom|. The
> directive
>
>        importFrom(foo, f, g)
>
> specifies that the exported variables |f| and |g| of the package *foo*
> are to be imported.
>
> Can anybody tell us the conditions for which import and importFrom
> commands should be used in the NAMESPACE rather than in the Depends and
> Suggests declarations of the description file, and the conditions of
> their applicability (without error message... eg with a working example) ?

If you import from another namespace (which is the recommended way 
rather than just relying on search order), do not forget to declare it 
as "Imports" in your DESCRIPTION file. Your package depends on the other 
one: It could not be loaded without having the other one installed now.

Uwe Ligges



> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Namespace dependency not required
Uwe Ligges