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

Convert negative fwf widths to positive #380

Merged
merged 1 commit into from Jun 9, 2016
Merged

Conversation

@leeper
Copy link
Contributor

@leeper leeper commented Mar 10, 2016

This is a really simple change that allows someone to specify negative column widths when using read_fwf(). To demonstrate the problem here's a comparison of read.fwf() versus read_fwf() when one wants to skip a column:

> read.fwf(fwf_sample, widths = c(5, -1, 4), col.names = letters[c(1,3)])
      a    c
1 12345 7890
2 12345 7890
3 12345 7890
4 12345 7890
5 12345 7890
> read_fwf(fwf_sample, fwf_widths(c(5, -1, 4), letters[1:3]), col_types = cols(a = "i", b = "_", c = "i"))
Error: Begin offset (5) must be smaller than end offset (4)

If a user is porting code from read.fwf() to readr, they are very likely to have negative column widths. This PR simply converts width to positive values as required by fwf_widths(), such that the result of the above is:

> read_fwf(fwf_sample, fwf_widths(c(5, -1, 4), letters[1:3]), col_types = cols(a = "i", b = "_", c = "i"))
      a    c
1 12345 7890
2 12345 7890
3 12345 7890
4 12345 7890
5 12345 7890
@hadley
Copy link
Member

@hadley hadley commented Jun 2, 2016

Could you please add a bullet to news?

@hadley
Copy link
Member

@hadley hadley commented Jun 9, 2016

Bump. Are you still interested in this?

@leeper leeper force-pushed the leeper:master branch to 1c82b28 Jun 9, 2016
@leeper
Copy link
Contributor Author

@leeper leeper commented Jun 9, 2016

Just added a note. (Sorry, had slipped my mind.)

@hadley hadley merged commit 424c90d into tidyverse:master Jun 9, 2016
1 check was pending
1 check was pending
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@hadley
Copy link
Member

@hadley hadley commented Jun 9, 2016

Thanks!

@hadley hadley removed the in progress label Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants