Skip to content
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

Improve separate() error when no sep specified #375

Closed
pgensler opened this issue Nov 10, 2017 · 1 comment
Closed

Improve separate() error when no sep specified #375

pgensler opened this issue Nov 10, 2017 · 1 comment
Labels
feature a feature request or enhancement strings 🎻

Comments

@pgensler
Copy link

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 = ':')
@hadley
Copy link
Member

hadley commented Nov 15, 2017

The default splits at non-alphanumeric symbols, which I think is useful. But maybe the error message could be more informative here

@hadley hadley added the feature a feature request or enhancement label Nov 15, 2017
@hadley hadley changed the title FR: add better error when no sep is specified Improve separate() better error when no sep specified Nov 16, 2017
@hadley hadley changed the title Improve separate() better error when no sep specified Improve separate() error when no sep specified Nov 16, 2017
@hadley hadley closed this as completed in 3b80146 Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement strings 🎻
Projects
None yet
Development

No branches or pull requests

2 participants