File: selection-context.Rmd

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 (25 lines) | stat: -rw-r--r-- 634 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

```{r, child = "setup.Rmd", include = FALSE}
```

Functions like `starts_with()`, `contains()` or `matches()` are
__selection helpers__ that only work in a selection context.

Examples of valid selection contexts are:

- Inside `dplyr::select()`.
- The `cols` argument of `tidyr::pivot_longer()`.

Using a selection helper anywhere else results in an error:

```{r, error = TRUE}
starts_with("foo")

mtcars[contains("foo")]

subset(mtcars, select = matches("foo"))
```

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).