Description Usage Arguments Details Value Examples
Take what was input and treat it as a column name argument to a dplyr function.
1 | treat_input_as_col(arg)
|
arg |
the argument for which the literal input text is to be used as a column name. |
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.
Something that will resolve to a column named when prefixed with !!.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.