Dan Chaltiel
Dan Chaltiel

Reputation: 8484

How to manage legacy dependencies in a R package?

I'm working on a fork of a package that depends upon the ReporteRs library.

However, this library has been deprecated by its owner for a few years, in favour of the officer and flextable libraries.

On of the main reasons for this depreciation is not to depend on rJava, which may cause installation problems and bugs.

In my package, how should I manage this case?

So far, my package was processing data to return a ReporteRs object. If I change my functions to return an officer object I would break backward compatibilty.

But if I don't, and keep old, ReporteRs returning function as legacy backward compatibilty functions, I have to keep ReporteRs in my dependencies and my package would be rJava-dependant.

Is there a win-win solution?

Upvotes: 1

Views: 143

Answers (1)

January
January

Reputation: 17090

Here is what I would do:

  1. Make your best attempt to re-implement your functions with the officer library, but keeping your old API. Make sure that you warn the users that these functions are deprecated. At the same time make new functions fully compliant with officer/flextable syntax. Note that you might change the behavior of the functions slightly (as in, not ensuring all parameters are properly evaluated), as long as they take the same parameters and return the same type of objects.
  2. If that is really not possible, just add a compatibility warning to your old functions.
  3. Create a transitional package version that you would keep around for a few weeks or months with both versions of these functions. If the package still needs to depend on rJava, tough luck.
  4. Keep track of the packages that depend on your package. If there are not too many, you can contact their developers directly. Maybe the issue is not as serious as you think it is?

EDIT: As discussed above, you can make your dependency on ReportR conditional on the availability of ReportR. Then, you can put ReportR into the Suggests field of the DESCRIPTION file rather than Depends, and in the package you can use code like this:

if(requireNamespace("ReportR")) {
   warning("This function is deprecated, better use MyNewFunction instead")
   ReportR::whatever() ...
} else {
   warning("To run this (deprecated) function, please install the ReportR package")
}

Upvotes: 1

Related Questions