【发布时间】:2020-05-13 21:36:39
【问题描述】:
我想为tidymodels 配方包中的各种步进函数使用带有列名的向量。我的直觉是简单地使用(prep 和 juice 只是在这里用于说明):
library(tidymodels)
library(modeldata)
data(biomass)
remove_vector <- c("oxygen","nitrogen")
test_recipe <- recipe(HHV ~ .,data = biomass) %>%
step_rm(remove_vector)
test_recipe %>%
prep %>%
juice %>%
head
但这会返回警告:
Note: Using an external vector in selections is ambiguous.
i Use `all_of(remove_vector)` instead of `remove_vector` to silence this message.
i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This message is displayed once per session.
当然,这让我很担心(我想确保我在编码时不会遇到错误消息),但我仍然得到了我想要的结果。
但是,当我按照错误消息并将以下内容与all_of 一起使用时:
test_recipe <- recipe(HHV ~ .,data = biomass) %>%
step_rm(all_of(remove_vector))
test_recipe %>%
prep %>%
juice %>%
head
我收到错误消息:
错误:并非所有函数都允许在步进函数选择器中使用(例如
all_of)。请参阅 ?selections。
在?selections 中,我似乎没有找到对我所遇到的确切(看似简单)问题的参考。
有什么想法吗? 非常感谢!
【问题讨论】:
-
这不是你的错,因为错误信息令人困惑,但食谱还不能理解所有的 tidyselect 选择器。看起来像你already found what is currently implemented,我们正在努力使这种凝聚力。这肯定不是错误消息的完美组合!
-
太好了,感谢您确认 Julia!继续做好tidymodels的工作,期待即将到来的! :)
标签: r tidymodels r-recipes