dplyr 0.7 equivalent for deprecated mutate_

前端 未结 2 842
暗喜
暗喜 2020-12-17 22:47

I cannot find in dplyr 0.7 a way to replace the mutate_ function which is going to be deprecated.

The mutate_ function is useful in my

2条回答
  •  半阙折子戏
    2020-12-17 23:27

    To expand a little bit on MrFlick's example, let's assume you have a number of instructions stored as strings, as well as the corresponding names that you want to assign to the resulting computations:

    ln <- list( "test2", "test3" )
    lf <- list( "substr(test, 1, 5)", "substr(test, 5, 5)" )
    

    Match up names to their instructions and convert everything to quosures:

    ll <- setNames( lf, ln ) %>% lapply( rlang::parse_quosure )
    

    As per aosmith's suggestion, the entire list can now be passed to mutate, using the special !!! operator:

    tibble( test = "test@test" ) %>% mutate( !!! ll )
    # # A tibble: 1 x 3
    #        test test2 test3
    #         
    # 1 test@test test@     @
    

提交回复
热议问题