Skip to content

pivot_longer() regression with tibble 3.0.1 #949

@krlmlr

Description

@krlmlr

From tidyverse/tibble#766, CC @mvazquezs.

Is the previous behavior correct? Do we need a better error message?

tibble 2.1.3

library(tidyverse)

tibble(id = 1, x_1 = 1, x_2 = 2, y_1 = 1, y_2 = 2) %>%
  pivot_longer(
    cols = -id,
    names_to = c("x", "x_dil"),
    names_pattern = "(.+)_(.+)",
    values_to = c("mfi", "dil")
  )
#> # A tibble: 4 x 5
#>      id x     x_dil   mfi   dil
#>   <dbl> <chr> <chr> <dbl> <dbl>
#> 1     1 x     1         1    NA
#> 2     1 x     2        NA     2
#> 3     1 y     1         1    NA
#> 4     1 y     2        NA     2

Created on 2020-04-29 by the reprex package (v0.3.0)

tibble 3.0.1

library(tidyverse)

tibble(id = 1, x_1 = 1, x_2 = 2, y_1 = 1, y_2 = 2) %>%
  pivot_longer(
    cols = -id,
    names_to = c("x", "x_dil"),
    names_pattern = "(.+)_(.+)",
    values_to = c("mfi", "dil")
  )
#> Error: Assigned data `values_to` must be compatible with existing data.
#> x Existing data has 4 rows.
#> x Assigned data has 2 rows.
#> ℹ Only vectors of size 1 are recycled.

Created on 2020-04-29 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions