UPDATE: From comment below on this post, this is now working as expected, without the issues I laid out here.
Below is a toy example of using rename_
fr
There are a few thing that make this painful:
c(x = "new")
is the same as c("x" = "new")
, and not the opposite
of c(new = x)
.
You can construct the vector you want with setNames(x, "new")
,
but...
I forgot to add the .dots
argument to rename_
(bug report at
https://github.com/hadley/dplyr/issues/708) so you can't do:
rename_(dat, .dots = setNames(x, "new"))
Instead you need to use do.call
:
do.call(rename_, c(list(quote(dat)), list(setNames(x, "new"))))
In my Rstudio, I define:
x <- 'myname'
dat <- data.frame(yes=1, no=2)
I want to change the variable name from yes to myname
It doesn't work:
rename_(dat, .dots = setNames(x, "yes"))
But this works:
rename_(dat, .dots = setNames("yes", x))
rename_(dat, .dots = setNames("yes", paste(x) ))