I'd like to a create a new verb for dplyr flollowing this StackOverflow
post and am seeking help on getting started.
While my "production code" uses the pick function shown in the question inside of mutate (hard coded to only choose from 4 columns), I'd rather be able to choose from any set of columns. Thinking about the problem some more, I came up with the pipeline below (at the bottom of this post). However, instead of typing that block of code every time, I'd like to turn it into a function. How would I go about it? I'm especially confused the non-standard evaluation of columns.
What I want:
df %>% consolidate(cols = y1:y4, pick = x)
What I have:
df %>%
mutate(row = row_number()) %>%
gather(n, y, y1:y4) %>%
mutate(n = as.integer(str_extract(n, "[0-9]+"))) %>%
filter(x == n) %>%
arrange(row) %>%
select(-c(row, n))