【发布时间】:2021-05-02 08:26:56
【问题描述】:
我想更改一些参数的名称。
在the guidelines之后,我应该使用lifecycle::deprecate_warn,然后将旧名称赋予新名称。
但是,在我的函数中,参数通常与 quosures 一起使用,因此归因失败并出现错误:
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
由reprex package (v0.3.0) 于 2021-01-28 创建
我盲目地用enquo 和其他人尝试了各种东西,但没有任何效果。
如何将旧名称归于新名称?
【问题讨论】: