Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark a function as deprecated in customised R package [closed]

Tags:

r

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?

like image 603
lebelinoz Avatar asked Jun 19 '17 03:06

lebelinoz


People also ask

What does it mean when a function is deprecated in R?

Description. When an object is about to be removed from R it is first deprecated and should include a call to . Deprecated .

What package is Function %>% in R?

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.

What happens when a function is deprecated?

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.


1 Answers

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") 
like image 197
lebelinoz Avatar answered Sep 19 '22 23:09

lebelinoz