very nice, thanks! i wonder if we actually hit a limitation of select_at or select_if here. These seem to be the natural candidates for this kind of task, yet as you said, this is not easy to do
select_if doesn't seem to have access to the column names once the condition is wrapped inside funs, but the funs wrapper is necessary for the variance condition to work. I'm not sure how to resolve this, but here is an illustration of the issue:
library(tidyverse)
testdf <- data_frame(one = c(1,1,1),
two = c(1,2,3),
three = c(3,3,3))
testdf %>%
select_if(names(.)=="three")
#> # A tibble: 3 x 1
#> three
#> <dbl>
#> 1 3
#> 2 3
#> 3 3
testdf %>%
select_if(funs(names(.)=="three"))
#> Error in selected[[i]] <- .p(.tbl[[tibble_vars[[i]]]], ...): replacement has length zero
testdf %>%
select_if(var(.) != 0)
#> Error in tbl_if_vars(.tbl, .predicate, caller_env(), .include_group_vars = TRUE): length(.p) == length(tibble_vars) is not TRUE
testdf %>%
select_if(funs(var(.) != 0))
#> # A tibble: 3 x 1
#> two
#> <dbl>
#> 1 1
#> 2 2
#> 3 3