Skip to content

Improve separate() error when no sep specified #375

Description

@pgensler

This is not very informative, other than the underlying logic failed

data2 <- c(
  'Order/ID : IN-2013-77878',
  'Order/Date : 2/5/13',
  'Ship/Mode: Second Class',
  'product/id : TEC-AC-10003033',
  '   ',
  'Order/ID : IN-2013-77878',
  'Order/Date : 2/8/13',
  'Ship/Mode: Second Class',
  'product/id : FUR-CH-10004050'
)


> data <- tibble::enframe(data2) %>%
+   select(value) %>%
+   filter(., str_detect(value,':')) %>%
+   separate(., value, into = c('var','val')) # use tidyr's seperate to split data
Warning message:
Too many values at 8 locations: 1, 2, 3, 4, 5, 6, 7, 8 

It fails due to no sep argument, so maybe outputting an error message stating "Hey are you missing a separator argument?)

This works:

data <- tibble::enframe(data2) %>%
  select(value) %>%
  filter(., str_detect(value,':')) %>%
  separate(., value, into = c('var','val'), sep = ':')

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions