Functional programming with dplyr

后端 未结 2 1295
臣服心动
臣服心动 2021-01-02 14:42

Looking for a more efficient / elegant way to pass multiple arguments to a group-by using non-standard evaluation in a function using dplyr. I don\'t want to use the ... ope

2条回答
  •  一向
    一向 (楼主)
    2021-01-02 15:02

    You could just do a straight eval.parent(substitute(...)) like this. Being base R it works consistently across R and is simple to do. One can even use an ordinary aes.

    plot_lines <- function(df, x, y, group) eval.parent(substitute(
       df %>%
          group_by(x, group) %>%
          my_smry %>%
          ggplot + geom_line(aes(x = x, y = y, group = group, color = group))
    ))
    plot_lines(my_df, month, conversion_rate, category)
    

提交回复
热议问题