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

Undesired trimws in read_fwf #636

Closed
juangomezduaso opened this Issue Mar 15, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@juangomezduaso

juangomezduaso commented Mar 15, 2017

Trying to read a fixed width file I find a problem when a character field has just blanks. It becomes NA instead of its original value. The function parse_character seems to do a trimws of the data and then the resulting "" is considered as NA (by default). I dont know weather this is the intended behavior, but in that case it would be nice if read_fwf had a trim_ws parameter as read_delim has, in order to be able to read such fields.

@jimhester jimhester added feature and removed feature labels Dec 7, 2017

@jimhester

This comment has been minimized.

Member

jimhester commented Dec 7, 2017

I think the solution is just for the user to remove the "" value from the na argument in this case.

@jimhester jimhester closed this Dec 7, 2017

@juangomezduaso

This comment has been minimized.

juangomezduaso commented Dec 11, 2017

Hi Jim:
In that case I would get an empty , "" , string and not an NA, but the trimming of white space would have been done anyway. My intention was to get the string with as many blanks as there were originally in the file.
Excuse me for the not very clear initial exposition of my post. What I wanted to point out was not about this particular case of empty strings, but the general trimming issue:
Why doesnt read_fwf have a trim_ws parameter as read_delim has? This would affect the cases where the strings are composed of something else than white space as well.
I understand that in many situations in a fixed width format, the blanks are just there because of the format, with no meaning by themselves at all. But there are cases in which I think it would be good to be able to preserve the data exactly as it came, and making the trimming of white space an option would get it.
Thanks for your attention

jimhester added a commit that referenced this issue Dec 11, 2017

@jimhester

This comment has been minimized.

Member

jimhester commented Dec 11, 2017

I have added a trim_ws argument to read_fwf().

@lock

This comment has been minimized.

lock bot commented Sep 25, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.