Legacy versions of nest() and unnest()
tidyr 1.0.0 introduced a new syntax for nest()
and unnest()
. The majority
of existing usage should be automatically translated to the new syntax with a
warning. However, if you need to quickly roll back to the previous behaviour,
these functions provide the previous interface. To make old code work as is,
add the following code to the top of your script:
library(tidyr) nest <- nest_legacy unnest <- unnest_legacy
nest_legacy(data, ..., .key = "data") unnest_legacy(data, ..., .drop = NA, .id = NULL, .sep = NULL, .preserve = NULL)
data |
A data frame. |
... |
Specification of columns to unnest. Use bare variable names or functions of variables. If omitted, defaults to all list-cols. |
.key |
The name of the new column, as a string or symbol. This argument
is passed by expression and supports
quasiquotation (you can unquote strings and
symbols). The name is captured from the expression with |
.drop |
Should additional list columns be dropped? By default,
|
.id |
Data frame identifier - if supplied, will create a new column with
name |
.sep |
If non- |
.preserve |
Optionally, list-columns to preserve in the output. These
will be duplicated in the same way as atomic vectors. This has
|
# Nest and unnest are inverses df <- data.frame(x = c(1, 1, 2), y = 3:1) df %>% nest_legacy(y) df %>% nest_legacy(y) %>% unnest_legacy() # nesting ------------------------------------------------------------------- as_tibble(iris) %>% nest_legacy(!Species) as_tibble(chickwts) %>% nest_legacy(weight) # unnesting ----------------------------------------------------------------- df <- tibble( x = 1:2, y = list( tibble(z = 1), tibble(z = 3:4) ) ) df %>% unnest_legacy(y) # You can also unnest multiple columns simultaneously df <- tibble( a = list(c("a", "b"), "c"), b = list(1:2, 3), c = c(11, 22) ) df %>% unnest_legacy(a, b) # If you omit the column names, it'll unnest all list-cols df %>% unnest_legacy()
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.