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 | e...@debian.org ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel