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

write_csv does not write output correctly #1169

Closed
xuqingyu opened this issue Jan 7, 2021 · 3 comments
Closed

write_csv does not write output correctly #1169

xuqingyu opened this issue Jan 7, 2021 · 3 comments

Comments

@xuqingyu
Copy link

xuqingyu commented Jan 7, 2021


I am writing a column-combined data (say three 500*100 matrices), but write_csv repeats the first one matrix three times in the output.csv.

reprex(
library(tidyverse);
set.seed(100)
temp1 <- data.frame(matrix(rnorm(8760*100),nrow = 8760, ncol = 100));
temp2 <- data.frame(matrix(rnorm(8760*100,200),nrow = 8760, ncol = 100));
temp3 <- data.frame(matrix(rnorm(8760*100,300),nrow = 8760, ncol = 100));
temp4 <- cbind(temp1,temp2,temp3);
write_csv(temp4, './test.csv'))
@xuqingyu
Copy link
Author

xuqingyu commented Jan 7, 2021

Well, I did a little troubleshooting on my end.
It looks like that write_csv requires that the column names to be unique? I make new names of temp4 by

colnames(temp4) <- make.names(colnames(temp4),unique = TRUE);

and then write_csv works fine. In contrast, write.csv (the default of R) works fine without making column names unique.

Should this be an issue to be fixed?
Many thanks,

@jimhester
Copy link
Collaborator

Writing with duplicated columns was a bug recently introduced by #1009, it is now fixed, so this should now work how you expect.

Thank you for opening the issue and for supplying a reproducible example, it is a big help!

@xuqingyu
Copy link
Author

xuqingyu commented Jan 8, 2021

Thank you Jim!

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

2 participants