[R-pkg-devel] Support for several versions of another package

Iñaki Ucar |uc@r @end|ng |rom |edor@project@org
Mon Feb 22 14:15:56 CET 2021


On Mon, 22 Feb 2021 at 11:55, Gábor Csárdi <csardi.gabor using gmail.com> wrote:
>
> On Sun, Feb 21, 2021 at 3:47 PM Iñaki Ucar <iucar using fedoraproject.org> wrote:
> >
> > Hi,
> >
> > Let's say that pkgA uses pkgB::function1. Then, version 2 of pkgB
> > removes function1 and exports function2 for the same functionality. So
> > pkgA does something along these lines:
> >
> > if (utils::packageVersion("pkgB") < 2) {
> >   pkgB::function1()
> > } else {
> >   pkgB::function2()
> > }
> >
> > I'd say that there's nothing wrong with this code, and yet checks will
> > complain about "missing o unexported object" in pkgB, for either
> > function1 or function2 depending on the version of pkgB that is
> > available.
> >
> > Isn't this a false positive? Or is there a better way of doing this?
>
> I would just do this:
>
> if (utils::packageVersion("pkgB") < 2) {
>   getExportedValue("pkgB", "function1")()
> } else {
>   getExportedValue("pkgB", "function2")()
> }
>
> I would think that the check is fine with this, although I haven't tried.

This works without warnings or notes. Thanks!

-- 
Iñaki Úcar



More information about the R-package-devel mailing list