1## ----setup, echo = FALSE, message = FALSE-------------------------------------
2knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
3options(tibble.print_min = 6L, tibble.print_max = 6L)
4set.seed(1014)
5
6# Manually "import"; only needed for old dplyr which uses old tidyselect
7# which doesn't attach automatically in tidy-select contexts
8all_of <- tidyselect::all_of
9
10## -----------------------------------------------------------------------------
11library(tidyr)
12
13iris %>%
14  nest(data = !Species)
15
16## -----------------------------------------------------------------------------
17packageVersion("tidyr")
18
19mini_iris <- as_tibble(iris)[c(1, 2, 51, 52, 101, 102), ]
20mini_iris
21
22## -----------------------------------------------------------------------------
23nest_egg <- function(df, cols) {
24  nest(df, egg = {{ cols }})
25}
26
27nest_egg(mini_iris, !Species)
28
29## -----------------------------------------------------------------------------
30nest_egg <- function(df, cols) {
31  nest(df, egg = all_of(cols))
32}
33
34vars <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
35nest_egg(mini_iris, vars)
36
37## -----------------------------------------------------------------------------
38sel_vars <- function(df, cols) {
39  tidyselect::eval_select(rlang::enquo(cols), df)
40}
41sel_vars(mini_iris, !Species)
42
43