Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nest() and unnest() don't work with some names #123

Closed
mitchelloharawild opened this issue Jun 5, 2019 · 0 comments
Closed

nest() and unnest() don't work with some names #123

mitchelloharawild opened this issue Jun 5, 2019 · 0 comments

Comments

@mitchelloharawild
Copy link
Member

nest()

Cannot nest into a column with the same name as a column in the nested dataset.

library(tidyverse)
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following object is masked from 'package:dplyr':
#> 
#>     id
tourism %>% 
  as_tibble %>% 
  nest(-Purpose, .key = "Trips")
#> # A tibble: 4 x 2
#>   Purpose  Trips               
#>   <chr>    <list>              
#> 1 Business <tibble [6,080 × 4]>
#> 2 Holiday  <tibble [6,080 × 4]>
#> 3 Other    <tibble [6,080 × 4]>
#> 4 Visiting <tibble [6,080 × 4]>
tourism %>% 
  nest(-Purpose, .key = "Trips")
#> Error in .subset2(x, i): attempt to select less than one element in get1index

Created on 2019-06-05 by the reprex package (v0.2.1)

unnest_tsibble()

Suppose the above was possible. unnest_tsibble() will incorrectly identify no tsibble columns that are being unnested.

library(tidyverse)
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following object is masked from 'package:dplyr':
#> 
#>     id
nested_tourism <- tourism %>% 
  as_tibble %>% 
  nest(-Purpose, .key = "Trips") %>% 
  mutate(Trips = map(Trips, as_tsibble, key = c("Region", "State"), index = Quarter)) %>% 
  new_tibble(., nrow = NROW(.), subclass = "lst_ts")

nested_tourism
#> # A tibble: 4 x 2
#>   Purpose  Trips                
#>   <chr>    <list>               
#> 1 Business <tsibble [6,080 × 4]>
#> 2 Holiday  <tsibble [6,080 × 4]>
#> 3 Other    <tsibble [6,080 × 4]>
#> 4 Visiting <tsibble [6,080 × 4]>

nested_tourism %>% 
  unnest_tsibble("Trips")
#> Unnested columns contain no tsibble object.

nested_tourism %>% 
  as_tibble %>% 
  unnest(Trips)
#> # A tibble: 24,320 x 5
#>    Purpose  Quarter    Region   State           Trips
#>    <chr>    <date>     <chr>    <chr>           <dbl>
#>  1 Business 1998-01-01 Adelaide South Australia  135.
#>  2 Business 1998-04-01 Adelaide South Australia  110.
#>  3 Business 1998-07-01 Adelaide South Australia  166.
#>  4 Business 1998-10-01 Adelaide South Australia  127.
#>  5 Business 1999-01-01 Adelaide South Australia  137.
#>  6 Business 1999-04-01 Adelaide South Australia  200.
#>  7 Business 1999-07-01 Adelaide South Australia  169.
#>  8 Business 1999-10-01 Adelaide South Australia  134.
#>  9 Business 2000-01-01 Adelaide South Australia  154.
#> 10 Business 2000-04-01 Adelaide South Australia  169.
#> # … with 24,310 more rows

Created on 2019-06-05 by the reprex package (v0.2.1)

earowang added a commit that referenced this issue Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant