5

I'm trying to use Imports: instead of Depends: in the DESCRIPTION files of my packages, yet I still feel I've got some more to understand on this ;-)

What I learned from this post (by the way: awesome post!!!) is that everything my package, say mypkg, imports (say imported.pkg) via Imports: lives in environment imports:mypkg instead of being attached to the search path. When trying to find foo that ships with imported.pkg, R looks in imports:mypkg before traversing the search list. So far, so good.

Actual question

If imported.pkg (imported by mypkg) depends on a certain other package (stated in Depends: section of the package's DESCRIPTION file), do I need to make this very package a Depends: dependency of my package in order for R to find functions of that package? So it seems to me at the moment as otherwise R complains.

Evidence

Seems like simply importing such a package is not enough. As an example, take package roxygen2 (CRAN). It depends on digest while importing a bunch of other packages. I imported it (along with digest as mypkg also needs it) and checked environment imports:mypkg which does list the digest function: "digest" %in% parent.env(asNamespace("mypkg")) returns TRUE

Yet when running roxygenize() from within a function that is part of mypkg, R complains that it can't find digest.

Rappster
  • 12,762
  • 7
  • 71
  • 120
  • You also need to declare an `importFrom` in the `NAMESPACE` file. See for example http://stackoverflow.com/questions/7283134/what-is-the-benefit-of-import-in-a-namespace-in-r or http://stackoverflow.com/a/13261139/602276 – Andrie Apr 27 '13 at 19:25
  • I carried out the actual import via `import(imported.pkg)` and `import(digest)` in my `NAMESPACE` file (entire packages), that should do as well, shouldn't it? If something failed, there would also be no `digest` in the `imports:mypkg` environment - which there is. – Rappster Apr 27 '13 at 19:34
  • 2
    I think this falls under the "caveat" section of this answer: http://stackoverflow.com/a/8638902/967840 – GSee Apr 27 '13 at 19:38
  • Ahhh, okay! Thanks for the pointer! One more question though: when my functions call functions in packages that my package **imports**, do I need to do anything special to tell R "hey, look in the `imports:mypkg` environment first before going to the search path" (e.g. by using `::`) or does R figure that out itself? – Rappster Apr 27 '13 at 19:50
  • In that respect: can't I tell R **explicitly** to look in `imports:mypkg` first, "no matter what" in the sense of "also when calling a package's function that relies on packages that have not been declared as *imports* in the package's `NAMESPACE` files"? Because `mypkg` would take care of importing the dependency, so its functions would actually be available in `imports:mypkg` – Rappster Apr 27 '13 at 19:54

1 Answers1

1

You could have a look at my blog : http://r2d2.quartzbio.com/posts/package-depends-dirty-hack-solution.html Now i have a better and cleaner solution but not published yet. Hope it helps.

Karl Forner
  • 4,175
  • 25
  • 32