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

export with append #201

Closed
julian-urbano opened this Issue Feb 15, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@julian-urbano
Copy link

julian-urbano commented Feb 15, 2019

When exporting a data.frame in CSV, one useful option is to append the contents to an existing file (eg. when processing in batches). In data.table::fwrite there is an argument append that does precisely this, of course omitting the column names when appending.

If we try this using rio::export, it doesn't work because col.names is always set to TRUE in export_delim.

rio::export(iris[1:2,], "file.csv")
rio::export(iris[1:2,], "file.csv", append = TRUE)
$ cat file.csv
Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species
5.1,3.5,1.4,0.2,setosa
4.9,3,1.4,0.2,setosa
Sepal.Length,Sepal.Width,Petal.Length,Petal.Width,Species
5.1,3.5,1.4,0.2,setosa
4.9,3,1.4,0.2,setosa

To solve this we need to manually set col.names = FALSE, but it should use the default in fwrite that writes the column names if the file does not exist, or omits if it does.

What do you think?

Thanks!

@leeper leeper added the bug label Feb 19, 2019

@leeper

This comment has been minimized.

Copy link
Owner

leeper commented Feb 19, 2019

Good call. Want to send a PR (including a test)? Should be a pretty simple fix around here: https://github.com/leeper/rio/blob/master/R/export_methods.R#L5

@julian-urbano

This comment has been minimized.

Copy link
Author

julian-urbano commented Feb 21, 2019

Sure, will do.

@leeper

This comment has been minimized.

Copy link
Owner

leeper commented Feb 26, 2019

I just took care of this. Thanks for raising the issue!

@leeper leeper added this to the v0.6 milestone Feb 26, 2019

@leeper leeper closed this in 015f242 Feb 26, 2019

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