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

Conversation

Projects
None yet
2 participants
@leeper
Contributor

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

This comment has been minimized.

Member

hadley commented Jun 2, 2016

Could you please add a bullet to news?

@hadley hadley added the in progress label Jun 2, 2016

@hadley

This comment has been minimized.

Member

hadley commented Jun 9, 2016

Bump. Are you still interested in this?

@leeper leeper force-pushed the leeper:master branch from 5c0848a to 1c82b28 Jun 9, 2016

@leeper

This comment has been minimized.

Contributor

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

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@hadley

This comment has been minimized.

Member

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