Skip to content

Commit

Permalink
Use new quarto chunk style
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Oct 25, 2024
1 parent 23e00ac commit bcef4c6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 26 deletions.
4 changes: 3 additions & 1 deletion man/faq/external-vector.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

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

## Ambiguity between columns and external variables
Expand Down
4 changes: 3 additions & 1 deletion man/faq/selection-context.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

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

Functions like `starts_with()`, `contains()` or `matches()` are
Expand Down
3 changes: 2 additions & 1 deletion man/faq/setup.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

```{r, include = FALSE}
```{r}
#| include: FALSE
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
Expand Down
4 changes: 3 additions & 1 deletion man/rmd/setup.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

```{r, include = FALSE}
```{r}
#| include: FALSE
options(
tibble.print_min = 4,
tibble.max_extra_cols = 8,
Expand Down
34 changes: 22 additions & 12 deletions vignettes/syntax.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r}
#| include: FALSE
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
Expand All @@ -23,7 +25,7 @@ options(

This is a technical description of the tidyselect syntax.

```{r setup}
```{r}
library(tidyselect)
library(magrittr)
Expand Down Expand Up @@ -63,9 +65,9 @@ variables).

Today, the syntax of tidyselect is generally designed around Boolean algebra,
i.e. we recommend writing `starts_with("a") & !ends_with("z")`. Earlier
versions of tidyselect had more of a flavour of set operations, so that
versions of tidyselect had more of a flavour of set operations, so that
you'd write `starts_with("a") - ends_with("b")`. While the set operations are
still supported, and is how tidyselect represents variables internally, we no
still supported, and is how tidyselect represents variables internally, we no
longer recommend them because Boolean algebra is easy for people to
understand.

Expand Down Expand Up @@ -299,7 +301,8 @@ on the kind of expression:
includes bare symbols, the boolean operators, `-`, `:`, and `c()`.
You can't refer to environment-variables in a data-expression:

```{r, error = TRUE}
```{r}
#| error: true
cyl_pos <- 2
mtcars %>% select_loc(mpg | cyl_pos)
```
Expand All @@ -309,7 +312,8 @@ on the kind of expression:
symbols that are part of those calls. You can't refer to
data-variables in a data-expression:
```{r, error = TRUE}
```{r}
#| error: true
mtcars %>% select_loc(all_of(mpg))
```
Expand Down Expand Up @@ -352,7 +356,8 @@ overridden to cause an error. This is to prevent confusion stemming
from normal data masking usage where variables can be transformed on
the fly:

```{r, error = TRUE}
```{r}
#| error: true
mtcars %>% select_loc(cyl^2)
mtcars %>% select_loc(mpg * wt)
Expand All @@ -372,7 +377,8 @@ Unlike `eval_select()` which can select without renaming,
`eval_rename()` expects a fully named selection. If one or several
names are missing, an error is thrown.

```{r, error = TRUE}
```{r}
#| error: true
mtcars %>% select_loc(mpg)
mtcars %>% rename_loc(mpg)
Expand All @@ -385,7 +391,8 @@ If the input data is a data frame, tidyselect generally throws an
error when duplicate column names are selected, in order to respect
the invariant of unique column names.

```{r, error = TRUE}
```{r}
#| error: true
# Lists can have duplicates
as.list(mtcars) %>% select_loc(foo = mpg, foo = cyl)
Expand All @@ -396,15 +403,17 @@ mtcars %>% select_loc(foo = mpg, foo = cyl)
A selection can rename a variable to an existing name if the latter is
not part of the selection:

```{r, error = TRUE}
```{r}
#| error: true
mtcars %>% select_loc(cyl, cyl = mpg)
mtcars %>% select_loc(disp, cyl = mpg)
```

This is not possible when renaming.

```{r, error = TRUE}
```{r}
#| error: true
mtcars %>% rename_loc(cyl, cyl = mpg)
mtcars %>% rename_loc(disp, cyl = mpg)
Expand Down Expand Up @@ -442,7 +451,8 @@ dups %>% select_loc(y)

If the duplicates are selected, this is an error:

```{r, error = TRUE}
```{r}
#| error: true
dups %>% select_loc(x)
```

Expand Down
30 changes: 20 additions & 10 deletions vignettes/tidyselect.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r}
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
```{r}
#| label: setup
library(tidyselect)
library(magrittr)
```

```{r, include = FALSE}
```{r}
#| include: false
# For better printing
mtcars <- tibble::as_tibble(mtcars)
iris <- tibble::as_tibble(iris)
Expand Down Expand Up @@ -49,15 +52,17 @@ selections.

- Passing __dots__ as in `dplyr::select()`.

```{r, eval = FALSE}
```{r}
#| eval: false
mtcars %>% dplyr::select(mpg, cyl)
```
- Interpolating __named arguments__ as in `tidyr::pivot_longer()`. In
this case, multiple inputs can be provided inside `c()` or by using
boolean operators:
```{r, eval = FALSE}
```{r}
#| eval: false
mtcars %>% pivot_longer(c(mpg, cyl))
mtcars %>% pivot_longer(mpg | cyl)
```
Expand All @@ -83,7 +88,8 @@ The following examples illustrate how you could write a function that
takes a selection of data and returns the corresponding data frame
with capitalised names:
```{r, eval = FALSE}
```{r}
#| eval: false
# Passing dots
toupper_dots <- function(data, ...) {
sel <- dplyr::select(data, ...)
Expand Down Expand Up @@ -181,7 +187,8 @@ The data-vars inside the data frame are combined with the env-vars of
the environment, making it possible for users to refer to their data
variables:

```{r, error = TRUE}
```{r}
#| error: true
NULL %>% with_data(mean(cyl) * 10)
mtcars %>% with_data(mean(cyl) * 10)
Expand Down Expand Up @@ -279,7 +286,8 @@ particular it throws an error if the selected inputs are unnamed. In
practice, `eval_rename()` only accepts a `c()` expression as `expr`
argument, and all inputs inside the outermost `c()` must be named:

```{r, error = TRUE}
```{r}
#| error: true
eval_rename(rlang::expr(mpg), mtcars)
eval_rename(rlang::expr(c(mpg)), mtcars)
Expand Down Expand Up @@ -366,7 +374,8 @@ mtcars %>% select(if_width(2))
The `fn` argument makes the error message more informative when the
helper is used in the wrong context:

```{r, error = TRUE}
```{r}
#| error: true
mtcars[if_width(2)]
```

Expand Down Expand Up @@ -408,7 +417,8 @@ if_width <- function(n, vars = peek_vars(fn = "if_width")) {
If the input is a data frame, the user is now informed that their
selection should not contain duplicates:

```{r, error = TRUE}
```{r}
#| error: true
dups %>% select(if_width(3))
```

Expand Down

0 comments on commit bcef4c6

Please sign in to comment.