treat_input_as_col: treat_input_as_col

Description Usage Arguments Details Value Examples

Description

Take what was input and treat it as a column name argument to a dplyr function.

Usage

1

Arguments

arg

the argument for which the literal input text is to be used as a column name.

Details

This is used inside a function to pass the literal text of what the caller typed as an argument to a 'dplyr' function. When using 'dplyr' the text will typically be destined for a column name argument. See examples for usage scenarios.

Value

Something that will resolve to a column named when prefixed with !!.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
select_this <- function(a_col){
 select(mtcars, !!treat_input as_col(a_col))
}
select_this(cyl)

mean_this <- function(a_col){
 mutate(mtcars, result = mean(!!treat_input_as_col(a_col)))
}
mean_this(cyl)

filter_same <- function(dat, x, y) {
 filter(dat, !!treat_input_as_col(x) == !!treat_input_as_col(y))
}
filter_same(mtcars, carb, gear)

## End(Not run)

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