Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deprecate an argument?

Tags:

r

Is there a standard way of deprecating arguments in R?

Example: For a web API package, I previously included a paging=TRUE argument which would paginate over all the results and download everything.

Now I want to have a limit argument instead, and only download everything if set to limit=0. This effectively eliminates the need for the paging argument, so I need to let people now it basically does nothing now. How do I do that?

like image 383
jakub Avatar asked Dec 01 '16 08:12

jakub


People also ask

How do you deprecate?

To deprecate a class or method, use the @deprecated tag, as explained in How to Write Doc Comments for JavaDoc. The paragraph following the @deprecated tag should explain why the item has been deprecated and suggest how the user can avoid using it.

What is deprecated function in Python?

Usage of a module may be 'deprecated', which means that it may be removed from a future Python release.


1 Answers

Something like as follows maybe would do for you?

foo <- function(paging = T, limit = 0) {
  if (!missing("paging"))
    warning("argument deprecated")
}

Example outputs:

# > foo()
# > foo(limit = 0)
# > foo(T)
# Warning message:
#   In foo(T) : argument deprecated
# > foo(paging = T)
# Warning message:
#   In foo(paging = T) : argument deprecated

As @Roland points out, it should also be mentioned in the documentation for that function that the argument is now deprecated.

like image 120
John Smith Avatar answered Oct 19 '22 04:10

John Smith