Is there a way to prevent write.csv to transform the column names a la make.names? I mean, if I write the code: x <- structure (NULL) x [["a+b"]] <- c (1,2) write.csv (x, file = "foo.csv", row.names = FALSE, quote = FALSE) I get in foo.csv: a.b 1 2 but I want: a+b 1 2 Any suggestions? Cheers, -- Rafael Laboissiere
Rafael Laboissiere wrote:> Is there a way to prevent write.csv to transform the column names a la > make.names? I mean, if I write the code: > > x <- structure (NULL) > x [["a+b"]] <- c (1,2) > write.csv (x, file = "foo.csv", row.names = FALSE, quote = FALSE)your x is not a data.frame, hence write.csv() (or better, write.table()) converts your *list* x to a data.frame implicitly by using as.data.frame (and this tries to convert names to more regular names by make.names()). You can avoid it by either working on data.frames or stop the make.names() conversion by forcing the data.frame in advance as in: write.csv (as.data.frame(x, optional=TRUE), file = "foo.csv", row.names = FALSE, quote = FALSE) Uwe Ligges> I get in foo.csv: > > a.b > 1 > 2 > > but I want: > > a+b > 1 > 2 > > Any suggestions? > > Cheers, >
* Uwe Ligges <ligges at statistik.tu-dortmund.de> [2009-03-03 15:27]:> Rafael Laboissiere wrote: >> Is there a way to prevent write.csv to transform the column names a la >> make.names? I mean, if I write the code: >> >> x <- structure (NULL) >> x [["a+b"]] <- c (1,2) >> write.csv (x, file = "foo.csv", row.names = FALSE, quote = FALSE) > > > your x is not a data.frame, hence write.csv() (or better, write.table()) > converts your *list* x to a data.frame implicitly by using as.data.frame > (and this tries to convert names to more regular names by make.names()). > You can avoid it by either working on data.frames or stop the > make.names() conversion by forcing the data.frame in advance as in: > > write.csv (as.data.frame(x, optional=TRUE), file = "foo.csv", > row.names = FALSE, quote = FALSE)Great, it works. Thanks! -- Rafael Laboissiere