Skip to content

Should indices_to go to left of value column? #1486

Closed

Description

@hadley

In unnest_longer()? Since you normally expect the name of something to come first.

Activity

  1. DavisVaughan commented on Feb 16, 2023

    @DavisVaughan
    Member

    Seems reasonable to me

  2. added
    featurea feature request or enhancement
    nesting 🐦nesting, chopping, and packing
    on Nov 1, 2023
  3. DavisVaughan commented on Sep 8, 2025

    @DavisVaughan
    Member

    This seems like a good tidy dev day issue, I think you'd need to look at new_long_indexed_frame() in particular, and make sure tests get updated to account for the new order, and add a NEWS bullet.

    Here are some examples of what we mean by this:

    library(tidyr)
    
    df <- tibble(
      x = 1:4,
      y = list(NULL, 1:3, 4:5, integer())
    )
    
    # i.e. should `index` come before `y`?
    df |> unnest_longer(y, indices_to = "index")
    #> # A tibble: 5 × 3
    #>       x     y index
    #>   <int> <int> <int>
    #> 1     2     1     1
    #> 2     2     2     2
    #> 3     2     3     3
    #> 4     3     4     1
    #> 5     3     5     2
    
    
    # more examples
    
    df <- tibble(
      x = 1:2,
      y = list(1:2, 3:4),
      z = list(5:6, 7:8)
    )
    df |>
      unnest_longer(c(y, z), indices_to = "{col}_id")
    #> # A tibble: 4 × 5
    #>       x     y  y_id     z  z_id
    #>   <int> <int> <int> <int> <int>
    #> 1     1     1     1     5     1
    #> 2     1     2     2     6     2
    #> 3     2     3     1     7     1
    #> 4     2     4     2     8     2
    
    
    df <- tibble(
      x = 1:2,
      y = list(c(a = 1, b = 2), c(a = 10, b = 11, c = 12))
    )
    df |> unnest_longer(y, indices_to = "foo")
    #> # A tibble: 5 × 3
    #>       x     y foo  
    #>   <int> <dbl> <chr>
    #> 1     1     1 a    
    #> 2     1     2 b    
    #> 3     2    10 a    
    #> 4     2    11 b    
    #> 5     2    12 c
  4. added 2 commits that reference this issue on Sep 19, 2025
    2069d2b
    22eb77c
  5. added a commit that references this issue on Sep 19, 2025
    ff9b893
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementnesting 🐦nesting, chopping, and packingtidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions