I want to change the name of some argument.
Following the guidelines, I should use lifecycle::deprecate_warn
and then attribute the old name to the new name.
However, in my function, the argument is normally used with quosures, so the attribution fails with an error:
library(tidyverse)
library(lifecycle)
library(rlang)
my_fun = function(df, cols, .vars = deprecated()){
if (quo_is_missing(enquo(cols)) && !quo_is_missing(enquo(.vars))) {
deprecate_warn("0.1.6", "my_fun(.vars=)", "my_fun(cols=)")
cols <- .vars #error is thrown here
}
select(df, {{cols}})
}
my_fun(iris, cols=Sepal.Length) %>% head()
#> Sepal.Length
#> 1 5.1
#> 2 4.9
#> 3 4.7
#> 4 4.6
#> 5 5.0
#> 6 5.4
my_fun(iris, .vars=Sepal.Length) %>% head()
#> Warning: The `.vars` argument of `my_fun()` is deprecated as of <NA> 0.1.6.
#> Please use the `cols` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> Error in my_fun(iris, .vars = Sepal.Length): objet 'Sepal.Length' introuvable
Created on 2021-01-28 by the reprex package (v0.3.0)
I blindly tried various things with enquo
and others but nothing worked.
How can I attribute the old name to the new name?
question from:https://stackoverflow.com/questions/65937178/how-to-assign-a-quosure-to-another-object