| 1 |
|
| 2 |
tidyselect implements a DSL for selecting variables. It provides helpers |
| 3 |
for selecting variables: |
| 4 |
|
| 5 |
- `var1:var10`: variables lying between `var1` on the left and `var10` on the right. |
| 6 |
* [`starts_with("a")`][tidyselect::starts_with]: names that start with `"a"`. |
| 7 |
* [`ends_with("z")`][tidyselect::ends_with]: names that end with `"z"`. |
| 8 |
* [`contains("b")`][tidyselect::contains]: names that contain `"b"`. |
| 9 |
* [`matches("x.y")`][tidyselect::matches]: names that match regular expression `x.y`. |
| 10 |
* [`num_range(x, 1:4)`][tidyselect::num_range]: names following the pattern, `x1`, `x2`, ..., `x4`. |
| 11 |
* [`all_of(vars)`][tidyselect::all_of]/[`any_of(vars)`][tidyselect::any_of()]: |
| 12 |
matches names stored in the character vector `vars`. `all_of(vars)` will |
| 13 |
error if the variables aren't present; `any_of(var)` will match just the |
| 14 |
variables that exist. |
| 15 |
* [`everything()`][tidyselect::everything]: all variables. |
| 16 |
* [`last_col()`][tidyselect::last_col]: furthest column on the right. |
| 17 |
* [`where(is.numeric)`][tidyselect::where]: all variables where |
| 18 |
`is.numeric()` returns `TRUE`. |
| 19 |
|
| 20 |
As well as operators for combining those selections: |
| 21 |
|
| 22 |
- `!selection`: only variables that don't match `selection`. |
| 23 |
- `selection1 & selection2`: only variables included in both `selection1` and `selection2`. |
| 24 |
- `selection1 | selection2`: all variables that match either `selection1` or `selection2`. |
| 25 |
|
| 26 |
When writing code inside packages you can substitute `"var"` for `var` to avoid `R CMD check` notes. |