friendlyeval (version 0.1.1)

treat_strings_as_cols: treat_strings_as_cols

Description

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

Usage

treat_strings_as_cols(arg)

Arguments

arg

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

Value

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

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.

Examples

Run this code
# 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"))

# }

Run the code above in your browser using DataLab