dplyr 'rename' standard evaluation function not working as expected?

前端 未结 2 805
终归单人心
终归单人心 2020-12-13 15:53

UPDATE: From comment below on this post, this is now working as expected, without the issues I laid out here.

Below is a toy example of using rename_ fr

2条回答
  •  半阙折子戏
    2020-12-13 16:25

    In my Rstudio, I define:

    x <- 'myname'
    dat <- data.frame(yes=1, no=2)
    

    I want to change the variable name from yes to myname

    It doesn't work:

    rename_(dat, .dots = setNames(x, "yes"))
    

    But this works:

    rename_(dat, .dots = setNames("yes", x))
    
    rename_(dat, .dots = setNames("yes", paste(x) ))
    

提交回复
热议问题