[R-pkg-devel] Handling Not-Always-Needed Dependencies?

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Aug 2 18:36:51 CEST 2016


On Tue, Aug 2, 2016 at 11:26 AM, Thomas J. Leeper <thosjleeper at gmail.com> wrote:
> I have a fairly open-ended question about the handling of package
> dependencies that is inspired by the precise distinction between
> "Depends", "Imports", and "Suggests" listed in DESCRIPTION.
>
> Some background, as I understand it: Prior to requiring package
> namespaces, we listed package dependencies in "Depends" because the
> required package had to be (1) installed and (2) on the search path in
> order to access its functions. After introducing and requiring
> namespaces, there are very few circumstances in which "Depends" is
> needed because functions from the required package can either be
> imported (via "Imports" and NAMESPACE) and/or referred to using the
> `pkg::fun()` style. "Suggests" packages are maybe needed for examples,
> vignettes, etc. but are not installed by default via
> `install.packages()`, so are not guaranteed to be available.
>
> Some observations:
>
> 1. "Depends" seems to be less useful than before, except in rare cases
> where a package needs to be (a) installed, (b) loaded, and (c) on the
> search path. Imports covers most package dependency use cases.
>
> 2. There is a gap in functionality between "Imports" and "Suggests".
> Sometimes there is a need for functions that should be available
> (i.e., installed) but do not need to be loaded or imported because
> they are rarely used (e.g., graphing functions). Importing the
> functions adds bloat but only putting their package in "Suggests" does
> not guarantee availability when, for example, calling
> `requireNamespace()` or `require()`.
>
Maybe I'm missing something, but isn't that the point of calling
requireNamespace()?  For example:
if (requireNamespace("suggestedPackage"))
  stop("suggestedPackage required but not installed")

That doesn't seem like a heavy burden for package writers when writing
infrequently used functions in their package.  You could even add the
install.packages command to the error message to instruct users to
install the required package.

> Suggestion:
>
> Might it be useful to have a category between "Imports" and "Suggests"
> that covers packages that should be installed but not imported?
>
> This could be done by changing `install.packages()` to cover
> "Suggests" by default, changing the meaning of "Depends" and
> "Imports", or adding a new category to DESCRIPTION.
>
I personally would not want install.packages() to install packages I'm
unlikely to actually use.

It's also not clear to me how importing rarely used functions causes
bloat, but installing all packages for all rarely-used functions does
not cause bloat.

> I am interested in hearing your thoughts on this issue.
>
> Best,
> -Thomas
>
> Thomas J. Leeper
> http://www.thomasleeper.com
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-package-devel mailing list