【发布时间】:2018-02-08 02:15:06
【问题描述】:
我想在函数中使用rename_(或rename?)来重命名小标题中的列。例如,假设我在下面的函数中有rename(as_tibble(iris),petal = Petal.Width)`
rr <- function(toRename, newName, dt) {
rename_(dt, .dots = rlang::expr(list(!! newName = toRename)))
}
我可以将要重命名的数据集以及重命名为字符串的元素传递给我可以调用的位置:
rr('petal', 'Petal.Width', dt = as_tibble(iris))
用于将Petal.Width 重命名为petal。
我该怎么做?
【问题讨论】:
标签: r dplyr lazy-evaluation tidyverse