From 9eb33d8dcca527d4429fc6422d0ee5197f81b0a9 Mon Sep 17 00:00:00 2001 From: Maria Paula Caldas <33395215+mpaulacaldas@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:43:41 +0200 Subject: [PATCH] Provide arguments to nest() and unnest() to get rid of warnings (#825) --- model-many.Rmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/model-many.Rmd b/model-many.Rmd index 83ba13c..331be20 100644 --- a/model-many.Rmd +++ b/model-many.Rmd @@ -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.