From t.jombart at imperial.ac.uk  Wed Jun  5 21:57:41 2013
From: t.jombart at imperial.ac.uk (Jombart, Thibaut)
Date: Wed, 5 Jun 2013 19:57:41 +0000
Subject: [Rd] conflicting imports despite using importFrom in NAMESPACE
In-Reply-To: <51AF8F32.3010801@fhcrc.org>
References: <2CB2DA8E426F3541AB1907F98ABA65706386D41F@icexch-m1.ic.ac.uk>
	<63D11F8E-D047-4E48-B8A0-E6EC9E24BE62@gmail.com>,
	<51AF8F32.3010801@fhcrc.org>
Message-ID: <2CB2DA8E426F3541AB1907F98ABA65706386D4F6@icexch-m1.ic.ac.uk>


Hi Martin, 

thanks, this is reassuring - I'm assuming it is just a problem on my computer then.

Thanks for pointing out the exportPattern("."). For some purposes I actually ended up needing to export some hidden functions, but I guess I could just not export these and reference to them explicitly using ':::'.

Best
Thibaut
________________________________________
From: Martin Morgan [mtmorgan at fhcrc.org]
Sent: 05 June 2013 20:19
To: peter dalgaard
Cc: Jombart, Thibaut; r-devel at r-project.org
Subject: Re: [Rd] conflicting imports despite using importFrom in NAMESPACE

On 06/05/2013 11:59 AM, peter dalgaard wrote:
> I'd suspect that the Imports: line in DESCRIPTION imports the full namespaces, including conflicting items, on top of importFrom items. Does it not help to use Depends: instead?

I think of Imports: and Depends: as different -- presumably the end user has no
need for ape / igraph beyond the functionality provided by the new package.

For what it's worth, with a minimal package (attached, modulo the mailman gods),

$ tree PkgA
PkgA
??? DESCRIPTION
??? NAMESPACE
??? R

1 directory, 2 files

and with DESCRIPTION / NAMESPACE as below, I don't see any warning about
replacing previous imports

$ R --vanilla
 > library(PkgA)
 > sessionInfo()
R version 3.0.1 beta (2013-05-07 r62721)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] PkgA_1.2.3

loaded via a namespace (and not attached):
[1] ape_3.0-8       grid_3.0.1      igraph_0.6.5-2  lattice_0.20-15
[5] nlme_3.1-109

likewise with R version 3.0.1 beta (2013-05-07 r62721).

Also I don't think exportPattern(".") is to be recommended; see section 1.5.1 of
Writing R Extensions (though as a lazy programmer I kind of like the pattern
"^[^\\.]").

Martin Morgan

> -pd
>
>
> On Jun 5, 2013, at 18:48 , Jombart, Thibaut wrote:
>
>>
>> Dear all,
>>
>> It is my understanding that using 'importFrom' in the NAMESPACE of a package allows to avoid conflicts between different packages defining objects with identical names. However, I can still see conflicts while loading the package using 'library'.
>>
>> Here is a toy example, with a package 'foo' importing 'as.igraph' from the igraph package, and 'nj' from ape.
>>
>> 'foo' uses the following DESCRIPTION file:
>> ----------------------
>> Package: foo
>> Version: 0.0-0
>> Date: 2013/06/04
>> Title: foo
>> Author:  John Doe
>> Maintainer: John Doe <jdoe at nowhere.org>
>> Imports: igraph, ape
>> Description: just a test.
>> License: GPL (>=2)
>> LazyLoad: yes
>> ----------------------
>>
>> And the following NAMESPACE:
>> ----------------------
>> ## Export all names
>> exportPattern(".")
>>
>> ## Export all classes
>> exportClassPattern(".")
>>
>> ## Import all packages listed as Imports or Depends
>> importFrom(igraph, as.igraph)
>> importFrom(ape, nj)
>> ----------------------
>>
>> The check (R 3.0.1) passes without warnings, but then when loading the package:
>>> library(foo)
>> Warning messages:
>> 1: replacing previous import ?as.igraph? when loading ?ape?
>> 2: replacing previous import ?edges? when loading ?ape?
>>>
>>
>> I would have assumed only ape::nj and igraph::as.igraph would be imported when loading 'foo', so this conflict should not occur.
>>
>> There is probably something simple I have missed as I have just began to pay attention to NAMESPACES recently. Reading this post:
>> http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends
>> clarified things a bit, but I still don't understand the warning above.
>>
>> Any clarification will be much appreciated.
>>
>> All the best
>>
>> Thibaut
>>
>> --
>> ######################################
>> Dr Thibaut JOMBART
>> MRC Centre for Outbreak Analysis and Modelling
>> Department of Infectious Disease Epidemiology
>> Imperial College - School of Public Health
>> St Mary?s Campus
>> Norfolk Place
>> London W2 1PG
>> United Kingdom
>> Tel. : 0044 (0)20 7594 3658
>> t.jombart at imperial.ac.uk
>> http://sites.google.com/site/thibautjombart/
>> http://adegenet.r-forge.r-project.org/
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>


--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793


[Rd] conflicting imports despite using importFrom in NAMESPACE
Jombart, Thibaut