[R] write.table() or write.csv() --- add a comment?

Duncan Murdoch murdoch at stats.uwo.ca
Mon Apr 3 04:04:05 CEST 2006

On 4/2/2006 9:38 PM, ivo welch wrote:
> Dear R group:  Is there a way to pass a comment line to write.table()
> or write.csv()?  presumably, following linux and R conventions, it
> would be preceded by a '#' in the output.
> write.csv( object, file="object.csv", comment=paste("this csv file was
> created by mycode.R on 12/2/2005");
> of course, the R read functions are already smart enough to ignore the
> comment lines.

Open a connection, write the comment to the connection, write the data 
to the connection, close the connection.


con <- file("object.csv", open="wt")
writeLines(paste("# this csv file was created by mycode.R on 
12/2/2005"), con)
write.csv( object, con)

Duncan Murdoch

More information about the R-help mailing list