Question: Proper way to deprecate an S4 generic
0
gravatar for Michael Steinbaugh
9 weeks ago by
Harvard
Michael Steinbaugh20 wrote:

What's the current best practice for deprecating an S4 generic? Is something along the lines of this approach recommended?

setGeneric(
    name = "A",
    def = function(object, ...) {
        .Deprecated("B")
        standardGeneric("B")
    }
)

setGeneric(
    name = "B",
    def = function(object, ...) {
        standardGeneric("B")
    }
)

Or should the deprecation call be placed inside an ANY method instead?

setMethod(
    f = "A",
    signature = signature("ANY"),
    definition = function(object, ...) {
        .Deprecated("B")
        B(object, ...)
    }
)
s4 generic • 94 views
ADD COMMENTlink modified 9 weeks ago by Marcel Ramos ♦♦ 360 • written 9 weeks ago by Michael Steinbaugh20
Answer: Proper way to deprecate an S4 generic
2
gravatar for Marcel Ramos
9 weeks ago by
Marcel Ramos ♦♦ 360
United States
Marcel Ramos ♦♦ 360 wrote:

Hi Michael!

First, please make sure that other developers are not importing your generic from your package. You could try the revdep package to check for those https://github.com/r-lib/revdepcheck.

Otherwise, your change could break other packages. Also, if they are using your generic, it would be good to consider moving the generic to another more appropriate package.

But to answer your question, it is better to deprecate the generic in the highest level, inside the setGeneric function (first option). This would ensure that all the methods will get the deprecation message. If deprecate inside the "ANY" method, class-specific methods might not get the message.

Best regards, Marcel

ADD COMMENTlink written 9 weeks ago by Marcel Ramos ♦♦ 360
1

Thanks Marcel. I've started consolidating my S4 generics into a single pacakge when applicable, similar to the BiocGenerics approach. I'm trying to be extremely conservative deprecating generics, but there are a few edge cases where the verbs aren't quite as clear as another spelling, and I want to be able to redirect users and/or revdeps to that improved variant.

ADD REPLYlink written 9 weeks ago by Michael Steinbaugh20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 136 users visited in the last hour