Proper way to deprecate an S4 generic
1
0
Entering edit mode
@mjsteinbaugh
Last seen 12 months ago
Cambridge, MA

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 • 1.2k views
ADD COMMENT
2
Entering edit mode
@marcel-ramos-7325
Last seen 2 days ago
United States

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 COMMENT
1
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 758 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6