I am trying to rename a column with
dplyr::rename() and R is returning this error that I am unable to find anywhere online.
Error: `new_name` = old_name must be a symbol or a string, not formula
Reproducible example with a 2 column data frame:
library(dplyr) df <- data.frame(old_name = seq(1:10), x = seq(1:10)) df %>% dplyr::rename(new_name = old_name)
> sessionInfo() R version 3.4.3 (2017-11-30) Platform: x86_64-apple-darwin17.2.0 (64-bit) Running under: macOS High Sierra 10.13.1 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib locale:  en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages:  stats graphics grDevices utils datasets methods base other attached packages:  dplyr_0.7.4 loaded via a namespace (and not attached):  compiler_3.4.3 magrittr_1.5 assertthat_0.2.0 R6_2.2.2  bindrcpp_0.2 glue_1.2.0 tibble_1.3.4 Rcpp_0.12.14.3  pkgconfig_2.0.1 rlang_0.1.4.9000 bindr_0.1 >
I expect this new simple data frame to have the first column renamed to
new_name. This also does not work with
Current R version is 3.4.3 and dplyr version is 0.7.4.
I was unable to replicate this on R version 3.3.3, but was able to replicate it on R version 3.4.0. This was tested on a completely clean R session.
My current solution is to rewrite part of my code with
plyr::rename as that still works, but this is not ideal because it requires me to rewrite a lot of code.
Working example with
library(plyr) df <- data.frame(old_name = seq(1:10), x = seq(1:10)) df %>% plyr::rename(replace = c('old_name' = 'new_name'))