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

Thomas J. Leeper thosjleeper at gmail.com
Tue Aug 2 21:57:57 CEST 2016


My concerns with installing on the fly are that it (1) requires internet
access during run time, and either (2) involves assumptions about
repository and library locations, or (3) requires exposing all arguments to
install.packages() via higher level functions, or (4) needs interactivity.

-Thomas

On Aug 2, 2016 8:39 PM, "Dirk Eddelbuettel" <edd at debian.org> wrote:

>
> On 2 August 2016 at 11:00, Kevin Ushey wrote:
> | You could abuse the LinkingTo: field of the DESCRIPTION file, to
> | specify 'packages you want installed alongside your package that you
> | won't necessarily use at runtime'. (It's possible that 'R CMD check'
> | might warn about strange usages of LinkingTo:, but I'm not sure)
>
> I'd rather not abuse LinkingTo: any further. I fear its feelings are
> sufficiently hurt being mostly used for 'IncludeFrom:' and no linking.
>
> Kidding aside I think we have room for new tags in DESCRIPTION. We may as
> well do it right.
>
> | You could also just place these packages in Suggests, but guard their
> | usages with a function that attempts to download, install and load
> | those packages. E.g. (pseudo-ish code)
> |
> |     ensure_package_loaded <- function(package) {
> |       if (requireNamespace(package))
> |         return(TRUE)
>
> Nice.  [ And erratum in my previus email where I meant requireNamespace() ]
>
> We could even go one further and store this in a per-package environment,
> being filled through .onLoad() or .onAttach().
>
> |       if (interactive())
> |        # prompt user to download + install package, then try to load
> again
> |       stop("routine requires package but is not installed")
> |     }
>
> I don't see why this should work only when interactive(). I think it should
> work all the time.
>
> I also don't think it needs to stop. It is after all just some auxiliary
> functionality that Suggests provides.  Eg extra regression tests, say with
> or
> without a certain backend -- and those tests then need the yes/no toggle
> and
> skip if unavailable.
>
> | and use it as:
> |
> |     uses_foo <- function() {
> |       ensure_package_loaded("foo")
> |       foo::bar()
> |     }
>
> Sure.
>
> | This would at least minimize the amount of time spent 'annoying' the
> | user re: installation of package dependencies (it would only happen
> | the first time they try to use those functions)
>
> I don't really want other packages going off installing autonomously.
> We pretty much make this explicit in DESCRIPTION so that the user can make
> an
> informed choice.
>
> | Overall, I think the best resolution here is through clever use of
> | Suggests + on-demand installation of required packages, rather than
> | adding another field to the DESCRIPTION file.
>
> Wholly agreed on some part, less so on the remainders.
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list