Skip to content

This is a method for the tidyr tidyr::nest() generic. It is translated using the non-nested variables in the by argument and .SD in the j argument.


# S3 method for dtplyr_step
nest(.data, ..., .names_sep = NULL, .key = deprecated())



A data frame.


<tidy-select> Columns to nest, specified using name-variable pairs of the form new_col = c(col1, col2, col3). The right hand side can be any valid tidy select expression.


If NULL, the default, the names will be left as is. In nest(), inner names will come from the former outer names; in unnest(), the new outer names will come from the inner names.

If a string, the inner and outer names will be used together. In nest(), the names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by names_sep. In unnest(), the new inner names will have the outer names (+ names_sep) automatically stripped. This makes names_sep roughly symmetric between nesting and unnesting.


Not supported.


A lazy_dt().


if (require("tidyr", quietly = TRUE)) {
  dt <- lazy_dt(tibble(x = c(1, 2, 1), y = c("a", "a", "b")))
  dt %>% nest(data = y)

  dt %>% dplyr::group_by(x) %>% nest()
#> Source: local data table [2 x 2]
#> Groups: x
#> Call:   `_DT24`[, .(data = .(.SD)), by = .(x)]
#>       x data                
#>   <dbl> <list>              
#> 1     1 <data.table [2 × 1]>
#> 2     2 <data.table [1 × 1]>
#> # Use to access results