Provide arguments to nest() and unnest() to get rid of warnings (#825)

This commit is contained in:
Maria Paula Caldas 2020-10-03 16:43:41 +02:00 committed by GitHub
parent 50adc6a9f3
commit 9eb33d8dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -351,7 +351,7 @@ You can also use it on an ungrouped data frame, specifying which columns you wan
```{r}
gapminder %>%
nest(year:gdpPercap)
nest(data = c(year:gdpPercap))
```
### From vectorised functions
@ -374,7 +374,7 @@ df %>%
```{r}
df %>%
mutate(x2 = stringr::str_split(x1, ",")) %>%
unnest()
unnest(x2)
```
(If you find yourself using this pattern a lot, make sure to check out `tidyr::separate_rows()` which is a wrapper around this common pattern).
@ -420,7 +420,7 @@ probs <- c(0.01, 0.25, 0.5, 0.75, 0.99)
mtcars %>%
group_by(cyl) %>%
summarise(p = list(probs), q = list(quantile(mpg, probs))) %>%
unnest()
unnest(c(p, q))
```
### From a named list
@ -464,7 +464,7 @@ df %>%
mtcars %>%
group_by(cyl) %>%
summarise(q = list(quantile(mpg))) %>%
unnest()
unnest(q)
```
1. What does this code do? Why might might it be useful?
@ -540,7 +540,7 @@ df1 <- tribble(
2, "c", 3
)
df1
df1 %>% unnest(y, z)
df1 %>% unnest(c(y, z))
# Doesn't work because y and z have different number of elements
df2 <- tribble(
@ -549,7 +549,7 @@ df2 <- tribble(
2, c("b", "c"), 3
)
df2
df2 %>% unnest(y, z)
df2 %>% unnest(c(y, z))
```
The same principle applies when unnesting list-columns of data frames. You can unnest multiple list-cols as long as all the data frames in each row have the same number of rows.