[R-pkg-devel] Conditionally register method with generic in other package
Hadley Wickham
h.wickham at gmail.com
Thu Dec 7 20:54:18 CET 2017
On Thu, Dec 7, 2017 at 2:44 AM, Bill Denney <bill at denney.ws> wrote:
>
>> On Dec 6, 2017, at 07:45, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
>>
>> To avoid excessive dependencies, I would like to only register
>> foo.bar() if package A is installed at the time package B is
>> installed. If package A is installed after package B, then warn the
>> user when package B is loaded and/or attached, so they can re-install
>> A and have foo.bar() registered correctly.
>
> One simple solution would be to wrap the instantiation of foo.bar in a require test:
>
> if (require(A)) {
> foo.bar <- function(...) {
> print("To be or not to be")
> }
> } else {
> message("To use the foo.bar function, please install package A.")
> }
I don't think that will work because the code will be executed at
build time, not package-load time.
Hadley
--
http://hadley.nz
More information about the R-package-devel
mailing list