/
select_all.Rd
73 lines (60 loc) · 2.25 KB
/
select_all.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colwise-select.R
\name{select_all}
\alias{select_all}
\alias{rename_all}
\alias{select_if}
\alias{rename_if}
\alias{select_at}
\alias{rename_at}
\title{Select and rename a selection of variables}
\usage{
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{
\item{.tbl}{A \code{tbl} object.}
\item{.funs}{A single expression quoted with \code{\link[=funs]{funs()}} or within a
quosure, a string naming a function, or a function.}
\item{...}{Additional arguments for the function calls in
\code{.funs}. These are evaluated only once, with \link[rlang:tidy-dots]{tidy
dots} support.}
\item{.predicate}{A predicate function to be applied to the columns
or a logical vector. The variables for which \code{.predicate} is or
returns \code{TRUE} are selected. This argument is passed to
\code{\link[rlang:as_function]{rlang::as_function()}} and thus supports quosure-style lambda
functions and strings representing function names.}
\item{.vars}{A list of columns generated by \code{\link[=vars]{vars()}},
a character vector of column names, a numeric vector of column
positions, or \code{NULL}.}
}
\description{
These \link{scoped} variants of \code{\link[=select]{select()}} and \code{\link[=rename]{rename()}} operate on a
selection of variables. The semantics of these verbs have subtle
but important differences:
\itemize{
\item Selection drops variables that are not in the selection while
renaming retains them.
\item The renaming function is optional for selection but not for
renaming.
}
The \code{_if} and \code{_at} variants always retain grouping variables for grouped
data frames.
}
\examples{
# 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)
}