I'm wondering if there is a DRY way to write the following pipe:
library(tidyverse)
data(iris)
iris %>% arrange(Sepal.Width, Species) %>% select(Sepal.Width, Species)
This works perfectly but if a change in the code is needed, I have two places to edit.
Is there any way to rewrite the code in such a way that the variables are listed only once in the pipeline?
I'd hope there is a way I can store the variable list v
and then call:
iris %>% arrange(v) %>% select(v)
I've tried to use quote
, Sym
, and many other functions of Non Standard Evaluation in order to store the list of variables to no avail.
All those answers were unhelpful for this problem:
r - how to use a variable in a variable