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

[Feature request]: add check for newline at end of original file before appending to it with write_csv() #1560

Open
morrisLuke opened this issue Nov 7, 2024 · 0 comments

Comments

@morrisLuke
Copy link

write_csv() seems to assume when appending to a file that the file concludes with a newline. However, when creating a file in Excel and saving as CSV, that behavior can't be 100% assumed.

Suggestion: When append is TRUE start with a check that the original file ends with a newline, and add one before starting append if not.

Current state of feature:

Take testfile.csv to read

a, b, c, d
1, 2, 3, 4
5, 6, 7, 8

(note lack of newline at end)

and environment variable whatToAdd to read

tribble( ~a, ~b, ~c, ~d, 9, 10, 11, 12, 13, 14, 15, 16 )

when I perform readr::write_csv(whatToAdd, "testfile.csv", append = TRUE) I'm expecting the appending to start on a new line. However I'm instead getting a testfile.csvlooking like

a, b, c, d
1, 2, 3, 4
5, 6, 7, 89, 10, 11, 12
13, 14, 15, 16

Just trying to save the next person from falling into the issue that sucked up a good chunk of my morning. Take care!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant