Message-ID: <CAPPM_gTuV9m_aXsWS01yajGg0cx+mtBCqp5D5SVwK1JFwZsOEQ@mail.gmail.com>
Date: 2018-01-22T11:55:36Z
From: Joshua Ulrich
Subject: [R-pkg-devel] Conditionally register method with generic in other package
In-Reply-To: <CAPPM_gSe+nGTxi2qZcM4DKW5=_SeO+z80vWb5fEkMp+iQMV5Tw@mail.gmail.com>
For posterity, the solution I employed did not register the method as
a formal S3 method. Functionality in package B was unchanged as long
as package B was loaded and attached... which was good enough for my
purposes.
On Wed, Dec 6, 2017 at 6:45 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> I have a feeling I know the answer to this question, but I'm asking
> with the hope that I learn something new.
>
> Package A defines a S3 generic function, "foo()". Package B defines a
> S3 class "bar", and a foo.bar() method. This method is not strictly
> necessary for the package to function, and package A has many
> dependencies.
>
> 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.
>
> I could figure out a way to do this manually, but doubt it would be
> CRAN-approved. What is the recommended way to handle this situation?
> I've received one suggestion to split B into 2 packages: one without
> the method, and one with. Are there other alternatives?
>
> Thanks,
> Josh
>
> --
> Joshua Ulrich | about.me/joshuaulrich
> FOSS Trading | www.fosstrading.com
> R/Finance 2018 | www.rinfinance.com
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2018 | www.rinfinance.com