From bcef4c69f59f8dd2f554d85f7fa94003e98e42e0 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Fri, 25 Oct 2024 12:45:12 +0200 Subject: [PATCH] Use new quarto chunk style https://github.com/r-lib/usethis/issues/1913 --- man/faq/external-vector.Rmd | 4 +++- man/faq/selection-context.Rmd | 4 +++- man/faq/setup.Rmd | 3 ++- man/rmd/setup.Rmd | 4 +++- vignettes/syntax.Rmd | 34 ++++++++++++++++++++++------------ vignettes/tidyselect.Rmd | 30 ++++++++++++++++++++---------- 6 files changed, 53 insertions(+), 26 deletions(-) diff --git a/man/faq/external-vector.Rmd b/man/faq/external-vector.Rmd index 5238bc93..15878ad2 100644 --- a/man/faq/external-vector.Rmd +++ b/man/faq/external-vector.Rmd @@ -1,5 +1,7 @@ -```{r, child = "setup.Rmd", include = FALSE} +```{r} +#| child: "setup.Rmd" +#| include: FALSE ``` ## Ambiguity between columns and external variables diff --git a/man/faq/selection-context.Rmd b/man/faq/selection-context.Rmd index eaec09d9..27c7467c 100644 --- a/man/faq/selection-context.Rmd +++ b/man/faq/selection-context.Rmd @@ -1,5 +1,7 @@ -```{r, child = "setup.Rmd", include = FALSE} +```{r} +#| child: "setup.Rmd" +#| include: FALSE ``` Functions like `starts_with()`, `contains()` or `matches()` are diff --git a/man/faq/setup.Rmd b/man/faq/setup.Rmd index 0e3c7565..b5dc2163 100644 --- a/man/faq/setup.Rmd +++ b/man/faq/setup.Rmd @@ -1,5 +1,6 @@ -```{r, include = FALSE} +```{r} +#| include: FALSE knitr::opts_chunk$set( collapse = TRUE, comment = "#>" diff --git a/man/rmd/setup.Rmd b/man/rmd/setup.Rmd index cfbb0943..23db638a 100644 --- a/man/rmd/setup.Rmd +++ b/man/rmd/setup.Rmd @@ -1,5 +1,7 @@ -```{r, include = FALSE} +```{r} +#| include: FALSE + options( tibble.print_min = 4, tibble.max_extra_cols = 8, diff --git a/vignettes/syntax.Rmd b/vignettes/syntax.Rmd index c2c0dd4d..2c11c0e8 100644 --- a/vignettes/syntax.Rmd +++ b/vignettes/syntax.Rmd @@ -7,7 +7,9 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r, include = FALSE} +```{r} +#| include: FALSE + knitr::opts_chunk$set( collapse = TRUE, comment = "#>" @@ -23,7 +25,7 @@ options( This is a technical description of the tidyselect syntax. -```{r setup} +```{r} library(tidyselect) library(magrittr) @@ -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. @@ -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) ``` @@ -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)) ``` @@ -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) @@ -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) @@ -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) @@ -396,7 +403,8 @@ 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) @@ -404,7 +412,8 @@ 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) @@ -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) ``` diff --git a/vignettes/tidyselect.Rmd b/vignettes/tidyselect.Rmd index 0adf1e13..64808976 100644 --- a/vignettes/tidyselect.Rmd +++ b/vignettes/tidyselect.Rmd @@ -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) @@ -49,7 +52,8 @@ selections. - Passing __dots__ as in `dplyr::select()`. - ```{r, eval = FALSE} + ```{r} + #| eval: false mtcars %>% dplyr::select(mpg, cyl) ``` @@ -57,7 +61,8 @@ selections. 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) ``` @@ -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, ...) @@ -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) @@ -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) @@ -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)] ``` @@ -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)) ```