The problem is when the approval assessment occurs. In my opinion, the goal of mutate_ is not to recreate the mutate syntax, for example, using paste to create mutate(SomeName = "") . Instead, it should allow the generation of functions. The reason your approach fails is (I believe) the fact that it is looking for a function named "" .
Instead, you need to pass a function that can be evaluated (here I use paste as a placeholder) and set the name of this column using your variable. This should work:
df <- diamonds NewName <- "SomeName" df <- df %>% mutate_(.dots = setNames("paste('')",NewName))
It also allows you to control more, for example, you can embed cut and color :
df <- df %>% mutate_(.dots = setNames("paste(cut, color)",NewName))
gives:
carat cut color clarity depth table price xyz SomeName <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <chr> 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 Ideal E 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 Premium E 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 Good E 4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63 Premium I 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75 Good J 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48 Very Good J 7 0.24 Very Good I VVS1 62.3 57 336 3.95 3.98 2.47 Very Good I 8 0.26 Very Good H SI1 61.9 55 337 4.07 4.11 2.53 Very Good H 9 0.22 Fair E VS2 65.1 61 337 3.87 3.78 2.49 Fair E 10 0.23 Very Good H VS1 59.4 61 338 4.00 4.05 2.39 Very Good H
(Note that I also got the original syntax to work for the first time, followed by subsequent crashes. It's worth digging in.)
source share