-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathkeep_at.Rd
More file actions
40 lines (36 loc) · 1.41 KB
/
keep_at.Rd
File metadata and controls
40 lines (36 loc) · 1.41 KB
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/keep.R
\name{keep_at}
\alias{keep_at}
\alias{discard_at}
\title{Keep/discard elements based on their name/position}
\usage{
keep_at(x, at)
discard_at(x, at)
}
\arguments{
\item{x}{A list or atomic vector.}
\item{at}{A logical, integer, or character vector giving the elements
to select. Alternatively, a function that takes a vector of names,
and returns a logical, integer, or character vector of elements to select.
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}: if the tidyselect package is
installed, you can use \code{vars()} and tidyselect helpers to select
elements.}
}
\description{
\code{keep_at()} and \code{discard_at()} are similar to \code{[} or \code{dplyr::select()}: they
return the same type of data structure as the input, but only containing
the requested elements. (If you're looking for a function similar to
\code{[[} see \code{\link[=pluck]{pluck()}}/\code{\link[=chuck]{chuck()}}).
}
\examples{
x <- c(a = 1, b = 2, cat = 10, dog = 15, elephant = 5, e = 10)
x |> keep_at(letters)
x |> discard_at(letters)
# Can also use a function
x |> keep_at(\(x) nchar(x) == 3)
x |> discard_at(\(x) nchar(x) == 3)
}
\seealso{
\code{\link[=keep]{keep()}}/\code{\link[=discard]{discard()}} to keep/discard elements by value.
}