[R] Wriritng to a CSV file
peter dalgaard
pdalgd at gmail.com
Thu Feb 9 18:11:00 CET 2012
On Feb 8, 2012, at 21:56 , David Winsemius wrote:
>
> On Feb 8, 2012, at 2:29 PM, Ron Michael wrote:
>
>> Okay, so I understood that appending can only happen row-wise. Therefore I tried with following code:
>>
>>> write.csv(matrix(1:5, 1), "dat.csv")
>>> write.csv(matrix(1:5, 1), "dat.csv", append = TRUE)
>> Warning message:
>> In write.csv(matrix(1:5, 1), "dat.csv", append = TRUE) :
>> attempt to set 'append' ignored
>>
>> It is destroying my previous file. Where I have done wrong?
>
> Failed to read the help page. `write.csv` has some of its setting hard coded and will prevent you from changing them.
Exactly. Note, however, that write.csv is really just write.table with a particular set of arguments. Nothing is keeping you from using a similar set of arguments with append=TRUE in an explicit write.table() call.
It is of course debatable whether the behavior of write.csv is undue patronizing, but as I understand it, the rationale is that you can guarantee that write.csv creates a proper CSV file, but once you start appending, multiple things can go wrong: Forgetting to omit headers, different number of columns, different column types, etc. It is not realistic to have write.csv(...append=TRUE) make the necessary checks, and as it can't be sure to write a properly formed CSV, it just won't do it, period.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list