I built my first R package months ago and I now realise some of my older functions are looking a bit dated. I'm already writing better functions to replace them.
I've seen how other R packages warn of deprecated functions, and redirect users to the newer functions. I want to do the same.
How do I mark a function as deprecated in R? Do I just set a warning?
Description. When an object is about to be removed from R it is first deprecated and should include a call to . Deprecated .
The pipe operator, written as %>% , has been a longstanding feature of the magrittr package for R. It takes the output of one function and passes it into another function as an argument. This allows us to link a sequence of analysis steps.
Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future.
The answer is to call the .Deprecated
function from base R:
f_old = function(x) {
.Deprecated("f_new")
return(x * x)
}
f_new = function(x) {
return(x^2)
}
This will give the appropriate warning:
> f_old(4)
[1] 16
Warning message:
'f_old' is deprecated.
Use 'f_new' instead.
See help("Deprecated")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With