I have been using a standard pattern when using dplyr mutate inside functions. Here is a toy example(only to prove a point):
myFunction = function(colname) {
dots <- setNames(list(lazyeval::interp(~ifelse(x>25, x*10, x/10), x = quote(colname))), "my_new_col")
mutate_(mtcars, .dots = dots)
}
I have made this into a function to not type it out every time. But this is rather verbose and I am not sure if there is a simpler way to parameterize calls to mutate_. Suggestions?
I'm assuming your function is trying to create a new column based on an existing column. Here is the function using the
tidyeval
approach. See Programming with dplyr for details.