These scoped variants of select()
and rename()
operate on a
selection of variables. The semantics of these verbs have simple
but important differences:
Selection drops variables that are not in the selection while renaming retains them.
The renaming function is optional for selection but not for renaming.
select_all(.tbl, .funs = list(), ...)rename_all(.tbl, .funs = list(), ...)
select_if(.tbl, .predicate, .funs = list(), ...)
rename_if(.tbl, .predicate, .funs = list(), ...)
select_at(.tbl, .vars, .funs = list(), ...)
rename_at(.tbl, .vars, .funs = list(), ...)
A tbl
object.
A single expression quoted with funs()
or within a
quosure, a string naming a function, or a function.
Additional arguments for the function calls in
.funs
. These are evaluated only once, with explicit
splicing.
A predicate function to be applied to the columns
or a logical vector. The variables for which .predicate
is or
returns TRUE
are selected. This argument is passed to
rlang::as_function()
and thus supports quosure-style lambda
functions and strings representing function names.
A list of columns generated by vars()
,
or a character vector of column names, or a numeric vector of column
positions.
# NOT RUN {
# Supply a renaming function:
select_all(mtcars, toupper)
select_all(mtcars, "toupper")
select_all(mtcars, funs(toupper(.)))
# Selection drops unselected variables:
is_whole <- function(x) all(floor(x) == x)
select_if(mtcars, is_whole, toupper)
# But renaming retains them:
rename_if(mtcars, is_whole, toupper)
# The renaming function is optional for selection:
select_if(mtcars, is_whole)
# }
Run the code above in your browser using DataLab