I want to rename a column inside a function with a name passed as an argument for this function. Basically, I have a function
produce_data_frame <- function(name) {
return(iris)
}
And I want that this function change the Sepal.length column name with 'name' (with name taking the value of name) I tried different things such as
produce_data_frame <- function(name) {
name <- enquo(name)
iris %>%
rename((!!name) = Sepal.Length) %>%
return()
}
And when calling
produce_data_frame("newName")
I would like to get back the iris data.frame with the Sepal.Length column named newName. But my understanding of NSE is still very basic, and it doesn't even compile.