Jombart, Thibaut
2013-Jun-05 16:48 UTC
[Rd] conflicting imports despite using importFrom in NAMESPACE
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/
peter dalgaard
2013-Jun-05 18:59 UTC
[Rd] conflicting imports despite using importFrom in NAMESPACE
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? -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-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com