treat_strings_as_cols: treat_strings_as_cols

Description Usage Arguments Details Value Examples

Description

Take a list/vector of strings and use the values as column names.

Usage

1

Arguments

arg

the argument that holds a list of values to be used as column names.

Details

This is used to take the character values of a list or vector and use them as a comma separated list of column names in a dplyr function. The most common usage would be applied yo the values of a single argument, as in the 'select_these2' example, however it can also be used with ... to transform all ... values to column names - see 'select_these3' example.

Value

something that will resolve to a comma separated list of column names when prefixed with '!!!'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
select_these2 <- function(dat, cols){
  select(dat, !!!treat_strings_as_cols(cols))
}
select_these2(mtcars, cols = c("cyl", "wt"))

select_these3 <- function(dat, ...){
 dots <- list(...)
 select(dat, !!!treat_strings_as_cols(dots))
}
select_these3(mtcars, "cyl", "wt")

select_not_these <- function(dat, cols){
  select(dat, -c(!!!treat_strings_as_cols(cols)))
}
select_not_these(mtcars, cols = c("cyl", "wt"))


## End(Not run)

MilesMcBain/rlung documentation built on May 21, 2019, 9:22 a.m.