I am working on a family of R packages, all of which share substantial common code which is housed in an internal package, lets call it myPackageUtilities
. So I have several packages
myPackage1
, myPackage2
, etc...
All of these packages depend on every method in myPackageUtilities
. For a real-world example, please see statnet on CRAN. Each dependent package, of course, has
Depends: myPackageUtilities
in its DESCRIPTION file.
My question is: In the R code for myPackage1
, which of the following two techniques for accessing methods from myPackageUtilities
is preferable:
- Use
:::
to access the methods inmyPackageUtilities
, or - Export everything from
myPackageUtilities
(e.g. by includingexportPattern("^[^\\.]")
in the NAMESPACE)?
Option 2 clutters the end-user's search path, but the R gurus recommend against using :::
.
Follow-up question: If (2) is the better choice, is there a way to export everything using roxygen2?
Suppose we have a package called
randomUtils
and this package has a function calledsd
that calculates the Slytherin Defiance Quotient.Now I write a package called
spellbound
. Ifspellbound
Depends onrandomUtils
, thenrandomUtils::sd
will be found in the search path and can conflict with calculating standard deviation.If
spellbound
ImportsrandomUtils
, however, then R will installrandomUtils
but will not load it whenspellbound
is loaded. Thus, the new version ofsd
can't be found on the search path, but can still be accessed byrandomUtils::sd
With an ever growing body of contributed work on CRAN, it is becoming very important that we use Imports as much as possible so that we don't introduce unexpected behaviors by having conflicting function definitions.
An example of when I have used Depends: when writing the HydeNet package, I wanted the end user to be able to use the rjags package in concert with HydeNet. So I put rjags in Depends so that
library (HydeNet)
would loaf both packages. (In other words, putrjags
on the search path.Moral of the story, if you don't intend for the user to directly access the functions, it should go in Imports.