Skip to content
Prev 4253 / 12125 Next

[R-pkg-devel] Farming out methods to other packages

On Sat, 10 Aug 2019 at 19:21, Lenth, Russell V <russell-lenth at uiowa.edu> wrote:
The order of dispatch is meant to ensure that your package can't be
broken by a clash with another one. In other words, if recover_data is
called inside emmeans, emmeans:::recover_data.foo is called, but then
if it's called inside foopkg, then foopkg:::recover_data.foo is called
instead.

This feature, however, plays against your intended use case here, and
I think that the best way to circumvent it is by 1) renaming those
methods (e.g., recover_data_foo, because as soon as there is a
something.foo in your namespace, it will be dispatched regardless of
whether you register it or not), and 2) register them dynamically on
load time if foopkg is not available. There is an implementation for
this available here:
https://github.com/r-lib/vctrs/blob/master/R/register-s3.R

I?aki
Message-ID: <CALEXWq0urMLWJc+tD9pp=wRPFF2GPphfXSOfTBRjo_dy7jsd9g@mail.gmail.com>
In-Reply-To: <DM6PR04MB4380C0F1C69B4B99804A7341F1D10@DM6PR04MB4380.namprd04.prod.outlook.com>