select_all: Select and rename a selection of variables

Description Usage Arguments Examples

Description

These scoped variants of select() and rename() operate on a selection of variables. The semantics of these verbs have subtle but important differences:

The _if and _at variants always retain grouping variables for grouped data frames.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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(), ...)

Arguments

.tbl

A tbl object.

.funs

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 tidy dots support.

.predicate

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.

.vars

A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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)
select_at(mtcars, vars(-contains("ar"), starts_with("c")), toupper)

# But renaming retains them:
rename_if(mtcars, is_whole, toupper)
rename_at(mtcars, vars(-(1:3)), toupper)
rename_all(mtcars, toupper)

# The renaming function is optional for selection:
select_if(mtcars, is_whole)
select_at(mtcars, vars(-everything()))
select_all(mtcars)

olascodgreat/samife documentation built on May 13, 2019, 6:11 p.m.