File: faq-selection-context.Rd

package info (click to toggle)
r-cran-tidyselect 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 556 kB
  • sloc: sh: 13; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/faq.R
\name{faq-selection-context}
\alias{faq-selection-context}
\title{FAQ - Error: Must be used within a \emph{selecting} function}
\description{
Functions like \code{starts_with()}, \code{contains()} or \code{matches()} are
\strong{selection helpers} that only work in a selection context.

Examples of valid selection contexts are:
\itemize{
\item Inside \code{dplyr::select()}.
\item The \code{cols} argument of \code{tidyr::pivot_longer()}.
}

Using a selection helper anywhere else results in an error:\if{html}{\out{<div class="r">}}\preformatted{starts_with("foo")
#> Error: `starts_with()` must be used within a *selecting* function.
#> i See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.

mtcars[contains("foo")]
#> Error: `contains()` must be used within a *selecting* function.
#> i See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.

subset(mtcars, select = matches("foo"))
#> Error: `matches()` must be used within a *selecting* function.
#> i See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.
}\if{html}{\out{</div>}}

If you see this error, you’ve probably used a selection helper in the
wrong place, possibly as the result of a typo (e.g. misplaced comma or
wrong argument name).
}