Hello, I am writing out to a file and have two quick questions that I can't seem to track down the correct answers for. Luckily, I *think* they are both simple enough that someone might be able to point me in the right direction on them without too much trouble. Both questions relate to the process below where CompleteFrame is a data frame containing what I want printed to a file. filename <- "C:\\MyDocuments\\TestOut_050609.txt" output <-file(filename, open="wt") write.csv(CompleteFrame, output, row.names = FALSE, col.names=FALSE) close(output) Question #1: Every time I run this process, I get the warning: Warning message: In write.csv(CompleteFrame, output, row.names = FALSE, col.names = FALSE) : attempt to set 'col.names' ignored And it still prints the column names as the first row in my file, which I do not want... Question #2: This process puts quotes around all data of class = character. I can't have these quotes in my file - is it possible to get R to omit them even if my data frame contains character strings? Any help or hints on this are greatly appreciated! Thanks, Brigid
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Brigid Mooney > Sent: Wednesday, May 06, 2009 1:42 PM > To: r-help at r-project.org > Subject: [R] Print to File Formatting > > Hello, > > I am writing out to a file and have two quick questions that I can't > seem to track down the correct answers for. Luckily, I *think* they > are both simple enough that someone might be able to point me in the > right direction on them without too much trouble. > > Both questions relate to the process below where CompleteFrame is a > data frame containing what I want printed to a file. > > filename <- "C:\\MyDocuments\\TestOut_050609.txt" > > output <-file(filename, open="wt") > write.csv(CompleteFrame, output, row.names = FALSE, col.names=FALSE) > close(output) > > Question #1: > Every time I run this process, I get the warning: > Warning message: > In write.csv(CompleteFrame, output, row.names = FALSE, > col.names = FALSE) : > attempt to set 'col.names' ignored > > And it still prints the column names as the first row in my file, > which I do not want... > > Question #2: > This process puts quotes around all data of class = character. > I can't have these quotes in my file - is it possible to get R to omit > them even if my data frame contains character strings? > > > Any help or hints on this are greatly appreciated! > > Thanks, > Brigid >Brigid, Look at ?write.table. This should solve both problems. Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA
Brigid Mooney wrote:> Hello, > > I am writing out to a file and have two quick questions that I can't > seem to track down the correct answers for. Luckily, I *think* they > are both simple enough that someone might be able to point me in the > right direction on them without too much trouble. > > Both questions relate to the process below where CompleteFrame is a > data frame containing what I want printed to a file. > > filename <- "C:\\MyDocuments\\TestOut_050609.txt" > > output <-file(filename, open="wt") > write.csv(CompleteFrame, output, row.names = FALSE, col.names=FALSE) > close(output) > > Question #1: > Every time I run this process, I get the warning: > Warning message: > In write.csv(CompleteFrame, output, row.names = FALSE, col.names = FALSE) : > attempt to set 'col.names' ignored > > And it still prints the column names as the first row in my file, > which I do not want... > > Question #2: > This process puts quotes around all data of class = character. > I can't have these quotes in my file - is it possible to get R to omit > them even if my data frame contains character strings? > > > Any help or hints on this are greatly appreciated! > > Thanks, > Brigid > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Hi Brigid, Re. Question 1: This is simply due to a convention about csv files. In order to ensure conformity of the output file, write.csv() doesn't allow users to change col.names. Re. Question 2: The "quote" argument is what you should be modifying. If you really want no column names, use write.table() instead (with sep="," and a filename with a .csv extension). After all, write.csv() is merely a wrapper for write.table(). Cheers, -- *Luc Villandr?* /Biostatistician McGill University Health Center - Montreal Children's Hospital Research Institute/