Skip to content

Add a deprecate adverb function [Feature Request] #188

@DanChaltiel

Description

@DanChaltiel

Hi,

In experimental packages growing more mature, I end up with many functions being simply renamed.

This causes many functions to be just a call to deprecate_warn() and then a call to the replacement function. I think it would be clearer if there was a purrr-style adverb to be used.

Something like this:

deprecatedly = function(f, what, when, with=rlang::caller_arg(f), details=NULL, type="warn"){
  if(!stringr::str_ends(with, "\\(\\)")) with=paste0(with,"()")
  if(!stringr::str_ends(what, "\\(\\)")) what=paste0(what,"()")
  function(...){
    lifecycle::deprecate_warn(when, what, with, details)
    f(...)
  }
}

new_function = function(){
  "foo"
}

old_function = deprecatedly(new_function, what="old_function", when="0.1")

old_function()
#> Warning: `old_function()` was deprecated in <NA> 0.1.
#> ℹ Please use `new_function()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> [1] "foo"

Created on 2024-12-26 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions