[Rd] Namespace dependency not required

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Mar 18 19:30:50 CET 2012



On 18.03.2012 19:27, Patrick Giraudoux wrote:
> Le 18/03/2012 18:02, Uwe Ligges a écrit :
>>
>>
>> On 18.03.2012 16:08, Patrick Giraudoux wrote:
>>> Le 18/03/2012 14:57, Uwe Ligges a écrit :
>>>>
>>>>
>>>> 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
>>>>
>>>
>>> OK. got it (more or less).
>>>
>>> With this in the description file:
>>>
>>> Depends: boot (>= 1.3-4), nlme(>= 3.1-64), rgdal (>= 0.7-8), sp (>=
>>> 0.9-97), spdep (>= 0.5-43), splancs (>= 2.01-31)
>>>
>>> importFrom(splancs, inout) is accepted in the NAMESPACE file and I have
>>> no error message with rcmd check.
>>>
>>> Irr works also with:
>>>
>>> Depends: boot (>= 1.3-4), nlme(>= 3.1-64), rgdal (>= 0.7-8), sp (>=
>>> 0.9-97), spdep (>= 0.5-43)
>>> Imports: splancs (>= 2.01-31)
>>>
>>> Practically, I a am safe (thanks a lot), but I am however still hungry
>>> to learn a bit more. I hardly understand what R does when reading the
>>> suggests and imports in the DESCRIPTION file compared to what it does
>>> reading the NAMESPACE (my mistake was to believe that one was a
>>> substitute for the other). From a practical point of view, why is it
>>> important to use import or importFrom in the NAMESPACE when everything
>>> looks like working well when declarations are done in the DESCRIPTION
>>> file only (eg in depends or imports)? It is not crystal clear to me even
>>> reading carefully "Writing R extension". DESCRIPTION file is used to get
>>> the "list of packages that will be attached (...) before the current
>>> package" (indeed, now, I no longer needs to use 'require' within my
>>> package functions). In simple words, what may add the NAMESPACE to
>>> that ?
>>>
>>> Apologize to be so poorly aware (= so much stupid) about the role of
>>> each of those declaration spaces.
>>
>> Please read some literature about NAMESPACES, e.g. documentation in
>> Writing R Extensions plus Luke Tierney's articles in R News.
>
> ok. Will do it with Luke Tierney's articles. I read Writing R extensions
> already and also S programming (Venables and Ripley), but indeed should
> come down to more basic text for dudes :-) .

S Programming is excellent, but it was written before Namespaces were 
introduced to R.

Uwe Ligges




>
> Best,
>
> Patrick
>
>
>>
>> A NAMESPACE import imports functionality of another namespace into
>> your own namespace and hence avoids problems caused by name clashes.
>> The DESCRIPTION file is required to derive dependency structure of
>> packages, i.e. derive which package has to be *installed* first etc.
>>
>> Uwe Ligges
>>
>



More information about the R-devel mailing list