dplyr 0.7 equivalent for deprecated mutate_

前端 未结 2 825
暗喜
暗喜 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:24

    Here's one alternative

    a <- "test2"
    b <- "test3"
    dplyr::tibble(test = "test@test") %>% 
    dplyr::mutate(a := !!rlang::parse_expr("substr(test, 1, 5)"),
      b := !!rlang::parse_expr("substr(test, 5, 5)"))
    # # A tibble: 1 x 3
    #        test     a     b
    #         
    # 1 test@test test@     @
    

    We use the := operator to dynamically name parameters with strings, and we parse the expression string for the transformation and unwrap it with !!

提交回复
热议问题