In R: pass column name as argument and use it in function with dplyr::mutate() and lazyeval::interp()
This question links to this SO answer except that here I want to use the variable specified as function arg in a mutate_() . It works if I don't make any "calculations" in the mutate_() : data <- data.frame(v1=c(1,2), v2=c(3,4)) func1 <- function(df, varname){ res <- df %>% mutate_(v3=varname) return(res) } func1(data, "v1") This give the expected: v1 v2 v3 1 1 3 1 2 2 4 2 But if I do anything like this, it seems that I have not specified "v3" correctly: func2 <- function(df, varname){ res <- df %>% mutate_(v3=sum(varname)) return(res) } func2(data, "v1") Does not work; how come it is not