Question: Proper way to deprecate an S4 generic
0
7 months ago by
Harvard
Michael Steinbaugh30 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 • 180 views
modified 7 months ago by Marcel Ramos ♦♦ 410 • written 7 months ago by Michael Steinbaugh30
Answer: Proper way to deprecate an S4 generic
2
7 months ago by
Marcel Ramos ♦♦ 410
United States
Marcel Ramos ♦♦ 410 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

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.