Skip to content

Confusing x column in debug output for separate_wider_delim #1735

@iimog

Description

@iimog

The "Strings" chapter has an example for debugging widening problems. However, due to the fact that both the original column and one of the output columns are named x, the output is a bit confusing:

df <- tibble(x = c("1-1-1", "1-1-2", "1-3", "1-3-2", "1"))

debug <- df |> 
  separate_wider_delim(
    x,
    delim = "-",
    names = c("x", "y", "z"),
    too_few = "debug"
  )
#> Warning: Debug mode activated: adding variables `x_ok`, `x_pieces`, and
#> `x_remainder`.
debug
#> # A tibble: 5 × 6
#>   x     y     z     x_ok  x_pieces x_remainder
#>   <chr> <chr> <chr> <lgl>    <int> <chr>      
#> 1 1-1-1 1     1     TRUE         3 ""         
#> 2 1-1-2 1     2     TRUE         3 ""         
#> 3 1-3   3     <NA>  FALSE        2 ""         
#> 4 1-3-2 3     2     TRUE         3 ""         
#> 5 1     <NA>  <NA>  FALSE        1 ""

The column x still has the original content, and while there are columns for the new y and z the new x column is missing. This can easily be resolved by using a different column name for the original column:

df <- tibble(a = c("1-1-1", "1-1-2", "1-3", "1-3-2", "1"))

debug <- df |> 
  separate_wider_delim(
    a,
    delim = "-",
    names = c("x", "y", "z"),
    too_few = "debug"
  )
#> Warning: Debug mode activated: adding variables `x_ok`, `x_pieces`, and
#> `x_remainder`.
debug
#> # A tibble: 5 × 7
#>   x     y       z       a     a_ok  a_pieces a_remainder
#>   <chr> <chr>   <chr>   <chr> <lgl>    <int> <chr>      
#> 1 1     1       1       1-1-1 TRUE         3 ""         
#> 2 1     1       2       1-1-2 TRUE         3 ""         
#> 3 1     3       <NA>    1-3   FALSE        2 ""         
#> 4 1     3       2       1-3-2 TRUE         3 ""         
#> 5 1     <NA>    <NA>    1     FALSE        1 ""

I'm happy to create a pull request if you agree that this should be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions