| deprecated_generic | R Documentation |
To deprecate a generic, change new_generic() to deprecated_generic() in
its definition and supply when. Keep its existing dispatch_args, fun,
and method registrations, and keep exporting it under the same name. Calls
still dispatch to its methods, but now warn.
If you rename a generic or move it to another package, supply the
replacement as new instead of dispatch_args and fun:
Calling the old name warns, then calls the replacement.
Registering a method on the old name registers it on the replacement, without a warning. Both names use the same methods.
deprecated_generic(
name,
dispatch_args,
fun = NULL,
when,
new = NULL,
method = c("base", "lifecycle(warn)", "lifecycle(stop)"),
new_label = NULL
)
name |
The old name of the generic, as a string. As with
|
dispatch_args, fun |
As in |
when |
The package version when the deprecation began, e.g.
|
new |
The replacement: an S7 generic, usually the renamed generic, or a generic that now lives in another package. |
method |
How to signal the deprecation:
The lifecycle options require the lifecycle package to be installed, and to be a dependency of your package. |
new_label |
How to name the replacement in the warning, e.g. |
A function with class S7_deprecated_generic.
If pkg::gen() moves to pkgcore::gen(), define the old name in pkg as:
gen := deprecated_generic(new = pkgcore::gen, when = "2.0.0")
Methods registered through either name apply to calls through both names, including methods supplied by other packages.
When new is supplied, the deprecated generic has the same arguments as
the replacement and forwards them unchanged. Changing or deprecating
arguments needs code in the generic itself; this helper only deprecates
the generic's name.
deprecated_class() and deprecated_property() to deprecate
other parts of your API.
# Deprecate a generic by changing its definition:
shout := deprecated_generic("x", when = "2.0.0")
method(shout, class_character) <- \(x) toupper(x)
shout("hi")
# A generic renamed from summarise() to summarize():
summarize := new_generic("x")
method(summarize, class_double) <- function(x) mean(x)
summarise := deprecated_generic(new = summarize, when = "1.1.0")
# Calling the old name warns, then delegates:
summarise(c(1, 2, 3))
# Registering a method on the old name registers it on the new generic:
method(summarise, class_character) <- function(x) unique(x)
summarize(c("a", "b", "a"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.