Skip to content

separate_wider_regex(), names_sep, and too_few #1425

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

Closed
jennybc opened this issue Nov 18, 2022 · 0 comments · Fixed by #1448
Closed

separate_wider_regex(), names_sep, and too_few #1425

jennybc opened this issue Nov 18, 2022 · 0 comments · Fixed by #1448
Assignees
Milestone

Comments

@jennybc
Copy link
Member

jennybc commented Nov 18, 2022

Moving from Slack.

I just used separate_wider_regex() on a tibble created with parsermd on the section headings from a chapter from R Packages.

It turns out I needed to specify names_sep and too_few, but those user errors interact with each other in a way that makes it harder to figure out what's wrong.

library(tidyverse)

x <- tribble(
  ~ sec_h1, ~ sec_h2,
  "Intro {intro}", NA,
  "First cool thing {first-cool-thing}", NA,
  "First cool thing {first-cool-thing}", "First cool details {first-cool-details}",
  "Second cool thing", NA
)
x |> 
  separate_wider_regex(
    everything(),
    c("text" = "[^\\{]*", " [{]", label = ".*", "[}]"),
    too_few = "debug"
  )
#> Warning: Debug mode activated: adding variables `sec_h1_ok`, `sec_h1_matches`, and
#> `sec_h1_remainder`.
#> Warning: Debug mode activated: adding variables `sec_h2_ok`, `sec_h2_matches`, and
#> `sec_h2_remainder`.
#> Error in `unpack()`:
#> ! Names must be unique.
#> ✖ These names are duplicated:
#>   * "text" at locations 1 and 7.
#>   * "label" at locations 2 and 8.
#> ℹ Use argument `names_repair` to specify repair strategy.

I think I should be getting scolded first and foremost for not specifying names_sep, which is actually required since cols = everything(). That is the root cause of the unpack() error but the suggested remedy is off-base.

I'd probably also be happy with some default choice of names_sep (related #1367).

Until you get the naming stuff straightened out, you can't see the cool too_few = "debug" diagnostics.

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

Successfully merging a pull request may close this issue.

3 participants