How to use tidyeval on a column to mutate?

后端 未结 2 1062
天涯浪人
天涯浪人 2020-12-19 23:34

I\'m sorry for the confusion but eventually, the first example I posted (at the bottom of the page), did not help me to figure out how tidyeval works with mutate, so I\'m ad

2条回答
  •  余生分开走
    2020-12-19 23:46

    As the error says "Error: LHS must be a name or string" where LHS means left-hand side and it's specifically referring to the !!col := 1 part. You need to turn the quosure you made into a string or symbol. It's probably easiest to get the string version of the quosure with quo_name

    colTo1 <- function(dt, ...) {
        col <- quo_name(quo(...))
        mutate(mtcars, !!col := 1)
    }
    

提交回复
热议问题